File size: 2,963 Bytes
5893f8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use babel';

import WordpressAutocomplete from '../lib/wordpress-autocomplete';

// Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
//
// To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
// or `fdescribe`). Remove the `f` to unfocus the block.

describe('WordpressAutocomplete', () => {
  let workspaceElement, activationPromise;

  beforeEach(() => {
    workspaceElement = atom.views.getView(atom.workspace);
    activationPromise = atom.packages.activatePackage('wordpress-autocomplete');
  });

  describe('when the wordpress-autocomplete:toggle event is triggered', () => {
    it('hides and shows the modal panel', () => {
      // Before the activation event the view is not on the DOM, and no panel
      // has been created
      expect(workspaceElement.querySelector('.wordpress-autocomplete')).not.toExist();

      // This is an activation event, triggering it will cause the package to be
      // activated.
      atom.commands.dispatch(workspaceElement, 'wordpress-autocomplete:toggle');

      waitsForPromise(() => {
        return activationPromise;
      });

      runs(() => {
        expect(workspaceElement.querySelector('.wordpress-autocomplete')).toExist();

        let wordpressAutocompleteElement = workspaceElement.querySelector('.wordpress-autocomplete');
        expect(wordpressAutocompleteElement).toExist();

        let wordpressAutocompletePanel = atom.workspace.panelForItem(wordpressAutocompleteElement);
        expect(wordpressAutocompletePanel.isVisible()).toBe(true);
        atom.commands.dispatch(workspaceElement, 'wordpress-autocomplete:toggle');
        expect(wordpressAutocompletePanel.isVisible()).toBe(false);
      });
    });

    it('hides and shows the view', () => {
      // This test shows you an integration test testing at the view level.

      // Attaching the workspaceElement to the DOM is required to allow the
      // `toBeVisible()` matchers to work. Anything testing visibility or focus
      // requires that the workspaceElement is on the DOM. Tests that attach the
      // workspaceElement to the DOM are generally slower than those off DOM.
      jasmine.attachToDOM(workspaceElement);

      expect(workspaceElement.querySelector('.wordpress-autocomplete')).not.toExist();

      // This is an activation event, triggering it causes the package to be
      // activated.
      atom.commands.dispatch(workspaceElement, 'wordpress-autocomplete:toggle');

      waitsForPromise(() => {
        return activationPromise;
      });

      runs(() => {
        // Now we can test for view visibility
        let wordpressAutocompleteElement = workspaceElement.querySelector('.wordpress-autocomplete');
        expect(wordpressAutocompleteElement).toBeVisible();
        atom.commands.dispatch(workspaceElement, 'wordpress-autocomplete:toggle');
        expect(wordpressAutocompleteElement).not.toBeVisible();
      });
    });
  });
});