<commit_before>// Tests that require resetting the App.js module.
// Breaking out these tests to not require rewriting existing tests
// that don't use any modules state.
/* eslint-env jest */

import React from 'react'
import { shallow } from 'enzyme'
import { flushAllPromises } from 'js/utils/test-utils'

jest.mock('tab-cmp')
jest.mock('js/components/Dashboard/DashboardView')
jest.mock('js/analytics/withPageviewTracking', () => child => child)
jest.mock('js/assets/logos/favicon.ico', () => '/tab-favicon.png')

const getMockProps = () => ({
  location: {
    pathname: '/newtab/',
    search: '',
  },
})

beforeAll(() => {
  jest.useFakeTimers()
})

beforeEach(() => {
  jest.clearAllMocks()
  process.env.REACT_APP_CMP_ENABLED = 'true'
})

afterEach(() => {
  jest.resetModules()
})

describe('App.js: tab-cmp', () => {
  it('calls tabCMP.initializeCMP after a 1000ms timeout', async () => {
    expect.assertions(3)
    const tabCMP = require('tab-cmp').default
    const App = require('js/components/App/App').default
    const mockProps = getMockProps()
    shallow(<App {...mockProps} />)
    await flushAllPromises()
    expect(tabCMP.initializeCMP).not.toHaveBeenCalled()
    jest.advanceTimersByTime(800)
    await flushAllPromises()
    expect(tabCMP.initializeCMP).not.toHaveBeenCalled()
    jest.advanceTimersByTime(300)
    await flushAllPromises()
    expect(tabCMP.initializeCMP).toHaveBeenCalled()
  })

  it('calls tabCMP.initializeCMP with the expected configuration', async () => {
    expect.assertions(1)
    const tabCMP = require('tab-cmp').default
    const App = require('js/components/App/App').default
    const mockProps = getMockProps()
    shallow(<App {...mockProps} />)
    await flushAllPromises()
    jest.runAllTimers()
    expect(tabCMP.initializeCMP).toHaveBeenCalledWith({
      debug: expect.any(Boolean),
      displayPersistentConsentLink: false,
      onError: expect.any(Function),
      primaryButtonColor: '#9d4ba3',
      publisherName: 'Tab for a Cause',
      publisherLogo: expect.any(String),
    })
  })
})<commit_msg>Add test<commit_after>// Tests that require resetting the App.js module.
// Breaking out these tests to not require rewriting existing tests
// that don't use any modules state.
/* eslint-env jest */

import React from 'react'
import { shallow } from 'enzyme'
import { flushAllPromises } from 'js/utils/test-utils'

jest.mock('tab-cmp')
jest.mock('js/components/Dashboard/DashboardView')
jest.mock('js/analytics/withPageviewTracking', () => child => child)
jest.mock('js/assets/logos/favicon.ico', () => '/tab-favicon.png')

const getMockProps = () => ({
  location: {
    pathname: '/newtab/',
    search: '',
  },
})

beforeAll(() => {
  jest.useFakeTimers()
})

beforeEach(() => {
  jest.clearAllMocks()
  process.env.REACT_APP_CMP_ENABLED = 'true'
})

afterEach(() => {
  jest.resetModules()
})

describe('App.js: tab-cmp', () => {
  it('calls tabCMP.initializeCMP after a 1000ms timeout', async () => {
    expect.assertions(3)
    const tabCMP = require('tab-cmp').default
    const App = require('js/components/App/App').default
    const mockProps = getMockProps()
    shallow(<App {...mockProps} />)
    await flushAllPromises()
    expect(tabCMP.initializeCMP).not.toHaveBeenCalled()
    jest.advanceTimersByTime(800)
    await flushAllPromises()
    expect(tabCMP.initializeCMP).not.toHaveBeenCalled()
    jest.advanceTimersByTime(300)
    await flushAllPromises()
    expect(tabCMP.initializeCMP).toHaveBeenCalled()
  })

  it('calls tabCMP.initializeCMP with the expected configuration', async () => {
    expect.assertions(1)
    const tabCMP = require('tab-cmp').default
    const App = require('js/components/App/App').default
    const mockProps = getMockProps()
    shallow(<App {...mockProps} />)
    await flushAllPromises()
    jest.runAllTimers()
    expect(tabCMP.initializeCMP).toHaveBeenCalledWith({
      debug: expect.any(Boolean),
      displayPersistentConsentLink: false,
      onError: expect.any(Function),
      primaryButtonColor: '#9d4ba3',
      publisherName: 'Tab for a Cause',
      publisherLogo: expect.any(String),
    })
  })

  it('does not call tabCMP.initializeCMP when process.env.REACT_APP_CMP_ENABLED is not "true"', async () => {
    expect.assertions(1)
    process.env.REACT_APP_CMP_ENABLED = 'false'
    const tabCMP = require('tab-cmp').default
    const App = require('js/components/App/App').default
    const mockProps = getMockProps()
    shallow(<App {...mockProps} />)
    await flushAllPromises()
    jest.runAllTimers()
    expect(tabCMP.initializeCMP).not.toHaveBeenCalled()
  })
})
{'fraction_non_alphanumeric': 0.14910192599004546, 'fraction_numerical': 0.0067085046526725815, 'mean_word_length': 3.9065817409766455, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 29, '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': '12536', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1535, 'n_words': 287}