summaryrefslogtreecommitdiff
path: root/ui/tests/lib/components/CreateChannelForm.svelte.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/tests/lib/components/CreateChannelForm.svelte.test.js')
-rw-r--r--ui/tests/lib/components/CreateChannelForm.svelte.test.js52
1 files changed, 48 insertions, 4 deletions
diff --git a/ui/tests/lib/components/CreateChannelForm.svelte.test.js b/ui/tests/lib/components/CreateChannelForm.svelte.test.js
index 31f7462..c1adba5 100644
--- a/ui/tests/lib/components/CreateChannelForm.svelte.test.js
+++ b/ui/tests/lib/components/CreateChannelForm.svelte.test.js
@@ -1,8 +1,52 @@
-// async handleSubmit(event)
-import { describe, expect, test } from 'vitest';
+import { flushSync, mount, unmount } from 'svelte';
+import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
+import CreateChannelForm from '$lib/components/CreateChannelForm.svelte';
+import axios from 'axios';
+
+let component;
+
+let mocks = vi.hoisted(() => ({
+ post: vi.fn(),
+}));
describe('CreateChannelForm', () => {
- 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(CreateChannelForm, {
+ target: document.body, // `document` exists because of jsdom
+ });
+ flushSync();
+ });
+
+ afterEach(() => {
+ unmount(component);
+ });
+
+ test('onsubmit happy path', async () => {
+ // Set value on the one input this should match:
+ const inputs = document.body.querySelectorAll('input[type=text]');
+ inputs.value = 'channel name';
+ // 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();
+ expect(Array.from(inputs.values()).map((i) => i.value)).toEqual(['']);
});
});