summaryrefslogtreecommitdiff
path: root/ui/tests/lib/components/MessageInput.svelte.test.js
diff options
context:
space:
mode:
authorKit La Touche <kit@transneptune.net>2024-11-15 22:37:39 -0500
committerKit La Touche <kit@transneptune.net>2024-11-15 22:37:39 -0500
commit8a7cc9f8859c14b60da870cee199110e71e0f5da (patch)
tree31b692390dd1d8d60f7b5dfef5de79ef35908235 /ui/tests/lib/components/MessageInput.svelte.test.js
parent845372868fa9bc90b5f57d423b736d7d0581037d (diff)
Ratchet up Component test coverage
Turns out a number of our components are a pain to run via a mounting test, but Svelte does suggest that this is the dispreferred way to test anyway. Using use:, triggering navigation after logout, and scrollIntoView all make the headless node test process with the janky in-memory mount have a Very Bad Day. But this is still progress! We will press on.
Diffstat (limited to 'ui/tests/lib/components/MessageInput.svelte.test.js')
-rw-r--r--ui/tests/lib/components/MessageInput.svelte.test.js49
1 files changed, 44 insertions, 5 deletions
diff --git a/ui/tests/lib/components/MessageInput.svelte.test.js b/ui/tests/lib/components/MessageInput.svelte.test.js
index 597f0c3..d90026c 100644
--- a/ui/tests/lib/components/MessageInput.svelte.test.js
+++ b/ui/tests/lib/components/MessageInput.svelte.test.js
@@ -1,9 +1,48 @@
-// async onSubmit(event)
-// onKeyDown(event)
-import { describe, expect, test } from 'vitest';
+import { flushSync, mount, unmount } from 'svelte';
+import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
+import MessageInput from '$lib/components/MessageInput.svelte';
+import axios from 'axios';
+
+let component;
+
+let mocks = vi.hoisted(() => ({
+ post: vi.fn(),
+}));
describe('MessageInput', () => {
- test('stub', async () => {
- expect(true).toBeTruthy();
+ beforeEach(() => {
+ vi.mock('axios', async (importActual) => {
+ const actual = await importActual();
+
+ const mockAxios = {
+ default: {
+ ...actual.default,
+ create: vi.fn(() => ({
+ ...actual.default.create(),
+ post: mocks.post,
+ })),
+ },
+ };
+
+ return mockAxios;
+ });
+ mocks.post.mockResolvedValue({ status: 200 });
+
+ component = mount(MessageInput, {
+ target: document.body, // `document` exists because of jsdom
+ });
+ flushSync();
+ });
+
+ afterEach(() => {
+ unmount(component);
+ });
+
+ test('onsubmit happy path', async () => {
+ // Click the button, then flush the changes so you can synchronously write expectations
+ document.body.querySelector('button[type=submit]').click();
+ flushSync();
+
+ expect(mocks.post).toHaveBeenCalled();
});
});