From 1d5f74bca29c6bb28bef6035aa09a1e35884b40a Mon Sep 17 00:00:00 2001
From: Sam Nystrom <sam@samnystrom.dev>
Date: Sat, 16 Mar 2024 22:54:54 -0400
Subject: test: begin writing tests

---
 src/pages/SignUp.test.tsx | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 src/pages/SignUp.test.tsx

(limited to 'src/pages/SignUp.test.tsx')

diff --git a/src/pages/SignUp.test.tsx b/src/pages/SignUp.test.tsx
new file mode 100644
index 0000000..3029beb
--- /dev/null
+++ b/src/pages/SignUp.test.tsx
@@ -0,0 +1,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();
+});
-- 
cgit v1.2.3

