summaryrefslogtreecommitdiff
path: root/ui/tests/lib/components/MessageInput.svelte.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/tests/lib/components/MessageInput.svelte.test.js')
-rw-r--r--ui/tests/lib/components/MessageInput.svelte.test.js61
1 files changed, 25 insertions, 36 deletions
diff --git a/ui/tests/lib/components/MessageInput.svelte.test.js b/ui/tests/lib/components/MessageInput.svelte.test.js
index 3dde5d7..508fb43 100644
--- a/ui/tests/lib/components/MessageInput.svelte.test.js
+++ b/ui/tests/lib/components/MessageInput.svelte.test.js
@@ -1,48 +1,37 @@
-import { flushSync, mount, unmount } from 'svelte';
-import { afterEach, beforeEach, describe, expect, test, vi } 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 MessageInput from '$lib/components/MessageInput.svelte';
-import axios from 'axios';
-let component;
+const user = userEvent.setup();
-let mocks = vi.hoisted(() => ({
- post: vi.fn()
+const mocks = vi.hoisted(() => ({
+ sendMessage: vi.fn()
}));
-describe('MessageInput', () => {
- 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;
+describe('CreateChannelForm', async () => {
+ beforeEach(async () => {
+ render(MessageInput, {
+ sendMessage: mocks.sendMessage
});
- mocks.post.mockResolvedValue({ status: 200 });
-
- component = mount(MessageInput, {
- target: document.body // `document` exists because of jsdom
- });
- flushSync();
});
- afterEach(() => {
- unmount(component);
- });
+ describe('sends a message', async () => {
+ it('with non-empty content', async () => {
+ const input = screen.getByRole('textbox');
+ await user.type(input, 'a happy surprise');
- 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();
+ const send = screen.getByRole('button');
+ await user.click(send);
- expect(mocks.post).toHaveBeenCalled();
+ expect(mocks.sendMessage).toHaveBeenCalledExactlyOnceWith('a happy surprise');
+ });
+
+ it('with empty content', async () => {
+ const send = screen.getByRole('button');
+ await user.click(send);
+
+ expect(mocks.sendMessage).toHaveBeenCalledExactlyOnceWith('');
+ });
});
});