pulsar-updater-spec.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. function wait(ms) {
  2. return new Promise(resolve => setTimeout(resolve, ms, true));
  3. }
  4. describe('PulsarUpdater', () => {
  5. let pack, workspaceElement;
  6. beforeEach(async () => {
  7. atom.config.set("pulsar-updater.checkForUpdatesOnLaunch", false);
  8. workspaceElement = atom.views.getView(atom.workspace);
  9. pack = await atom.packages.activatePackage('pulsar-updater');
  10. pack.mainModule.cache?.empty("last-update-check");
  11. });
  12. afterEach(async () => {
  13. pack.mainModule.cache?.empty("last-update-check");
  14. await atom.packages.deactivatePackage('pulsar-updater');
  15. });
  16. describe('when pulsar-updater:check-for-updates is triggered', () => {
  17. beforeEach(async () => {
  18. spyOn(pack.mainModule, 'checkForUpdates');
  19. })
  20. it('triggers an update check', () => {
  21. atom.commands.dispatch(workspaceElement, 'pulsar-updater:check-for-update');
  22. expect(pack.mainModule.checkForUpdates).toHaveBeenCalled();
  23. });
  24. });
  25. describe("when the remote version is greater than ours", () => {
  26. beforeEach(() => {
  27. spyOn(atom, "getVersion").andReturn("1.0.0");
  28. spyOn(pack.mainModule, 'findNewestRelease').andCallFake(() => {
  29. return "2.0.0";
  30. })
  31. spyOn(pack.mainModule, 'notifyAboutUpdate').andCallThrough();
  32. spyOn(pack.mainModule, 'notifyAboutCurrent').andCallThrough();
  33. });
  34. afterEach(() => {
  35. pack.mainModule.notifyAboutUpdate.reset();
  36. pack.mainModule.notifyAboutCurrent.reset();
  37. })
  38. it("signals that the user should update", async () => {
  39. jasmine.useRealClock();
  40. atom.commands.dispatch(workspaceElement, 'pulsar-updater:check-for-update');
  41. await wait(200);
  42. expect(pack.mainModule.notifyAboutUpdate).toHaveBeenCalledWith("2.0.0");
  43. expect(pack.mainModule.notifyAboutCurrent).not.toHaveBeenCalled();
  44. });
  45. });
  46. describe("when the remote version is equal to ours", () => {
  47. beforeEach(() => {
  48. spyOn(atom, "getVersion").andReturn("1.0.5");
  49. spyOn(pack.mainModule, 'findNewestRelease').andCallFake(() => {
  50. return "1.0.5";
  51. })
  52. spyOn(pack.mainModule, 'notifyAboutUpdate');
  53. spyOn(pack.mainModule, 'notifyAboutCurrent');
  54. });
  55. it("takes no action", async () => {
  56. jasmine.useRealClock();
  57. atom.commands.dispatch(workspaceElement, 'pulsar-updater:check-for-update');
  58. await wait(200);
  59. expect(pack.mainModule.notifyAboutUpdate).not.toHaveBeenCalled();
  60. expect(pack.mainModule.notifyAboutCurrent).toHaveBeenCalledWith("1.0.5", true);
  61. });
  62. });
  63. describe("when the user tells us to ignore until the next version", () => {
  64. let latestVersion = "1.0.6";
  65. beforeEach(() => {
  66. spyOn(atom, "getVersion").andReturn("1.0.5");
  67. spyOn(pack.mainModule, 'findNewestRelease').andCallFake(() => {
  68. return latestVersion;
  69. });
  70. spyOn(pack.mainModule, 'notifyAboutUpdate').andCallThrough();
  71. spyOn(pack.mainModule, 'notifyAboutCurrent').andCallThrough();
  72. });
  73. it("subsequent checks do not result in notifications", async () => {
  74. jasmine.useRealClock();
  75. atom.commands.dispatch(workspaceElement, 'pulsar-updater:check-for-update');
  76. await wait(200);
  77. expect(pack.mainModule.notifyAboutUpdate).toHaveBeenCalledWith("1.0.6");
  78. expect(pack.mainModule.notifyAboutCurrent).not.toHaveBeenCalled();
  79. pack.mainModule.ignoreForThisVersion("1.0.6");
  80. // Calling the method directly here because eventually we'll want a
  81. // user-initiated check for updates to ignore this cache.
  82. pack.mainModule.checkForUpdates();
  83. await wait(200);
  84. expect(pack.mainModule.notifyAboutUpdate.callCount).toBe(1);
  85. expect(pack.mainModule.notifyAboutCurrent).not.toHaveBeenCalled();
  86. latestVersion = "1.0.7";
  87. pack.mainModule.checkForUpdates();
  88. await wait(200);
  89. expect(pack.mainModule.notifyAboutUpdate).toHaveBeenCalledWith("1.0.7");
  90. expect(pack.mainModule.notifyAboutCurrent).not.toHaveBeenCalled();
  91. });
  92. });
  93. });