<commit_before>Grim = require 'grim'
DeprecationCopView = require '../lib/deprecation-cop-view'
path = require 'path'

describe "DeprecationCopView", ->
  [deprecationCopView, workspaceElement] = []

  beforeEach ->
    workspaceElement = atom.views.getView(atom.workspace)
    jasmine.attachToDOM(workspaceElement)

    expect(Grim.getDeprecationsLength()).toBe 0
    deprecatedMethod = -> Grim.deprecate("A test deprecation. This isn't used")
    deprecatedMethod()

    spyOn(Grim, 'deprecate') # Don't fail tests if when using deprecated APIs in deprecation cop's activation
    activationPromise = atom.packages.activatePackage('deprecation-cop')

    atom.commands.dispatch workspaceElement, 'deprecation-cop:view'

    waitsForPromise ->
      activationPromise

    runs ->
      jasmine.unspy(Grim, 'deprecate')
      deprecationCopView = atom.workspace.getActivePane().getActiveItem()

  afterEach ->
    Grim.clearDeprecations()

  it "displays deprecated methods", ->
    expect(deprecationCopView.html()).toMatch /Deprecated calls/
    expect(deprecationCopView.html()).toMatch /This isn't used/

  it "displays deprecated selectors", ->
    fakePackageDir = path.join(__dirname, "..", "spec", "fixtures", "package-with-deprecated-selectors")

    pack = atom.packages.loadPackage(fakePackageDir)
    spyOn(atom.packages, 'getActivePackages').andReturn([pack])
    deprecationCopView.find("button.refresh-selectors").click()

    packageItems = deprecationCopView.find("ul.selectors > li")
    expect(packageItems.length).toBe(1)
    expect(packageItems.eq(0).html()).toMatch /package-with-deprecated-selectors/

    packageDeprecationItems = packageItems.eq(0).find("li.source-file")
    expect(packageDeprecationItems.length).toBe(3)
    expect(packageDeprecationItems.eq(0).text()).toMatch /atom-text-editor/
    expect(packageDeprecationItems.eq(0).find("a").attr("href")).toBe(path.join(fakePackageDir, "menus", "old-menu.cson"))
    expect(packageDeprecationItems.eq(1).text()).toMatch /atom-pane-container/
    expect(packageDeprecationItems.eq(1).find("a").attr("href")).toBe(path.join(fakePackageDir, "keymaps", "old-keymap.cson"))
    expect(packageDeprecationItems.eq(2).text()).toMatch /atom-workspace/
    expect(packageDeprecationItems.eq(2).find("a").attr("href")).toBe(path.join(fakePackageDir, "stylesheets", "old-stylesheet.less"))
<commit_msg>Clear deprecations before each spec<commit_after>Grim = require 'grim'
DeprecationCopView = require '../lib/deprecation-cop-view'
path = require 'path'

describe "DeprecationCopView", ->
  [deprecationCopView, workspaceElement] = []

  beforeEach ->
    workspaceElement = atom.views.getView(atom.workspace)
    jasmine.attachToDOM(workspaceElement)

    Grim.clearDeprecations()
    deprecatedMethod = -> Grim.deprecate("A test deprecation. This isn't used")
    deprecatedMethod()

    spyOn(Grim, 'deprecate') # Don't fail tests if when using deprecated APIs in deprecation cop's activation
    activationPromise = atom.packages.activatePackage('deprecation-cop')

    atom.commands.dispatch workspaceElement, 'deprecation-cop:view'

    waitsForPromise ->
      activationPromise

    runs ->
      jasmine.unspy(Grim, 'deprecate')
      deprecationCopView = atom.workspace.getActivePane().getActiveItem()

  afterEach ->
    Grim.clearDeprecations()

  it "displays deprecated methods", ->
    expect(deprecationCopView.html()).toMatch /Deprecated calls/
    expect(deprecationCopView.html()).toMatch /This isn't used/

  it "displays deprecated selectors", ->
    fakePackageDir = path.join(__dirname, "..", "spec", "fixtures", "package-with-deprecated-selectors")

    pack = atom.packages.loadPackage(fakePackageDir)
    spyOn(atom.packages, 'getActivePackages').andReturn([pack])
    deprecationCopView.find("button.refresh-selectors").click()

    packageItems = deprecationCopView.find("ul.selectors > li")
    expect(packageItems.length).toBe(1)
    expect(packageItems.eq(0).html()).toMatch /package-with-deprecated-selectors/

    packageDeprecationItems = packageItems.eq(0).find("li.source-file")
    expect(packageDeprecationItems.length).toBe(3)
    expect(packageDeprecationItems.eq(0).text()).toMatch /atom-text-editor/
    expect(packageDeprecationItems.eq(0).find("a").attr("href")).toBe(path.join(fakePackageDir, "menus", "old-menu.cson"))
    expect(packageDeprecationItems.eq(1).text()).toMatch /atom-pane-container/
    expect(packageDeprecationItems.eq(1).find("a").attr("href")).toBe(path.join(fakePackageDir, "keymaps", "old-keymap.cson"))
    expect(packageDeprecationItems.eq(2).text()).toMatch /atom-workspace/
    expect(packageDeprecationItems.eq(2).find("a").attr("href")).toBe(path.join(fakePackageDir, "stylesheets", "old-stylesheet.less"))

{'fraction_non_alphanumeric': 0.14580265095729014, 'fraction_numerical': 0.004418262150220913, 'mean_word_length': 4.994955863808323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '1672651', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1480, 'n_words': 211}