orderthings-spec.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use babel';
  2. import Orderthings from '../lib/orderthings';
  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('Orderthings', () => {
  8. let workspaceElement, activationPromise;
  9. beforeEach(() => {
  10. workspaceElement = atom.views.getView(atom.workspace);
  11. activationPromise = atom.packages.activatePackage('orderthings');
  12. });
  13. describe('when the orderthings: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('.orderthings')).not.toExist();
  18. // This is an activation event, triggering it will cause the package to be
  19. // activated.
  20. atom.commands.dispatch(workspaceElement, 'orderthings:toggle');
  21. waitsForPromise(() => {
  22. return activationPromise;
  23. });
  24. runs(() => {
  25. expect(workspaceElement.querySelector('.orderthings')).toExist();
  26. let orderthingsElement = workspaceElement.querySelector('.orderthings');
  27. expect(orderthingsElement).toExist();
  28. let orderthingsPanel = atom.workspace.panelForItem(orderthingsElement);
  29. expect(orderthingsPanel.isVisible()).toBe(true);
  30. atom.commands.dispatch(workspaceElement, 'orderthings:toggle');
  31. expect(orderthingsPanel.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('.orderthings')).not.toExist();
  42. // This is an activation event, triggering it causes the package to be
  43. // activated.
  44. atom.commands.dispatch(workspaceElement, 'orderthings:toggle');
  45. waitsForPromise(() => {
  46. return activationPromise;
  47. });
  48. runs(() => {
  49. // Now we can test for view visibility
  50. let orderthingsElement = workspaceElement.querySelector('.orderthings');
  51. expect(orderthingsElement).toBeVisible();
  52. atom.commands.dispatch(workspaceElement, 'orderthings:toggle');
  53. expect(orderthingsElement).not.toBeVisible();
  54. });
  55. });
  56. });
  57. });