diff options
| author | Kit La Touche <kit@transneptune.net> | 2024-11-14 23:28:19 -0500 |
|---|---|---|
| committer | Kit La Touche <kit@transneptune.net> | 2024-11-14 23:28:19 -0500 |
| commit | 3a89459f8b48449b341469776a37d8b225e956f2 (patch) | |
| tree | f0b2e6726a350edd4bbd12e6d2119cd0b4ef433a /ui | |
| parent | b13b5b617022a679d93128bbee6032ea1bb31147 (diff) | |
Stub in tests
Diffstat (limited to 'ui')
6 files changed, 61 insertions, 19 deletions
diff --git a/ui/tests/lib/components/ChangePassword.svelte.test.js b/ui/tests/lib/components/ChangePassword.svelte.test.js index 6e0e652..09aa992 100644 --- a/ui/tests/lib/components/ChangePassword.svelte.test.js +++ b/ui/tests/lib/components/ChangePassword.svelte.test.js @@ -1,28 +1,35 @@ -// async onsubmit(event) -// -// Example: -/* */ import { flushSync, mount, unmount } from 'svelte'; -import { expect, test } from 'vitest'; +import { afterEach, describe, beforeEach, expect, test, vi } from 'vitest'; import ChangePassword from '$lib/components/ChangePassword.svelte'; +import axios from 'axios'; +vi.mock('axios'); -test('ChangePassword', () => { - // Instantiate the component using Svelte's `mount` API - const component = mount(ChangePassword, { - target: document.body, // `document` exists because of jsdom - props: { initial: 0 } - }); +describe('ChangePassword', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); - expect(document.body.innerHTML).toBe('<button>0</button>'); + test('onsubmit happy path', async () => { + axios.post.mockResolvedValue({ status: 200 }); - // Click the button, then flush the changes so you can synchronously write expectations - document.body.querySelector('button').click(); - flushSync(); + // Instantiate the component using Svelte's `mount` API + const component = mount(ChangePassword, { + target: document.body, // `document` exists because of jsdom + }); + flushSync(); - expect(document.body.innerHTML).toBe('<button>1</button>'); + // Set value in all three inputs at once: + const inputs = document.body.querySelectorAll('input[type=password]'); + inputs.value = 'pass'; + // Click the button, then flush the changes so you can synchronously write expectations + document.body.querySelector('button[type=submit]').click(); + flushSync(); - // Remove the component from the DOM - unmount(component); + // expect(axios.post).toHaveBeenCalledWith('/password', { password: 'pass', to: 'pass' }); + expect(Array.from(inputs.values()).map((i) => i.value)).toEqual(['', '', '']); + + // Remove the component from the DOM + unmount(component); + }); }); -/* */ diff --git a/ui/tests/lib/components/CreateChannelForm.svelte.test.js b/ui/tests/lib/components/CreateChannelForm.svelte.test.js index 0380e01..31f7462 100644 --- a/ui/tests/lib/components/CreateChannelForm.svelte.test.js +++ b/ui/tests/lib/components/CreateChannelForm.svelte.test.js @@ -1 +1,8 @@ // async handleSubmit(event) +import { describe, expect, test } from 'vitest'; + +describe('CreateChannelForm', () => { + test('stub', async () => { + expect(true).toBeTruthy(); + }); +}); diff --git a/ui/tests/lib/components/Invite.svelte.test.js b/ui/tests/lib/components/Invite.svelte.test.js index e4383cc..5d5742e 100644 --- a/ui/tests/lib/components/Invite.svelte.test.js +++ b/ui/tests/lib/components/Invite.svelte.test.js @@ -1 +1,8 @@ // async onsubmit(event) +import { describe, expect, test } from 'vitest'; + +describe('Invite', () => { + test('stub', async () => { + expect(true).toBeTruthy(); + }); +}); diff --git a/ui/tests/lib/components/LogOut.svelte.test.js b/ui/tests/lib/components/LogOut.svelte.test.js index e4383cc..65d78a9 100644 --- a/ui/tests/lib/components/LogOut.svelte.test.js +++ b/ui/tests/lib/components/LogOut.svelte.test.js @@ -1 +1,8 @@ // async onsubmit(event) +import { describe, expect, test } from 'vitest'; + +describe('LogOut', () => { + test('stub', async () => { + expect(true).toBeTruthy(); + }); +}); diff --git a/ui/tests/lib/components/Message.svelte.test.js b/ui/tests/lib/components/Message.svelte.test.js index d29a371..2ca0b85 100644 --- a/ui/tests/lib/components/Message.svelte.test.js +++ b/ui/tests/lib/components/Message.svelte.test.js @@ -1,2 +1,9 @@ // onDelete(event) // onmouseleave() +import { describe, expect, test } from 'vitest'; + +describe('Message', () => { + test('stub', async () => { + expect(true).toBeTruthy(); + }); +}); diff --git a/ui/tests/lib/components/MessageInput.svelte.test.js b/ui/tests/lib/components/MessageInput.svelte.test.js index 7c7f9aa..597f0c3 100644 --- a/ui/tests/lib/components/MessageInput.svelte.test.js +++ b/ui/tests/lib/components/MessageInput.svelte.test.js @@ -1,2 +1,9 @@ // async onSubmit(event) // onKeyDown(event) +import { describe, expect, test } from 'vitest'; + +describe('MessageInput', () => { + test('stub', async () => { + expect(true).toBeTruthy(); + }); +}); |
