1
0

qsp-spec.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use babel';
  2. import Qsp from '../lib/qsp';
  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. describe('Qsp', () => {
  8. let workspaceElement, activationPromise;
  9. beforeEach(() => {
  10. workspaceElement = atom.views.getView(atom.workspace);
  11. activationPromise = atom.packages.activatePackage('qsp');
  12. });
  13. describe('when the qsp:toggle event is triggered', () => {
  14. it('hides and shows the modal panel', () => {
  15. // Before the activation event the view is not on the DOM, and no panel
  16. // has been created
  17. expect(workspaceElement.querySelector('.qsrc')).not.toExist();
  18. // This is an activation event, triggering it will cause the package to be
  19. // activated.
  20. atom.commands.dispatch(workspaceElement, 'qsp:toggle');
  21. waitsForPromise(() => {
  22. return activationPromise;
  23. });
  24. runs(() => {
  25. expect(workspaceElement.querySelector('.qsrc')).toExist();
  26. let qspElement = workspaceElement.querySelector('.qsrc');
  27. expect(qspElement).toExist();
  28. let qspPanel = atom.workspace.panelForItem(qspElement);
  29. expect(qspPanel.isVisible()).toBe(true);
  30. atom.commands.dispatch(workspaceElement, 'qsp:toggle');
  31. expect(qspPanel.isVisible()).toBe(false);
  32. });
  33. });
  34. it('hides and shows the view', () => {
  35. // This test shows you an integration test testing at the view level.
  36. // Attaching the workspaceElement to the DOM is required to allow the
  37. // `toBeVisible()` matchers to work. Anything testing visibility or focus
  38. // requires that the workspaceElement is on the DOM. Tests that attach the
  39. // workspaceElement to the DOM are generally slower than those off DOM.
  40. jasmine.attachToDOM(workspaceElement);
  41. expect(workspaceElement.querySelector('.qsrc')).not.toExist();
  42. // This is an activation event, triggering it causes the package to be
  43. // activated.
  44. atom.commands.dispatch(workspaceElement, 'qsp:toggle');
  45. waitsForPromise(() => {
  46. return activationPromise;
  47. });
  48. runs(() => {
  49. // Now we can test for view visibility
  50. let qspElement = workspaceElement.querySelector('.qsrc');
  51. expect(qspElement).toBeVisible();
  52. atom.commands.dispatch(workspaceElement, 'qsp:toggle');
  53. expect(qspElement).not.toBeVisible();
  54. });
  55. });
  56. });
  57. });