<commit_before>path = require 'path'

{$} = require 'atom'
CSON = require 'season'
Q = require 'q'

PackageManager = require '../lib/package-manager'
ThemesPanel = require '../lib/themes-panel'

describe "ThemesPanel", ->
  [panel, packageManager, reloadedHandler] = []

  beforeEach ->
    atom.packages.loadPackage('atom-light-ui')
    atom.packages.loadPackage('atom-dark-ui')
    atom.packages.loadPackage('atom-light-syntax')
    atom.packages.loadPackage('atom-dark-syntax')
    atom.packages.packageDirPaths.push(path.join(__dirname, 'fixtures'))
    atom.config.set('core.themes', ['atom-dark-ui', 'atom-dark-syntax'])
    reloadedHandler = jasmine.createSpy('reloadedHandler')
    atom.themes.on 'reloaded', reloadedHandler
    atom.themes.activatePackages()

    waitsFor ->
      reloadedHandler.callCount is 1

    runs ->
      packageManager = new PackageManager
      themeMetadata = CSON.readFileSync(path.join(__dirname, 'fixtures', 'a-theme', 'package.json'))
      spyOn(packageManager, 'getFeatured').andCallFake (callback) ->
        Q([themeMetadata])
      spyOn(atom.themes, 'setEnabledThemes').andCallThrough()
      panel = new ThemesPanel(packageManager)

  afterEach ->
    atom.packages.unloadPackage('a-theme') if atom.packages.isPackageLoaded('a-theme')
    atom.themes.deactivateThemes()

  it "selects the active syntax and UI themes", ->
    expect(panel.uiMenu.val()).toBe 'atom-dark-ui'
    expect(panel.syntaxMenu.val()).toBe 'atom-dark-syntax'

  describe "when a UI theme is selected", ->
    it "updates the 'core.themes' config key with the selected UI theme", ->
      jasmine.unspy(window, 'setTimeout')
      panel.uiMenu.val('atom-light-ui').trigger('change')

      waitsFor ->
        atom.themes.setEnabledThemes.callCount > 0

      runs ->
        expect(atom.config.get('core.themes')).toEqual ['atom-light-ui', 'atom-dark-syntax']

  describe "when a syntax theme is selected", ->
    it "updates the 'core.themes' config key with the selected syntax theme", ->
      jasmine.unspy(window, 'setTimeout')
      panel.syntaxMenu.val('atom-light-syntax').trigger('change')

      waitsFor ->
        atom.themes.setEnabledThemes.callCount > 0

      runs ->
        expect(atom.config.get('core.themes')).toEqual ['atom-dark-ui', 'atom-light-syntax']

  describe "when the 'core.config' key is changes", ->
    it "refreshes the theme menus", ->
      reloadedHandler.reset()
      atom.config.set('core.themes', ['atom-light-ui', 'atom-light-syntax'])

      waitsFor ->
        reloadedHandler.callCount is 1

      runs -><commit_msg>Wait for config to be expected value<commit_after>path = require 'path'

{$} = require 'atom'
_ = require 'underscore-plus'
CSON = require 'season'
Q = require 'q'

PackageManager = require '../lib/package-manager'
ThemesPanel = require '../lib/themes-panel'

describe "ThemesPanel", ->
  [panel, packageManager, reloadedHandler] = []

  beforeEach ->
    atom.packages.loadPackage('atom-light-ui')
    atom.packages.loadPackage('atom-dark-ui')
    atom.packages.loadPackage('atom-light-syntax')
    atom.packages.loadPackage('atom-dark-syntax')
    atom.packages.packageDirPaths.push(path.join(__dirname, 'fixtures'))
    atom.config.set('core.themes', ['atom-dark-ui', 'atom-dark-syntax'])
    reloadedHandler = jasmine.createSpy('reloadedHandler')
    atom.themes.on 'reloaded', reloadedHandler
    atom.themes.activatePackages()

    waitsFor ->
      reloadedHandler.callCount is 1

    runs ->
      packageManager = new PackageManager
      themeMetadata = CSON.readFileSync(path.join(__dirname, 'fixtures', 'a-theme', 'package.json'))
      spyOn(packageManager, 'getFeatured').andCallFake (callback) ->
        Q([themeMetadata])
      spyOn(atom.themes, 'setEnabledThemes').andCallThrough()
      panel = new ThemesPanel(packageManager)

  afterEach ->
    atom.packages.unloadPackage('a-theme') if atom.packages.isPackageLoaded('a-theme')
    atom.themes.deactivateThemes()

  it "selects the active syntax and UI themes", ->
    expect(panel.uiMenu.val()).toBe 'atom-dark-ui'
    expect(panel.syntaxMenu.val()).toBe 'atom-dark-syntax'

  describe "when a UI theme is selected", ->
    it "updates the 'core.themes' config key with the selected UI theme", ->
      jasmine.unspy(window, 'setTimeout')
      panel.uiMenu.val('atom-light-ui').trigger('change')

      waitsFor "config to update", ->
        _.isEqual(atom.config.get('core.themes'), ['atom-light-ui', 'atom-dark-syntax'])

  describe "when a syntax theme is selected", ->
    it "updates the 'core.themes' config key with the selected syntax theme", ->
      jasmine.unspy(window, 'setTimeout')
      panel.syntaxMenu.val('atom-light-syntax').trigger('change')

      waitsFor "config to update", ->
        _.isEqual(atom.config.get('core.themes'), ['atom-dark-ui', 'atom-light-syntax'])

  describe "when the 'core.config' key is changes", ->
    it "refreshes the theme menus", ->
      reloadedHandler.reset()
      atom.config.set('core.themes', ['atom-light-ui', 'atom-light-syntax'])

      waitsFor ->
        reloadedHandler.callCount is 1

      runs ->
{'fraction_non_alphanumeric': 0.14985365853658536, 'fraction_numerical': 0.0011707317073170731, 'mean_word_length': 3.5443262411347516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '218232', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1560, 'n_words': 316}