<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
/* global describe, before, after, it */

const mockery = require('mockery')
const {shallow} = require('enzyme')
const assert = require('assert')
const Immutable = require('immutable')
let Main, NavigationBar
require('../../braveUnit')

describe('Main component unit tests', function () {
  before(function () {
    mockery.enable({
      warnOnReplace: false,
      warnOnUnregistered: false,
      useCleanCache: true
    })
    mockery.registerMock('../../extensions/brave/img/urlbar/browser_URL_fund_no_verified.svg', {})
    mockery.registerMock('../../extensions/brave/img/urlbar/browser_URL_fund_yes_verified.svg', {})
    mockery.registerMock('../../extensions/brave/img/urlbar/browser_URL_fund_no.svg', {})
    mockery.registerMock('../../extensions/brave/img/urlbar/browser_URL_fund_yes.svg', {})
    mockery.registerMock('../../extensions/brave/img/caret_down_grey.svg', 'caret_down_grey.svg')
    mockery.registerMock('../../extensions/brave/img/tabs/new_session.svg')
    mockery.registerMock('electron', require('../../lib/fakeElectron'))
    Main = require('../../../../js/components/main')
    NavigationBar = require('../../../../js/components/navigationBar')
  })

  after(function () {
    mockery.disable()
  })

  const windowState = Immutable.fromJS({
    activeFrameKey: 0,
    frames: [{
      key: 0,
      tabId: 1,
      location: 'http://brave.com'
    }],
    tabs: []
  })

  const appState = Immutable.fromJS({
    extensions: {
    },
    settings: {
    },
    siteSettings: {
      'https?://brave.com': {
        example3: true
      }
    },
    tabs: [{
      tabId: 1,
      canGoBack: true,
      canGoForward: true
    }]
  })

  describe('when user has history going forwards and backwards', function () {
    let wrapper

    before(function () {
      wrapper = shallow(
        <Main windowState={windowState} appState={appState} />
      )
    })

    it('both back/forward navigationButtonContainers are enabled', function () {
      assert.equal(wrapper.find('div.backforward > div.navigationButtonContainer.disabled').length, 0)
    })

    it('back navigation button is enabled', function () {
      const node = wrapper.find('div.backforward > div.navigationButtonContainer > .backButton').node
      assert.equal(node.props.disabled, false)
    })

    it('forward navigation button is enabled', function () {
      const node = wrapper.find('div.backforward > div.navigationButtonContainer > .forwardButton').node
      assert.equal(node.props.disabled, false)
    })
  })

  describe('when active tab is showing a message box', function () {
    let wrapper

    before(function () {
      const appState2 = appState.mergeIn(['tabs', 0], {
        messageBoxDetail: {
          message: 'sample message',
          title: 'sample title'
        }
      })

      wrapper = shallow(
        <Main windowState={windowState} appState={appState2} />
      )
    })

    it('passes activeTabShowingMessageBox to NavigationBar', function () {
      const navigationBar = wrapper.find(NavigationBar).node
      assert.equal(navigationBar.props.activeTabShowingMessageBox, true)
    })

    it('disables both back/forward navigationButtonContainers', function () {
      assert.equal(wrapper.find('div.backforward > div.navigationButtonContainer.disabled').length, 2)
    })

    it('disables the back navigation button', function () {
      const node = wrapper.find('div.backforward > div.navigationButtonContainer > .backButton').node
      assert.equal(node.props.disabled, true)
    })

    it('disables the forward navigation button', function () {
      const node = wrapper.find('div.backforward > div.navigationButtonContainer > .forwardButton').node
      assert.equal(node.props.disabled, true)
    })

    it('disables the lion icon', function () {
      const node = wrapper.find('[data-test-id="braveShieldButton"]').node
      assert.equal(node.props.disabled, true)
    })
  })

  describe('getTotalBlocks', function () {
    let instance

    before(function () {
      let wrapper = shallow(
        <Main windowState={windowState} appState={appState} />
      )
      instance = wrapper.instance()
    })

    it('returns false if there are no units blocked', function () {
      const frames = Immutable.fromJS({
        adblock: { blocked: [] },
        trackingProtection: { blocked: [] },
        noScript: { blocked: [] },<commit_msg>Update main.js test to use testId<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
/* global describe, before, after, it */

const mockery = require('mockery')
const {shallow} = require('enzyme')
const assert = require('assert')
const Immutable = require('immutable')
let Main, NavigationBar
require('../../braveUnit')

describe('Main component unit tests', function () {
  before(function () {
    mockery.enable({
      warnOnReplace: false,
      warnOnUnregistered: false,
      useCleanCache: true
    })
    mockery.registerMock('../../extensions/brave/img/urlbar/browser_URL_fund_no_verified.svg', {})
    mockery.registerMock('../../extensions/brave/img/urlbar/browser_URL_fund_yes_verified.svg', {})
    mockery.registerMock('../../extensions/brave/img/urlbar/browser_URL_fund_no.svg', {})
    mockery.registerMock('../../extensions/brave/img/urlbar/browser_URL_fund_yes.svg', {})
    mockery.registerMock('../../extensions/brave/img/caret_down_grey.svg', 'caret_down_grey.svg')
    mockery.registerMock('../../extensions/brave/img/tabs/new_session.svg')
    mockery.registerMock('electron', require('../../lib/fakeElectron'))
    Main = require('../../../../js/components/main')
    NavigationBar = require('../../../../js/components/navigationBar')
  })

  after(function () {
    mockery.disable()
  })

  const windowState = Immutable.fromJS({
    activeFrameKey: 0,
    frames: [{
      key: 0,
      tabId: 1,
      location: 'http://brave.com'
    }],
    tabs: []
  })

  const appState = Immutable.fromJS({
    extensions: {
    },
    settings: {
    },
    siteSettings: {
      'https?://brave.com': {
        example3: true
      }
    },
    tabs: [{
      tabId: 1,
      canGoBack: true,
      canGoForward: true
    }]
  })

  describe('when user has history going forwards and backwards', function () {
    let wrapper

    before(function () {
      wrapper = shallow(
        <Main windowState={windowState} appState={appState} />
      )
    })

    it('both back/forward navigationButtonContainers are enabled', function () {
      assert.equal(wrapper.find('div.backforward > div.navigationButtonContainer.disabled').length, 0)
    })

    it('back navigation button is enabled', function () {
      const node = wrapper.find('div.backforward > div.navigationButtonContainer > .backButton').node
      assert.equal(node.props.disabled, false)
    })

    it('forward navigation button is enabled', function () {
      const node = wrapper.find('div.backforward > div.navigationButtonContainer > .forwardButton').node
      assert.equal(node.props.disabled, false)
    })
  })

  describe('when active tab is showing a message box', function () {
    let wrapper

    before(function () {
      const appState2 = appState.mergeIn(['tabs', 0], {
        messageBoxDetail: {
          message: 'sample message',
          title: 'sample title'
        }
      })

      wrapper = shallow(
        <Main windowState={windowState} appState={appState2} />
      )
    })

    it('passes activeTabShowingMessageBox to NavigationBar', function () {
      const navigationBar = wrapper.find(NavigationBar).node
      assert.equal(navigationBar.props.activeTabShowingMessageBox, true)
    })

    it('disables both back/forward navigationButtonContainers', function () {
      assert.equal(wrapper.find('div.backforward > div.navigationButtonContainer.disabled').length, 2)
    })

    it('disables the back navigation button', function () {
      const node = wrapper.find('div.backforward > div.navigationButtonContainer > .backButton').node
      assert.equal(node.props.disabled, true)
    })

    it('disables the forward navigation button', function () {
      const node = wrapper.find('div.backforward > div.navigationButtonContainer > .forwardButton').node
      assert.equal(node.props.disabled, true)
    })

    it('disables the lion icon', function () {
      const node = wrapper.find('[testId="braveShieldButton"]').node
      assert.equal(node.props.disabled, true)
    })
  })

  describe('getTotalBlocks', function () {
    let instance

    before(function () {
      let wrapper = shallow(
        <Main windowState={windowState} appState={appState} />
      )
      instance = wrapper.instance()
    })

    it('returns false if there are no units blocked', function () {
      const frames = Immutable.fromJS({
        adblock: { blocked: [] },
        trackingProtection: { blocked: [] },
        noScript: { blocked: [] },
{'fraction_non_alphanumeric': 0.14460043196544276, 'fraction_numerical': 0.003023758099352052, 'mean_word_length': 2.996978851963746, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4422685', 'n_tokens_mistral': 2700, 'n_tokens_neox': 2621, 'n_words': 561}