-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add command to reset state * Add tests
- Loading branch information
Showing
8 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Memento } from 'vscode' | ||
import { resetPersistedState } from './util' | ||
import { RegisteredCommands } from '../commands/external' | ||
import { InternalCommands } from '../commands/internal' | ||
|
||
export const registerPersistenceCommands = ( | ||
workspaceState: Memento, | ||
internalCommands: InternalCommands | ||
) => { | ||
internalCommands.registerExternalCommand(RegisteredCommands.RESET_STATE, () => | ||
resetPersistedState(workspaceState) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { commands } from 'vscode' | ||
import { PersistenceKey } from './constants' | ||
import { resetPersistedState } from './util' | ||
import { buildMockMemento } from '../test/util' | ||
import { | ||
DEFAULT_HEIGHT, | ||
DEFAULT_SECTION_NB_ITEMS_PER_ROW | ||
} from '../plots/webview/contract' | ||
|
||
jest.mock('vscode') | ||
|
||
const mockedCommands = jest.mocked(commands) | ||
mockedCommands.executeCommand = jest.fn() | ||
|
||
describe('Persistence util', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
describe('resetPersistedState', () => { | ||
it('should reload the window', async () => { | ||
const workspaceState = buildMockMemento() | ||
|
||
await resetPersistedState(workspaceState) | ||
|
||
expect(mockedCommands.executeCommand).toHaveBeenCalledWith( | ||
'workbench.action.reloadWindow' | ||
) | ||
}) | ||
|
||
it('should reset all values from all dvc roots', async () => { | ||
const persistedState = { | ||
[PersistenceKey.PLOT_HEIGHT + 'root1']: DEFAULT_HEIGHT, | ||
[PersistenceKey.PLOT_NB_ITEMS_PER_ROW + 'root2']: | ||
DEFAULT_SECTION_NB_ITEMS_PER_ROW | ||
} | ||
const workspaceState = buildMockMemento(persistedState) | ||
|
||
await resetPersistedState(workspaceState) | ||
|
||
expect( | ||
workspaceState.get(PersistenceKey.PLOT_HEIGHT + 'root1') | ||
).toBeUndefined() | ||
expect( | ||
workspaceState.get(PersistenceKey.PLOT_NB_ITEMS_PER_ROW + 'root2') | ||
).toBeUndefined() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { commands, Memento } from 'vscode' | ||
|
||
export const resetPersistedState = async (workspaceState: Memento) => { | ||
for (const persistenceKey of workspaceState.keys()) { | ||
await workspaceState.update(persistenceKey, undefined) | ||
} | ||
|
||
await commands.executeCommand('workbench.action.reloadWindow') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters