Skip to content

Commit

Permalink
automator test
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed May 10, 2024
1 parent 543684e commit 38f5ee5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions tests/unit/automator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

import { vi, expect, test } from 'vitest'
import { clipboard } from 'electron'
import Automator from '../../src/automations/automator'
import MacosAutomator from '../../src/automations/macos'
import RobotAutomator from '../../src/automations/robot'

vi.mock('electron', () => ({
clipboard: {
readText: vi.fn(),
writeText: vi.fn()
}
}))

vi.mock(`../../src/automations/${process.platform === 'darwin' ? 'macos' : 'robot'}.ts`, async () => {
const MockAutomator = vi.fn()
MockAutomator.prototype.selectAll = vi.fn()
MockAutomator.prototype.moveCaretBelow = vi.fn()
MockAutomator.prototype.copySelectedText = vi.fn()
MockAutomator.prototype.pasteText = vi.fn()
return { default: MockAutomator }
})

test('Create', async () => {
const automator = new Automator()
expect(automator).toBeTruthy()
})

const prototype = process.platform === 'darwin' ? MacosAutomator.prototype : RobotAutomator.prototype

test('Select all', async () => {
const automator = new Automator()
await automator.selectAll()
expect(prototype.selectAll).toHaveBeenCalled()
})

test('Move caret below', async () => {
const automator = new Automator()
await automator.moveCaretBelow()
expect(prototype.moveCaretBelow).toHaveBeenCalled()
})

test('Get selected text', async () => {
const automator = new Automator()
await automator.getSelectedText()
expect(prototype.copySelectedText).toHaveBeenCalled()
})

test('Paste text', async () => {
const automator = new Automator()
await automator.pasteText('text')
expect(prototype.pasteText).toHaveBeenCalled()
})

test('Copy to clipboard', async () => {
const automator = new Automator()
await automator.copyToClipboard('text')
expect(clipboard.writeText).toHaveBeenCalledWith('text')
})
2 changes: 1 addition & 1 deletion tests/unit/commander.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { Command } from '../../src/types/index.d'
import { vi, beforeEach, expect, test } from 'vitest'
import { Command } from '../../src/types/index.d'
import { store } from '../../src/services/store'
import defaults from '../../defaults/settings.json'
import * as commander from '../../src/automations/commander'
Expand Down

0 comments on commit 38f5ee5

Please sign in to comment.