summaryrefslogtreecommitdiff
path: root/src/pages/SignUp.test.tsx
blob: 3029beb3637a223ca3717ee925a1efbc1b5adf7f (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
import { expect, test } from 'bun:test';
import { render, fireEvent } from '@testing-library/preact';
import { Pb } from '../context.ts';
import { pb } from '../preload.ts';
import SignUp from './SignUp.tsx';

test('has a link to log in', () => {
	const { getAllByText, getByLabelText, getByText } = render(
		<SignUp />
	);

	expect(getAllByText(/log in/i)).not.toHaveLength(0);
});

test('can sign up', () => {
	const username = 'foo';
	const email = 'foo@example.com';
	const password = '12345678';

	const { getByText, getByLabelText } = render(
		<Pb.Provider value={pb}>
			<SignUp />
		</Pb.Provider>
	);

	fireEvent.change(getByLabelText(/username/i), {target: {value: username}});
	fireEvent.change(getByLabelText(/email/i), {target: {value: email}});
	fireEvent.change(getByLabelText(/password/i), {target: {value: password}});
	fireEvent.change(getByLabelText(/confirm password/i), {target: {value: password}});

	fireEvent.click(getByText(/continue/i));

	expect(pb.authStore.isValid()).toBeTrue();
});