<commit_before>_ = require 'underscore'
cheerio = require 'cheerio'
path = require 'path'
jade = require 'jade'
fs = require 'fs'
moment = require 'moment'
Article = require '../../../models/article'
Articles = require '../../../collections/articles'
fixtures = require '../../../test/helpers/fixtures.coffee'

render = (templateName) ->
  filename = path.resolve __dirname, "../templates/#{templateName}.jade"
  jade.compile(
    fs.readFileSync(filename),
    { filename: filename }
  )

describe 'article show template', ->

  it 'renders sectionless articles', ->
    html = render('index')
      article: new Article title: 'hi', sections: [], section_ids: [], contributing_authors: []
      footerArticles: new Articles
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
    html.should.containEql 'hi'

  it 'renders fullscreen headers with video', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: []
        contributing_authors: []
        hero_section:
          type: 'fullscreen'
          background_url: 'http://video.mp4'
      footerArticles: new Articles
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
    html.should.containEql 'article-fullscreen__video-player'

  it 'renders fullscreen headers with static image', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: []
        contributing_authors: []
        hero_section:
          type: 'fullscreen'
          background_image_url: 'http://image.jpg'
      footerArticles: new Articles
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
    html.should.containEql 'article-fullscreen__image'

  it 'superSubArticles can render fullscreen header and SA menu with correct classes', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: []
        contributing_authors: []
        hero_section:
          type: 'fullscreen'
          background_image_url: 'http://image.jpg'
      footerArticles: new Articles
      superArticle: new Article
        super_article:
          partner_logo: 'http://logo.jpg'
          partner_logo_link: 'http://logo.com'
          partner_fullscreen_header_logo: 'http://fullscreen-logo.jpg'
      superSubArticles: {models: []}
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
    html.should.containEql 'article-fullscreen__image'
    html.should.containEql 'article-sa-sticky-header'
    html.should.containEql '<a href="http://logo.com"><img src="http://fullscreen-logo.jpg"/></a>'
    html.should.not.containEql 'visible no-transition'

  it 'renders a TOC', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: [
          {
            type: 'toc'
            links: [ {name: 'Kana Abe', value: 'Kana'}, { name: '<NAME>', value: 'Bob' } ]
          }
        ]
        contributing_authors: []
      footerArticles: new Articles
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
    html.should.containEql '<a href="#Kana">Kana Abe</a>'

  it 'can optionally exclude share buttons', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: [
          {
            type: 'toc'
            links: [ {name: 'Kana Abe', value: 'Kana'}, { name: '<NAME>', value: 'Bob' } ]
          }
        ]<commit_msg>Adds a test<commit_after>_ = require 'underscore'
cheerio = require 'cheerio'
path = require 'path'
jade = require 'jade'
fs = require 'fs'
moment = require 'moment'
markdown = require '../../../components/util/markdown'
Article = require '../../../models/article'
Articles = require '../../../collections/articles'
fixtures = require '../../../test/helpers/fixtures.coffee'

render = (templateName) ->
  filename = path.resolve __dirname, "../templates/#{templateName}.jade"
  jade.compile(
    fs.readFileSync(filename),
    { filename: filename }
  )

describe 'article show template', ->

  it 'renders sectionless articles', ->
    html = render('index')
      article: new Article title: 'hi', sections: [], section_ids: [], contributing_authors: []
      footerArticles: new Articles
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
    html.should.containEql 'hi'

  it 'renders fullscreen headers with video', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: []
        contributing_authors: []
        hero_section:
          type: 'fullscreen'
          background_url: 'http://video.mp4'
      footerArticles: new Articles
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
    html.should.containEql 'article-fullscreen__video-player'

  it 'renders fullscreen headers with static image', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: []
        contributing_authors: []
        hero_section:
          type: 'fullscreen'
          background_image_url: 'http://image.jpg'
      footerArticles: new Articles
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
    html.should.containEql 'article-fullscreen__image'

  it 'superSubArticles can render fullscreen header and SA menu with correct classes', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: []
        contributing_authors: []
        hero_section:
          type: 'fullscreen'
          background_image_url: 'http://image.jpg'
      footerArticles: new Articles
      superArticle: new Article
        super_article:
          partner_logo: 'http://logo.jpg'
          partner_logo_link: 'http://logo.com'
          partner_fullscreen_header_logo: 'http://fullscreen-logo.jpg'
      superSubArticles: {models: []}
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
    html.should.containEql 'article-fullscreen__image'
    html.should.containEql 'article-sa-sticky-header'
    html.should.containEql '<a href="http://logo.com"><img src="http://fullscreen-logo.jpg"/></a>'
    html.should.not.containEql 'visible no-transition'

  it 'super articles have markdown-supported footers', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: []
        contributing_authors: []
        is_super_article: true
      footerArticles: new Articles
      superArticle: new Article
        super_article:
          partner_logo: 'http://logo.jpg'
          partner_logo_link: 'http://logo.com'
          partner_fullscreen_header_logo: 'http://fullscreen-logo.jpg'
          footer_blurb: 'Article Test [Link](http://artsy.net)'
      superSubArticles: {models: []}
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
      markdown: markdown
    html.should.containEql '<a href="http://artsy.net">Link</a>'

  it 'renders a TOC', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: [
          {
            type: 'toc'
            links: [ {name: 'Kana Abe', value: 'Kana'}, { name: '<NAME>', value: 'Bob' } ]
          }
        ]
        contributing_authors: []
      footerArticles: new Articles
      crop: (url) -> url
      resize: (u) -> u
      moment: moment
      sd: {}
      asset: ->
    html.should.containEql '<a href="#Kana">Kana Abe</a>'

  it 'can optionally exclude share buttons', ->
    html = render('index')
      article: new Article
        title: 'hi'
        sections: [
          {
            type: 'toc'
            links: [ {name: 'Kana Abe', value: 'Kana'}, { name: '<NAME>', value: 'Bob' } ]
          }
        ]
{'fraction_non_alphanumeric': 0.14055415617128464, 'fraction_numerical': 0.00025188916876574307, 'mean_word_length': 2.1904379268782646, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '818469', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2402, 'n_words': 598}