<commit_before>import 'jsdom-global/register'
import _ from 'underscore'
import InfiniteScrollArticle, { __RewireAPI__ as RewireApi } from 'desktop/apps/article2/components/InfiniteScrollArticle'
import React from 'react'
import fixtures from 'desktop/test/helpers/fixtures.coffee'
import sinon from 'sinon'
import { Article } from '@artsy/reaction-force/dist/Components/Publishing'
import { shallow } from 'enzyme'

describe('<InfiniteScrollArticle />', () => {
  beforeEach(() => {
    window.history.replaceState = sinon.stub()
  })

  it('renders the initial article', () => {
    const article = _.extend({}, fixtures.article, {
      layout: 'standard',
      vertical: {
        name: 'Art Market'
      },
      contributing_authors: [{name: 'Kana'}]
    })
    const rendered = shallow(<InfiniteScrollArticle article={article} />)
    rendered.find(Article).length.should.equal(1)
    rendered.html().should.containEql('StandardLayout')
  })

  it('fetches more articles at the end of the page', async () => {
    const article = _.extend({}, fixtures.article, {
      layout: 'standard',
      vertical: {
        name: 'Art Market'
      },
      published_at: '2017-05-19T13:09:18.567Z',
      contributing_authors: [{name: 'Kana'}]
    })
    const data = {
      articles: [_.extend({}, fixtures.article, {
        slug: 'foobar',
        channel_id: '123',
        id: '678'
      })]
    }
    RewireApi.__Rewire__(
      'positronql',
      sinon.stub().returns(Promise.resolve(data))
    )
    const rendered = shallow(<InfiniteScrollArticle article={article} />)
    await rendered.instance().fetchNextArticles()
    rendered.update()
    rendered.find(Article).length.should.equal(2)
  })

  it('renders Related Articles', () => {
    const article = _.extend({}, fixtures.article, {
      layout: 'standard',
      vertical: {
        name: 'Art Market'
      },
      contributing_authors: [{name: 'Kana'}],
      relatedArticlesCanvas: [
        fixtures.article
      ],
      relatedArticlesPanel: [
        fixtures.article
      ]
    })
    const rendered = shallow(<InfiniteScrollArticle article={article} />)
    const html = rendered.html()
    html.should.containEql('Related Stories')
    html.should.containEql('Further Reading')<commit_msg>Update tests<commit_after>import 'jsdom-global/register'
import _ from 'underscore'
import fixtures from 'desktop/test/helpers/fixtures.coffee'
import sinon from 'sinon'
import React from 'react'
import { shallow } from 'enzyme'

describe('<InfiniteScrollArticle />', () => {
  window.matchMedia = () => {
    return {
      matches: false,
      addListener: () => {},
      removeListener: () => {}
    }
  }
  const InfiniteScrollArticle = require('desktop/apps/article2/components/InfiniteScrollArticle').default
  const { Article } = require('@artsy/reaction-force/dist/Components/Publishing')

  beforeEach(() => {
    window.history.replaceState = sinon.stub()
  })

  afterEach(() => {
    window.history.replaceState.reset()
  })

  it('renders the initial article', () => {
    const article = _.extend({}, fixtures.article, {
      layout: 'standard',
      vertical: {
        name: 'Art Market'
      },
      contributing_authors: [{name: 'Kana'}]
    })
    const rendered = shallow(
      <InfiniteScrollArticle
        article={article}
        headerHeight={'calc(100vh - 50px)'}
        marginTop={'50px'}
      />
    )
    rendered.find(Article).length.should.equal(1)
    rendered.html().should.containEql('StandardLayout')
  })

  it('fetches more articles at the end of the page', async () => {
    const article = _.extend({}, fixtures.article, {
      layout: 'standard',
      vertical: {
        name: 'Art Market'
      },
      published_at: '2017-05-19T13:09:18.567Z',
      contributing_authors: [{name: 'Kana'}]
    })
    const data = {
      articles: [_.extend({}, fixtures.article, {
        slug: 'foobar',
        channel_id: '123',
        id: '678'
      })]
    }
    InfiniteScrollArticle.__Rewire__(
      'positronql',
      sinon.stub().returns(Promise.resolve(data))
    )
    const rendered = shallow(<InfiniteScrollArticle article={article} />)
    await rendered.instance().fetchNextArticles()
    rendered.update()
    rendered.find(Article).length.should.equal(2)
  })

  it('renders Related Articles', () => {
    const article = _.extend({}, fixtures.article, {
      layout: 'standard',
      vertical: {
        name: 'Art Market'
      },
      contributing_authors: [{name: 'Kana'}],
      relatedArticlesCanvas: [
        fixtures.article
      ],
      relatedArticlesPanel: [
        fixtures.article
      ]
    })
    const rendered = shallow(<InfiniteScrollArticle article={article} />)
    const html = rendered.html()
    html.should.containEql('Related Stories')
    html.should.containEql('Further Reading')
{'fraction_non_alphanumeric': 0.1465979381443299, 'fraction_numerical': 0.012164948453608248, 'mean_word_length': 2.9991755976916736, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '7322652', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1448, 'n_words': 281}