<commit_before>_               = require 'underscore'
benv            = require 'benv'
jade            = require 'jade'
path            = require 'path'
fs              = require 'fs'
Backbone        = require 'backbone'
{ fabricate }   = require 'antigravity'
OrderedSet      = require '../../../models/ordered_set'
FeaturedLink    = require '../../../models/featured_link'
Gene            = require '../../../models/gene'
Artists         = require '../../../collections/artists'
Artist          = require '../../../models/artist'
Items           = require '../../../collections/items'

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

describe 'Artists', ->
  describe 'index page', ->
    after benv.teardown

    before (done) ->
      benv.setup =>
        benv.expose { $: benv.require 'jquery' }

        @artistCollection = new Artists(
          _.times(2, -> new Artist(fabricate('artist')))
        )

        @featuredLinksCollection = new Items(
          _.times(3, ->
            link = new FeaturedLink(fabricate('featured_link'))
            link.set 'artist', new Artist(fabricate('artist'))
            link
          ), { id: 'foobar', item_type: 'FeaturedLink' }
        )

        @genes = new Items(_.times(2, =>
          gene = new Gene(fabricate 'gene')
          gene.trendingArtists = @artistCollection.models
          gene
        ), { id: 'foobar', item_type: 'Gene'})

        @featuredArtists = new OrderedSet(name: 'Featured Artists', items: @featuredLinksCollection)

        template = render('index')(
          sd: {}
          letterRange:      ['a', 'b', 'c']
          featuredArtists:  @featuredArtists
          featuredGenes:    @genes
        )

        @$template = $(template)

        done()

    it 'renders the alphabetical nav', ->
      @$template.find('.alphabetical-index-range').text().should.equal 'abc'

    it 'has a single <h1> that displays the name of the artists set', ->
      $h1 = @$template.find('h1')
      $h1.length.should.equal 1
      $h1.text().should.equal 'Featured Artists'

    it 'renders the featured artists', ->
      @$template.find('.afc-artist').length.should.equal @featuredLinksCollection.length

    it 'renders the gene sets', ->
      @$template.find('.artists-featured-genes-gene').length.should.equal @genes.length

    it 'renders the trendingArtists for the genes', ->
      @$template.find('.afg-artist').length.should.equal @genes.length * @artistCollection.length

    it 'has jump links to the various gene pages', ->
      $links = @$template.find('.avant-garde-jump-link')
      $links.length.should.equal 2
      $links.first().text().should.equal fabricate('gene').name<commit_msg>Template test for four_thirds images<commit_after>_               = require 'underscore'
benv            = require 'benv'
jade            = require 'jade'
path            = require 'path'
fs              = require 'fs'
Backbone        = require 'backbone'
{ fabricate }   = require 'antigravity'
OrderedSet      = require '../../../models/ordered_set'
FeaturedLink    = require '../../../models/featured_link'
Gene            = require '../../../models/gene'
Artists         = require '../../../collections/artists'
Artist          = require '../../../models/artist'
Items           = require '../../../collections/items'

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

describe 'Artists', ->
  describe 'index page', ->
    after benv.teardown

    before (done) ->
      benv.setup =>
        benv.expose { $: benv.require 'jquery' }

        @artistCollection = new Artists(
          _.times(2, ->
            new Artist(fabricate('artist', { image_versions: ['four_thirds', 'tall'] }))
          )
        )

        @featuredLinksCollection = new Items(
          _.times(3, ->
            link = new FeaturedLink(fabricate('featured_link'))
            link.set 'artist', new Artist(fabricate('artist'))
            link
          ), { id: 'foobar', item_type: 'FeaturedLink' }
        )

        @genes = new Items(_.times(2, =>
          gene = new Gene(fabricate 'gene')
          gene.trendingArtists = @artistCollection.models
          gene
        ), { id: 'foobar', item_type: 'Gene'})

        @featuredArtists = new OrderedSet(name: 'Featured Artists', items: @featuredLinksCollection)

        template = render('index')(
          sd: {}
          letterRange:      ['a', 'b', 'c']
          featuredArtists:  @featuredArtists
          featuredGenes:    @genes
        )

        @$template = $(template)

        done()

    it 'renders the alphabetical nav', ->
      @$template.find('.alphabetical-index-range').text().should.equal 'abc'

    it 'has a single <h1> that displays the name of the artists set', ->
      $h1 = @$template.find('h1')
      $h1.length.should.equal 1
      $h1.text().should.equal 'Featured Artists'

    it 'renders the featured artists', ->
      @$template.find('.afc-artist').length.should.equal @featuredLinksCollection.length

    it 'renders the gene sets', ->
      @$template.find('.artists-featured-genes-gene').length.should.equal @genes.length

    it 'renders the trendingArtists for the genes', ->
      @$template.find('.afg-artist').length.should.equal @genes.length * @artistCollection.length

    it 'has jump links to the various gene pages', ->
      $links = @$template.find('.avant-garde-jump-link')
      $links.length.should.equal 2
      $links.first().text().should.equal fabricate('gene').name

    it 'uses four_thirds images', ->
      @$template.find('.afg-artist img').attr('src').should.include 'four_thirds'
{'fraction_non_alphanumeric': 0.1536087776444368, 'fraction_numerical': 0.0034287673581347507, 'mean_word_length': 2.246521981079577, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '1764092', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1726, 'n_words': 383}