diff --git a/src/App.vue b/src/App.vue index 7a4d1ad..a5490fc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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) + } }) @@ -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) || '/'] }) diff --git a/tests/screens/app.test.ts b/tests/screens/app.test.ts new file mode 100644 index 0000000..8ebf463 --- /dev/null +++ b/tests/screens/app.test.ts @@ -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') +})