summaryrefslogtreecommitdiff
path: root/ui/tests/lib/components/LogIn.svelte.test.js
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-02-24 11:41:24 -0500
committerOwen Jacobson <owen@grimoire.ca>2025-02-24 11:41:24 -0500
commit099471c574f6dceeb45f8bb5dae1699a734cb084 (patch)
tree945f44c9a90bf51de20c61a5a8c5ed82c2c05009 /ui/tests/lib/components/LogIn.svelte.test.js
parent36cadfe00cacc6a6523f9862d3f7a08a9d0ce611 (diff)
parentfc0f1654a56d2247728a766f43e72ff169704888 (diff)
Merge branch 'prop/global-state-at-top-level'
Diffstat (limited to 'ui/tests/lib/components/LogIn.svelte.test.js')
-rw-r--r--ui/tests/lib/components/LogIn.svelte.test.js38
1 files changed, 25 insertions, 13 deletions
diff --git a/ui/tests/lib/components/LogIn.svelte.test.js b/ui/tests/lib/components/LogIn.svelte.test.js
index b64d846..ab77c11 100644
--- a/ui/tests/lib/components/LogIn.svelte.test.js
+++ b/ui/tests/lib/components/LogIn.svelte.test.js
@@ -1,22 +1,34 @@
-import { flushSync, mount, unmount } from 'svelte';
-import { afterEach, beforeEach, describe, expect, test } from 'vitest';
+import { render, screen } from '@testing-library/svelte';
+import userEvent from '@testing-library/user-event';
+import { beforeEach, expect, test, describe, it, vi } from 'vitest';
import LogIn from '$lib/components/LogIn.svelte';
-let component;
+const user = userEvent.setup();
-describe('LogIn', () => {
- beforeEach(() => {
- component = mount(LogIn, {
- target: document.body // `document` exists because of jsdom
+const mocks = vi.hoisted(() => ({
+ logIn: vi.fn()
+}));
+
+describe('LogIn', async () => {
+ beforeEach(async () => {
+ render(LogIn, {
+ logIn: mocks.logIn
});
- flushSync();
});
- afterEach(() => {
- unmount(component);
- });
+ it('sends a login request', async () => {
+ const username = screen.getByLabelText('username');
+ await user.type(username, 'my username');
+
+ const password = screen.getByLabelText('password');
+ await user.type(password, 'my very creative and long password');
+
+ const signIn = screen.getByRole('button');
+ await user.click(signIn);
- test('mounts', async () => {
- expect(component).toBeTruthy();
+ expect(mocks.logIn).toHaveBeenCalledExactlyOnceWith(
+ 'my username',
+ 'my very creative and long password'
+ );
});
});