Skip to content

Commit

Permalink
app tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed May 17, 2024
1 parent 356f0a0 commit 1b103eb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ onMounted(() => {
}[window.api.platform]||''
// add it everywhere
window.platform = platform
document.platform = platform
document.querySelector('body').classList.add(platform)
if (platform) {
window.platform = platform
document.platform = platform
document.querySelector('body').classList.add(platform)
}
})
Expand All @@ -38,7 +40,7 @@ const routes = {
const currentPath = ref(window.location.hash)
const currentView = computed(() => {
//console.log(currentPath.value)
//console.log(currentPath.value.slice(1) || '/')
return routes[currentPath.value.slice(1) || '/']
})
Expand Down
62 changes: 62 additions & 0 deletions tests/screens/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

import { vi, beforeEach, expect, test, afterAll } from 'vitest'
import { enableAutoUnmount, mount } from '@vue/test-utils'
import App from '../../src/App.vue'
import Main from '../../src/screens/Main.vue'
import Wait from '../../src/screens/Wait.vue'
import Commands from '../../src/screens/Commands.vue'
import PromptAnywhere from '../../src/screens/PromptAnywhere.vue'
import defaults from '../../defaults/settings.json'

enableAutoUnmount(afterAll)

window.api = {
config: {
load: vi.fn(() => defaults),
},
commands: {
load: vi.fn(() => []),
},
prompts: {
load: vi.fn(() => []),
},
history: {
load: vi.fn(() => []),
},
on: vi.fn(),
}

test('Renders correctly', () => {
window.location = new URL('http://localhost/')
mount(App)
})

test('Renders Main', () => {
window.location = new URL('http://localhost/')
const wrapper = mount(App)
expect(wrapper.findComponent(Main).exists()).toBe(true)
})

test('Renders Wait', () => {
window.location = new URL('http://localhost/#/wait')
const wrapper = mount(App)
expect(wrapper.findComponent(Wait).exists()).toBe(true)
})

test('Renders Commands', () => {
window.location = new URL('http://localhost/#/command')
const wrapper = mount(App)
expect(wrapper.findComponent(Commands).exists()).toBe(true)
})

test('Renders PromptAnywhere', () => {
window.location = new URL('http://localhost/#/prompt')
const wrapper = mount(App)
expect(wrapper.findComponent(PromptAnywhere).exists()).toBe(true)
})

test('Transmits query params', () => {
window.location = new URL('http://localhost/?textId=6#/command')
const wrapper = mount(App)
expect(wrapper.findComponent(Commands).props().extra.textId).toBe('6')
})

0 comments on commit 1b103eb

Please sign in to comment.