summaryrefslogtreecommitdiff
path: root/ui/tests/lib/components/MessageInput.svelte.test.js
blob: c32ce1126376e1d99cd7695f2b8f1a983460d907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { render, screen } from '@testing-library/svelte';
import userEvent from '@testing-library/user-event';
import { beforeEach, expect, describe, it, vi } from 'vitest';
import MessageInput from '$lib/components/MessageInput.svelte';

const user = userEvent.setup();

const mocks = vi.hoisted(() => ({
  sendMessage: vi.fn(),
}));

describe('CreateChannelForm', async () => {
  beforeEach(async () => {
    render(MessageInput, {
      sendMessage: mocks.sendMessage,
    });
  });

  describe('sends a message', async () => {
    // Skipped as `user-event` can't actually type into a div with
    // `contenteditable="plaintext-only"` at this time. This capability is
    // pretty core, though; we'll notice (immediately) if it breaks.
    //
    // See <https://github.com/testing-library/user-event/issues/1197>.
    it.skip('with non-empty content', async () => {
      const input = screen.getByRole('textbox');
      await user.type(input, 'a happy surprise');

      const send = screen.getByRole('button');
      await user.click(send);

      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('');
    });
  });
});