test(join-space): update stale assertions to match current UI and API
Four assertions drifted from the current JoinSpace modal, carried over
when the file was renamed from the old JoinServer component in fc06e25
without being updated:
- Placeholder was expanded to cover URL-form invite input
('e.g. abc123' → 'e.g. abc123 or https://instance.com/join/abc123').
- 'shows validation error when submitting empty code' asserted a code
path that no longer exists: the submit button is now disabled when
the trimmed input is empty (JoinSpace.tsx line 166), so clicking it
is a no-op and the 'Invite code is required' error from the parser
is unreachable from the rendered form. Replaced with an assertion
that the button is disabled while the input is empty — the actual
validation UX.
- joinByCode signature took on a second `origin` argument during the
S2S DM unification + federated-join work (spaceStore.ts line 69).
parseInviteInput returns { code, origin: undefined } for a bare
code, so the call is `joinByCode('my-invite-code', undefined)`.
Assertion updated to match exactly.
No code behavior change — tests now reflect actual behavior, which
was already correct and deployed. Closes backlog #28.
This commit is contained in:
@@ -55,19 +55,20 @@ describe('JoinSpaceModal', () => {
|
||||
useUIStore.setState({ activeModal: 'joinSpace' });
|
||||
renderModal();
|
||||
expect(screen.getByText('Join a Space')).toBeInTheDocument();
|
||||
expect(screen.getByPlaceholderText('e.g. abc123')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByPlaceholderText('e.g. abc123 or https://instance.com/join/abc123')
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText('Join Space')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows validation error when submitting empty code', async () => {
|
||||
const user = userEvent.setup();
|
||||
it('disables the Join Space button while the input is empty', () => {
|
||||
useUIStore.setState({ activeModal: 'joinSpace' });
|
||||
renderModal();
|
||||
|
||||
const submitButton = screen.getByText('Join Space');
|
||||
await user.click(submitButton);
|
||||
|
||||
expect(screen.getByText('Invite code is required')).toBeInTheDocument();
|
||||
// The submit button is the validation gate in this UI — there is no
|
||||
// click-to-show-error path. parseInviteInput's 'Invite code is required'
|
||||
// branch is defensive only and unreachable from the rendered form.
|
||||
expect(screen.getByText('Join Space')).toBeDisabled();
|
||||
});
|
||||
|
||||
it('calls joinByCode with the entered invite code and navigates on success', async () => {
|
||||
@@ -79,16 +80,17 @@ describe('JoinSpaceModal', () => {
|
||||
renderModal();
|
||||
|
||||
// Type invite code
|
||||
const input = screen.getByPlaceholderText('e.g. abc123');
|
||||
const input = screen.getByPlaceholderText('e.g. abc123 or https://instance.com/join/abc123');
|
||||
await user.type(input, 'my-invite-code');
|
||||
|
||||
// Click join
|
||||
const submitButton = screen.getByText('Join Space');
|
||||
await user.click(submitButton);
|
||||
|
||||
// joinByCode should be called with the code
|
||||
// joinByCode(code, origin) — bare code has no origin, so second arg is
|
||||
// undefined (parseInviteInput returns { code, origin: undefined }).
|
||||
await waitFor(() => {
|
||||
expect(mockJoinByCode).toHaveBeenCalledWith('my-invite-code');
|
||||
expect(mockJoinByCode).toHaveBeenCalledWith('my-invite-code', undefined);
|
||||
});
|
||||
|
||||
// Should navigate to the new space
|
||||
@@ -108,7 +110,7 @@ describe('JoinSpaceModal', () => {
|
||||
|
||||
renderModal();
|
||||
|
||||
const input = screen.getByPlaceholderText('e.g. abc123');
|
||||
const input = screen.getByPlaceholderText('e.g. abc123 or https://instance.com/join/abc123');
|
||||
await user.type(input, 'bad-code');
|
||||
|
||||
const submitButton = screen.getByText('Join Space');
|
||||
|
||||
Reference in New Issue
Block a user