Skip to content

Commit a7b09c4

Browse files
committed
Reset shift interval when user ignores a color theme or font family (fixes #13)
1 parent 994e02c commit a7b09c4

File tree

6 files changed

+41
-18
lines changed

6 files changed

+41
-18
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [2.0.1] - 2020-01-11
11+
12+
### Fixed
13+
14+
- Reset the shift interval when the user ignores a color theme or font family
15+
- Restore spies at the end of tests
16+
1017
## [2.0.0] - 2020-01-11
1118

1219
### Added

src/color-themes.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ test(`shifts the color theme when running the "${commandMap.SHIFT_COLOR_THEME}"
2525

2626
const [,secondCall] = spy.mock.calls
2727
expect(secondCall).toEqual([commandMap.RESET_SHIFT_INTERVAL])
28+
29+
spy.mockRestore()
2830
})
2931

3032
// prettier-ignore
@@ -67,23 +69,28 @@ test(`unfavorites the current color theme when running the "${commandMap.TOGGLE_
6769
})
6870

6971
// prettier-ignore
70-
test(`ignores the current color theme and shifts the color theme when running the "${commandMap.IGNORE_COLOR_THEME}" command`, async () => {
71-
const spy = jest.spyOn(vscode.window, 'showInformationMessage')
72+
test(`ignores the current color theme, shifts the color theme, and resets the shift interval when running the "${commandMap.IGNORE_COLOR_THEME}" command`, async () => {
73+
const showInformationMessaageSpy = jest.spyOn(vscode.window, 'showInformationMessage')
74+
const executeCommandSpy = jest.spyOn(vscode.commands, 'executeCommand')
7275
await vscode.commands.executeCommand(commandMap.IGNORE_COLOR_THEME)
7376

7477
const {ignoreColorThemes} = vscode.workspace.getConfiguration(
7578
'shifty.colorThemes',
7679
)
7780
expect(ignoreColorThemes).toContain(DEFAULT_COLOR_THEME.id)
7881

79-
const [firstCall] = spy.mock.calls
82+
const [firstCall] = showInformationMessaageSpy.mock.calls
8083
expect(formatSnapshot(firstCall)).toMatchInlineSnapshot(
8184
`"['Ignored \\"Default Dark+\\"']"`,
8285
)
8386

8487
expect(getColorTheme()).not.toBe(DEFAULT_COLOR_THEME.id)
8588

86-
spy.mockRestore()
89+
const [, secondCall] =executeCommandSpy.mock.calls
90+
expect(secondCall).toEqual([commandMap.RESET_SHIFT_INTERVAL])
91+
92+
showInformationMessaageSpy.mockRestore()
93+
executeCommandSpy.mockRestore()
8794
})
8895

8996
// prettier-ignore

src/color-themes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ export function activateColorThemes(context: vscode.ExtensionContext): void {
5656

5757
context.subscriptions.push(
5858
vscode.commands.registerCommand(commandMap.IGNORE_COLOR_THEME, async () => {
59-
const colorTheme = await ignoreColorTheme()
59+
const colorTheme = getColorTheme()
60+
await ignoreColorTheme(colorTheme)
6061
vscode.window.showInformationMessage(`Ignored "${colorTheme}"`)
62+
63+
await vscode.commands.executeCommand(commandMap.RESET_SHIFT_INTERVAL)
6164
}),
6265
)
6366

@@ -121,9 +124,7 @@ export async function unfavoriteColorTheme(colorTheme: string): Promise<void> {
121124
)
122125
}
123126

124-
export async function ignoreColorTheme(): Promise<string> {
125-
const colorTheme = getColorTheme()
126-
127+
export async function ignoreColorTheme(colorTheme: string): Promise<void> {
127128
const config = vscode.workspace.getConfiguration('shifty.colorThemes')
128129
const ignoreColorThemes = config.get<string[]>('ignoreColorThemes', [])
129130
const favoriteColorThemes = config.get<string[]>('favoriteColorThemes', [])
@@ -141,7 +142,6 @@ export async function ignoreColorTheme(): Promise<string> {
141142
)
142143

143144
await shiftColorTheme()
144-
return colorTheme
145145
}
146146

147147
export function getColorTheme(): string {

src/extension.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ test(`shifts the color theme and font family when running the "${commandMap.SHIF
1919

2020
const [,secondCall] = spy.mock.calls
2121
expect(secondCall).toEqual([commandMap.RESET_SHIFT_INTERVAL])
22+
23+
spy.mockRestore()
2224
})

src/font-families/index.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ test(`shifts the font family when running the "${commandMap.SHIFT_FONT_FAMILY}"
7474

7575
const [,secondCall] = spy.mock.calls
7676
expect(secondCall).toEqual([commandMap.RESET_SHIFT_INTERVAL])
77+
78+
spy.mockRestore()
7779
})
7880

7981
// prettier-ignore
@@ -116,23 +118,28 @@ test(`unfavorites the current font family when running the "${commandMap.TOGGLE_
116118
})
117119

118120
// prettier-ignore
119-
test(`ignores the current font family and shift the font family when running the "${commandMap.IGNORE_FONT_FAMILY}" command`, async () => {
120-
const spy = jest.spyOn(vscode.window, 'showInformationMessage')
121+
test(`ignores the current font family, shifts the font family, and resets the shift interval when running the "${commandMap.IGNORE_FONT_FAMILY}" command`, async () => {
122+
const showInformationMessageSpy = jest.spyOn(vscode.window, 'showInformationMessage')
123+
const executeCommandSpy = jest.spyOn(vscode.commands, 'executeCommand')
121124
await vscode.commands.executeCommand(commandMap.IGNORE_FONT_FAMILY)
122125

123126
const {ignoreFontFamilies} = vscode.workspace.getConfiguration(
124127
'shifty.fontFamilies',
125128
)
126129
expect(ignoreFontFamilies).toContain(DEFAULT_FONT_FAMILY.id)
127130

128-
const [firstCall] = spy.mock.calls
131+
const [firstCall] = showInformationMessageSpy.mock.calls
129132
expect(formatSnapshot(firstCall)).toMatchInlineSnapshot(
130133
`"['Ignored \\"Courier New\\"']"`,
131134
)
132135

133136
expect(getFontFamily()).not.toBe(DEFAULT_FONT_FAMILY.id)
134137

135-
spy.mockRestore()
138+
const [, secondCall] = executeCommandSpy.mock.calls
139+
expect(secondCall).toEqual([commandMap.RESET_SHIFT_INTERVAL])
140+
141+
showInformationMessageSpy.mockRestore()
142+
executeCommandSpy.mockRestore()
136143
})
137144

138145
// prettier-ignore

src/font-families/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ export function activateFontFamilies(context: vscode.ExtensionContext): void {
6767

6868
context.subscriptions.push(
6969
vscode.commands.registerCommand(commandMap.IGNORE_FONT_FAMILY, async () => {
70-
const fontFamily = await ignoreFontFamily()
70+
const fontFamily = getFontFamily()
71+
await ignoreFontFamily(fontFamily)
7172
vscode.window.showInformationMessage(`Ignored "${fontFamily}"`)
73+
74+
vscode.commands.executeCommand(commandMap.RESET_SHIFT_INTERVAL)
7275
}),
7376
)
7477

@@ -126,9 +129,7 @@ export async function unfavoriteFontFamily(fontFamily: string): Promise<void> {
126129
)
127130
}
128131

129-
export async function ignoreFontFamily(): Promise<string> {
130-
const fontFamily = getFontFamily()
131-
132+
export async function ignoreFontFamily(fontFamily: string): Promise<void> {
132133
const config = vscode.workspace.getConfiguration('shifty.fontFamilies')
133134
const favoriteFontFamilies = config.get<string[]>('favoriteFontFamilies', [])
134135
const ignoreFontFamilies = config.get<string[]>('ignoreFontFamilies', [])
@@ -146,7 +147,6 @@ export async function ignoreFontFamily(): Promise<string> {
146147
)
147148

148149
await shiftFontFamily()
149-
return fontFamily
150150
}
151151

152152
export function getFontFamily(): string {

0 commit comments

Comments
 (0)