Skip to content

Commit

Permalink
Reset shift interval when user ignores a color theme or font family (f…
Browse files Browse the repository at this point in the history
…ixes #13)
  • Loading branch information
bmealhouse committed Jan 11, 2020
1 parent 994e02c commit a7b09c4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.0.1] - 2020-01-11

### Fixed

- Reset the shift interval when the user ignores a color theme or font family
- Restore spies at the end of tests

## [2.0.0] - 2020-01-11

### Added
Expand Down
15 changes: 11 additions & 4 deletions src/color-themes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ test(`shifts the color theme when running the "${commandMap.SHIFT_COLOR_THEME}"

const [,secondCall] = spy.mock.calls
expect(secondCall).toEqual([commandMap.RESET_SHIFT_INTERVAL])

spy.mockRestore()
})

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

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

const {ignoreColorThemes} = vscode.workspace.getConfiguration(
'shifty.colorThemes',
)
expect(ignoreColorThemes).toContain(DEFAULT_COLOR_THEME.id)

const [firstCall] = spy.mock.calls
const [firstCall] = showInformationMessaageSpy.mock.calls
expect(formatSnapshot(firstCall)).toMatchInlineSnapshot(
`"['Ignored \\"Default Dark+\\"']"`,
)

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

spy.mockRestore()
const [, secondCall] =executeCommandSpy.mock.calls
expect(secondCall).toEqual([commandMap.RESET_SHIFT_INTERVAL])

showInformationMessaageSpy.mockRestore()
executeCommandSpy.mockRestore()
})

// prettier-ignore
Expand Down
10 changes: 5 additions & 5 deletions src/color-themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ export function activateColorThemes(context: vscode.ExtensionContext): void {

context.subscriptions.push(
vscode.commands.registerCommand(commandMap.IGNORE_COLOR_THEME, async () => {
const colorTheme = await ignoreColorTheme()
const colorTheme = getColorTheme()
await ignoreColorTheme(colorTheme)
vscode.window.showInformationMessage(`Ignored "${colorTheme}"`)

await vscode.commands.executeCommand(commandMap.RESET_SHIFT_INTERVAL)
}),
)

Expand Down Expand Up @@ -121,9 +124,7 @@ export async function unfavoriteColorTheme(colorTheme: string): Promise<void> {
)
}

export async function ignoreColorTheme(): Promise<string> {
const colorTheme = getColorTheme()

export async function ignoreColorTheme(colorTheme: string): Promise<void> {
const config = vscode.workspace.getConfiguration('shifty.colorThemes')
const ignoreColorThemes = config.get<string[]>('ignoreColorThemes', [])
const favoriteColorThemes = config.get<string[]>('favoriteColorThemes', [])
Expand All @@ -141,7 +142,6 @@ export async function ignoreColorTheme(): Promise<string> {
)

await shiftColorTheme()
return colorTheme
}

export function getColorTheme(): string {
Expand Down
2 changes: 2 additions & 0 deletions src/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ test(`shifts the color theme and font family when running the "${commandMap.SHIF

const [,secondCall] = spy.mock.calls
expect(secondCall).toEqual([commandMap.RESET_SHIFT_INTERVAL])

spy.mockRestore()
})
15 changes: 11 additions & 4 deletions src/font-families/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ test(`shifts the font family when running the "${commandMap.SHIFT_FONT_FAMILY}"

const [,secondCall] = spy.mock.calls
expect(secondCall).toEqual([commandMap.RESET_SHIFT_INTERVAL])

spy.mockRestore()
})

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

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

const {ignoreFontFamilies} = vscode.workspace.getConfiguration(
'shifty.fontFamilies',
)
expect(ignoreFontFamilies).toContain(DEFAULT_FONT_FAMILY.id)

const [firstCall] = spy.mock.calls
const [firstCall] = showInformationMessageSpy.mock.calls
expect(formatSnapshot(firstCall)).toMatchInlineSnapshot(
`"['Ignored \\"Courier New\\"']"`,
)

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

spy.mockRestore()
const [, secondCall] = executeCommandSpy.mock.calls
expect(secondCall).toEqual([commandMap.RESET_SHIFT_INTERVAL])

showInformationMessageSpy.mockRestore()
executeCommandSpy.mockRestore()
})

// prettier-ignore
Expand Down
10 changes: 5 additions & 5 deletions src/font-families/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ export function activateFontFamilies(context: vscode.ExtensionContext): void {

context.subscriptions.push(
vscode.commands.registerCommand(commandMap.IGNORE_FONT_FAMILY, async () => {
const fontFamily = await ignoreFontFamily()
const fontFamily = getFontFamily()
await ignoreFontFamily(fontFamily)
vscode.window.showInformationMessage(`Ignored "${fontFamily}"`)

vscode.commands.executeCommand(commandMap.RESET_SHIFT_INTERVAL)
}),
)

Expand Down Expand Up @@ -126,9 +129,7 @@ export async function unfavoriteFontFamily(fontFamily: string): Promise<void> {
)
}

export async function ignoreFontFamily(): Promise<string> {
const fontFamily = getFontFamily()

export async function ignoreFontFamily(fontFamily: string): Promise<void> {
const config = vscode.workspace.getConfiguration('shifty.fontFamilies')
const favoriteFontFamilies = config.get<string[]>('favoriteFontFamilies', [])
const ignoreFontFamilies = config.get<string[]>('ignoreFontFamilies', [])
Expand All @@ -146,7 +147,6 @@ export async function ignoreFontFamily(): Promise<string> {
)

await shiftFontFamily()
return fontFamily
}

export function getFontFamily(): string {
Expand Down

0 comments on commit a7b09c4

Please sign in to comment.