From 3a89459f8b48449b341469776a37d8b225e956f2 Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Thu, 14 Nov 2024 23:28:19 -0500 Subject: Stub in tests --- .../lib/components/ChangePassword.svelte.test.js | 45 +++++++++++++--------- .../components/CreateChannelForm.svelte.test.js | 7 ++++ ui/tests/lib/components/Invite.svelte.test.js | 7 ++++ ui/tests/lib/components/LogOut.svelte.test.js | 7 ++++ ui/tests/lib/components/Message.svelte.test.js | 7 ++++ .../lib/components/MessageInput.svelte.test.js | 7 ++++ 6 files changed, 61 insertions(+), 19 deletions(-) (limited to 'ui/tests') 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(''); + 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(''); + // 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(); + }); +}); -- cgit v1.2.3