|
1 |
| -/** @babel */ |
| 1 | +const {it, fit, ffit, fffit, beforeEach, afterEach} = require('./async-spec-helpers') |
| 2 | +const {Emitter, Disposable, CompositeDisposable} = require('event-kit') |
2 | 3 |
|
3 |
| -import {it, fit, ffit, fffit, beforeEach, afterEach} from './async-spec-helpers' |
4 |
| -import {Emitter, Disposable, CompositeDisposable} from 'event-kit' |
5 |
| - |
6 |
| -import {HistoryManager, HistoryProject} from '../src/history-manager' |
7 |
| -import StateStore from '../src/state-store' |
| 4 | +const {HistoryManager, HistoryProject} = require('../src/history-manager') |
| 5 | +const StateStore = require('../src/state-store') |
8 | 6 |
|
9 | 7 | describe("HistoryManager", () => {
|
10 | 8 | let historyManager, commandRegistry, project, stateStore
|
11 | 9 | let commandDisposable, projectDisposable
|
12 | 10 |
|
13 | 11 | beforeEach(async () => {
|
14 |
| - // Do not clobber recent project history |
15 |
| - spyOn(atom.applicationDelegate, 'didChangeHistoryManager') |
16 |
| - |
17 | 12 | commandDisposable = jasmine.createSpyObj('Disposable', ['dispose'])
|
18 | 13 | commandRegistry = jasmine.createSpyObj('CommandRegistry', ['add'])
|
19 | 14 | commandRegistry.add.andReturn(commandDisposable)
|
@@ -185,11 +180,26 @@ describe("HistoryManager", () => {
|
185 | 180 | })
|
186 | 181 | })
|
187 | 182 |
|
188 |
| - describe("saveState" ,() => { |
| 183 | + describe("saveState", () => { |
| 184 | + let savedHistory |
| 185 | + beforeEach(() => { |
| 186 | + // historyManager.saveState is spied on globally to prevent specs from |
| 187 | + // modifying the shared project history. Since these tests depend on |
| 188 | + // saveState, we unspy it but in turn spy on the state store instead |
| 189 | + // so that no data is actually stored to it. |
| 190 | + jasmine.unspy(historyManager, 'saveState') |
| 191 | + |
| 192 | + spyOn(historyManager.stateStore, 'save').andCallFake((name, history) => { |
| 193 | + savedHistory = history |
| 194 | + return Promise.resolve() |
| 195 | + }) |
| 196 | + }) |
| 197 | + |
189 | 198 | it("saves the state", async () => {
|
190 | 199 | await historyManager.addProject(["/save/state"])
|
191 | 200 | await historyManager.saveState()
|
192 | 201 | const historyManager2 = new HistoryManager({stateStore, project, commands: commandRegistry})
|
| 202 | + spyOn(historyManager2.stateStore, 'load').andCallFake(name => Promise.resolve(savedHistory)) |
193 | 203 | await historyManager2.loadState()
|
194 | 204 | expect(historyManager2.getProjects()[0].paths).toEqual(['/save/state'])
|
195 | 205 | })
|
|
0 commit comments