feat: Tests for channel creation dialog
This commit is contained in:
parent
0e99daa477
commit
a23ec93319
@ -1,7 +1,11 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const newChannelSchema = z.object({
|
export const newChannelSchema = z.object({
|
||||||
channelName: z.string().min(1, 'Channel name is required').max(24, 'Channel name cannot be longer than 24 characters.'),
|
channelName: z
|
||||||
|
.string()
|
||||||
|
.min(1, 'Channel name is required')
|
||||||
|
.max(24, 'Channel name cannot be longer than 24 characters.')
|
||||||
|
.refine((value) => !/^\d/.test(value), 'Channel name cannot start with a number.'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type NewChannelSchema = typeof newChannelSchema;
|
export type NewChannelSchema = typeof newChannelSchema;
|
||||||
|
67
tests/createChannel.spec.ts
Normal file
67
tests/createChannel.spec.ts
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import { test, expect, type Page } from '@playwright/test';
|
||||||
|
import { login } from './utils';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
|
function generate15CharUUID() {
|
||||||
|
// Second regex prevents UUID from starting with a number
|
||||||
|
return uuidv4().replace(/-/g, '').replace(/^\d*/g, '').substring(0, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function tryCreateChannel(page: Page, channelName: string) {
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
await page.getByRole('button', { name: 'Create Channel' }).click();
|
||||||
|
await page.getByRole('textbox', { name: 'Channel Name' }).fill(channelName);
|
||||||
|
await page.getByRole('button', { name: 'Create', exact: true }).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
test.describe('Create Channel', () => {
|
||||||
|
let page: Page;
|
||||||
|
test.beforeEach(async ({ browser }) => {
|
||||||
|
page = await browser.newPage();
|
||||||
|
|
||||||
|
// Login and navigate
|
||||||
|
await login(page);
|
||||||
|
await page.goto('/channel/general', { timeout: 30000, waitUntil: 'domcontentloaded' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('successfully create new channel', async ({ request }) => {
|
||||||
|
const uuid: string = generate15CharUUID();
|
||||||
|
console.log(uuid);
|
||||||
|
|
||||||
|
// Try to create new channel
|
||||||
|
await tryCreateChannel(page, uuid);
|
||||||
|
|
||||||
|
// Check if channel exists
|
||||||
|
const res = await request.get(`/channel/${uuid}`);
|
||||||
|
expect(res.status()).toEqual(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not allow channel names > 25 characters', async () => {
|
||||||
|
// Try to create new channel
|
||||||
|
await tryCreateChannel(page, 'thisisatwentyfivelongstring;');
|
||||||
|
|
||||||
|
const error = page.getByText('Channel name cannot be longer than 24 characters.');
|
||||||
|
await expect(error).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not allow channel names to start with a number', async () => {
|
||||||
|
// Try to create new channel
|
||||||
|
await tryCreateChannel(page, '00-test');
|
||||||
|
|
||||||
|
const error = page.getByText('Channel name cannot start with a number.');
|
||||||
|
await expect(error).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not duplicate channel names', async () => {
|
||||||
|
const uuid: string = generate15CharUUID();
|
||||||
|
console.log(uuid);
|
||||||
|
|
||||||
|
// Try to create new channel
|
||||||
|
await tryCreateChannel(page, uuid);
|
||||||
|
await page.reload();
|
||||||
|
await tryCreateChannel(page, uuid);
|
||||||
|
|
||||||
|
const error = page.getByText('Channel already exists.');
|
||||||
|
await expect(error).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user