|
| 1 | +EmberTabs = require '../lib/ember-tabs' |
| 2 | + |
| 3 | +# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs. |
| 4 | +# |
| 5 | +# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit` |
| 6 | +# or `fdescribe`). Remove the `f` to unfocus the block. |
| 7 | + |
| 8 | +describe "EmberTabs", -> |
| 9 | + [workspaceElement, activationPromise] = [] |
| 10 | + |
| 11 | + beforeEach -> |
| 12 | + workspaceElement = atom.views.getView(atom.workspace) |
| 13 | + activationPromise = atom.packages.activatePackage('ember-tabs') |
| 14 | + |
| 15 | + describe "when the ember-tabs:toggle event is triggered", -> |
| 16 | + it "hides and shows the modal panel", -> |
| 17 | + # Before the activation event the view is not on the DOM, and no panel |
| 18 | + # has been created |
| 19 | + expect(workspaceElement.querySelector('.ember-tabs')).not.toExist() |
| 20 | + |
| 21 | + # This is an activation event, triggering it will cause the package to be |
| 22 | + # activated. |
| 23 | + atom.commands.dispatch workspaceElement, 'ember-tabs:toggle' |
| 24 | + |
| 25 | + waitsForPromise -> |
| 26 | + activationPromise |
| 27 | + |
| 28 | + runs -> |
| 29 | + expect(workspaceElement.querySelector('.ember-tabs')).toExist() |
| 30 | + |
| 31 | + emberTabsElement = workspaceElement.querySelector('.ember-tabs') |
| 32 | + expect(emberTabsElement).toExist() |
| 33 | + |
| 34 | + emberTabsPanel = atom.workspace.panelForItem(emberTabsElement) |
| 35 | + expect(emberTabsPanel.isVisible()).toBe true |
| 36 | + atom.commands.dispatch workspaceElement, 'ember-tabs:toggle' |
| 37 | + expect(emberTabsPanel.isVisible()).toBe false |
| 38 | + |
| 39 | + it "hides and shows the view", -> |
| 40 | + # This test shows you an integration test testing at the view level. |
| 41 | + |
| 42 | + # Attaching the workspaceElement to the DOM is required to allow the |
| 43 | + # `toBeVisible()` matchers to work. Anything testing visibility or focus |
| 44 | + # requires that the workspaceElement is on the DOM. Tests that attach the |
| 45 | + # workspaceElement to the DOM are generally slower than those off DOM. |
| 46 | + jasmine.attachToDOM(workspaceElement) |
| 47 | + |
| 48 | + expect(workspaceElement.querySelector('.ember-tabs')).not.toExist() |
| 49 | + |
| 50 | + # This is an activation event, triggering it causes the package to be |
| 51 | + # activated. |
| 52 | + atom.commands.dispatch workspaceElement, 'ember-tabs:toggle' |
| 53 | + |
| 54 | + waitsForPromise -> |
| 55 | + activationPromise |
| 56 | + |
| 57 | + runs -> |
| 58 | + # Now we can test for view visibility |
| 59 | + emberTabsElement = workspaceElement.querySelector('.ember-tabs') |
| 60 | + expect(emberTabsElement).toBeVisible() |
| 61 | + atom.commands.dispatch workspaceElement, 'ember-tabs:toggle' |
| 62 | + expect(emberTabsElement).not.toBeVisible() |
0 commit comments