-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
import { vi, beforeEach, expect, test } from 'vitest' | ||
import { Notification } from 'electron' | ||
import ReadAloud from '../../src/automations/readaloud' | ||
import * as window from '../../src/main/window' | ||
|
||
// mock electron | ||
vi.mock('electron', async() => { | ||
const Notification = vi.fn(); | ||
Notification.prototype.show = vi.fn(); | ||
return { | ||
Notification | ||
} | ||
}) | ||
|
||
// mock windows | ||
vi.mock('../../src/main/window.ts', async () => { | ||
return { | ||
hideWindows: vi.fn(), | ||
restoreWindows: vi.fn(), | ||
releaseFocus: vi.fn(), | ||
openReadAloudPalette: vi.fn(), | ||
isMainWindowFocused: vi.fn(() => false), | ||
} | ||
}) | ||
|
||
vi.mock('../../src/main/utils', async () => { | ||
return { | ||
wait: vi.fn(), | ||
putCachedText: vi.fn(() => 'textId') | ||
} | ||
}) | ||
|
||
// mock automator | ||
vi.mock('../../src/automations/automator.ts', async () => { | ||
let call = -1 | ||
const Automator = vi.fn() | ||
Automator.prototype.getSelectedText = vi.fn(() => { | ||
if (++call === 0) return 'Grabbed text' | ||
else if (call === 1) return '' | ||
else return null | ||
}) | ||
return { default: Automator } | ||
}) | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
test('Open readaloud window', async () => { | ||
await ReadAloud.read() | ||
expect(window.hideWindows).toHaveBeenCalled() | ||
expect(window.releaseFocus).toHaveBeenCalled() | ||
expect(window.openReadAloudPalette).toHaveBeenCalledWith('textId') | ||
}) | ||
|
||
test('Show no text error notification', async () => { | ||
await ReadAloud.read() | ||
expect(window.hideWindows).toHaveBeenCalled() | ||
expect(window.releaseFocus).toHaveBeenCalled() | ||
expect(Notification).toHaveBeenCalledWith({ title: 'Witsy', body: 'Please highlight the text you want to read aloud' }) | ||
}) | ||
|
||
test('Show no grab error notification', async () => { | ||
await ReadAloud.read() | ||
expect(window.hideWindows).toHaveBeenCalled() | ||
expect(window.releaseFocus).toHaveBeenCalled() | ||
expect(Notification).toHaveBeenCalledWith({ title: 'Witsy', body: 'An error occurred while trying to grab the text. Please check Privacy & Security settings.' }) | ||
}) |
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,43 @@ | ||
|
||
import { vi, beforeEach, expect, test } from 'vitest' | ||
import Transcriber from '../../src/automations/transcriber' | ||
import Automator from '../../src/automations/automator' | ||
import * as window from '../../src/main/window' | ||
|
||
// mock windows | ||
vi.mock('../../src/main/window.ts', async () => { | ||
return { | ||
hideWindows: vi.fn(), | ||
restoreWindows: vi.fn(), | ||
releaseFocus: vi.fn(), | ||
openTranscribePalette: vi.fn(), | ||
closeTranscribePalette: vi.fn(), | ||
isMainWindowFocused: vi.fn(() => false), | ||
} | ||
}) | ||
|
||
// mock automator | ||
vi.mock('../../src/automations/automator.ts', async () => { | ||
const Automator = vi.fn() | ||
Automator.prototype.pasteText = vi.fn() | ||
return { default: Automator } | ||
}) | ||
|
||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
test('Open transcriber window', async () => { | ||
await Transcriber.initTranscription() | ||
expect(window.hideWindows).toHaveBeenCalled() | ||
expect(window.releaseFocus).toHaveBeenCalled() | ||
expect(window.openTranscribePalette).toHaveBeenCalledWith() | ||
}) | ||
|
||
test('Insert transcription', async () => { | ||
await Transcriber.insertTranscription('Hello, World!') | ||
expect(window.closeTranscribePalette).toHaveBeenCalled() | ||
expect(window.releaseFocus).toHaveBeenCalled() | ||
expect(Automator.prototype.pasteText).toHaveBeenCalledWith('Hello, World!') | ||
}) |
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