From 021f934ccd0dd12aba183d693bd3471f53631c26 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 1 Jun 2017 15:48:08 -0700 Subject: [PATCH] Fix Pane.close test --- spec/pane-spec.js | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/spec/pane-spec.js b/spec/pane-spec.js index 32d0d3ee9..486881bc6 100644 --- a/spec/pane-spec.js +++ b/spec/pane-spec.js @@ -1162,7 +1162,7 @@ describe('Pane', () => { expect(pane.isDestroyed()).toBe(true) }) - it('does not destroy the pane if cancel is called', async () => { + it('does not destroy the pane if the user clicks cancel', async () => { const pane = new Pane(paneParams({items: [new Item('A'), new Item('B')]})) const [item1] = pane.getItems() @@ -1171,12 +1171,30 @@ describe('Pane', () => { item1.save = jasmine.createSpy('save') confirm.andReturn(1) + await pane.close() expect(confirm).toHaveBeenCalled() expect(item1.save).not.toHaveBeenCalled() expect(pane.isDestroyed()).toBe(false) }) + it('does not destroy the pane if the user starts to save but then does not choose a path', async () => { + const pane = new Pane(paneParams({items: [new Item('A'), new Item('B')]})) + const [item1] = pane.getItems() + + item1.shouldPromptToSave = () => true + item1.saveAs = jasmine.createSpy('saveAs') + + confirm.andReturn(0) + showSaveDialog.andReturn(undefined) + + await pane.close() + expect(atom.applicationDelegate.confirm).toHaveBeenCalled() + expect(confirm.callCount).toBe(1) + expect(item1.saveAs).not.toHaveBeenCalled() + expect(pane.isDestroyed()).toBe(false) + }) + describe('when item fails to save', () => { let pane, item1 @@ -1213,27 +1231,6 @@ describe('Pane', () => { expect(pane.isDestroyed()).toBe(false) }) - it('does not destroy the pane if user starts to save but then does not choose a path', async () => { - item1.saveAs = jasmine.createSpy('saveAs').andReturn(true) - - let confirmationCount = 0 - confirm.andCallFake(() => { - switch (confirmationCount++) { - case 0: return 0 - case 1: return 0 - default: return 1 - } - }) - - showSaveDialog.andReturn(undefined) - - await pane.close() - expect(atom.applicationDelegate.confirm).toHaveBeenCalled() - expect(confirmationCount).toBe(3) - expect(item1.save).toHaveBeenCalled() - expect(pane.isDestroyed()).toBe(false) - }) - it('does destroy the pane if the user saves the file under a new name', async () => { item1.saveAs = jasmine.createSpy('saveAs').andReturn(true)