import { IS_EE } from './config/constants'; import { Users } from './fixtures/userStates'; import { HomeChannel } from './page-objects'; import { Directory } from './page-objects/directory'; import { createDirectMessage, createTargetChannel, sendTargetChannelMessage } from './utils'; import { test, expect } from './utils/test'; test.use({ storageState: Users.admin.state }); test.describe('Preview public channel', () => { let poHomeChannel: HomeChannel; let poDirectory: Directory; let targetChannel: string; let targetChannelMessage: string; // Each test navigates to /home by itself after its API setup is done, otherwise the API mutations // can race the client boot (initial cached stores sync) and leave the UI stuck on the loading screen test.beforeEach(async ({ page }) => { poHomeChannel = new HomeChannel(page); poDirectory = new Directory(page); }); test.beforeAll(async ({ api }) => { targetChannel = await createTargetChannel(api); targetChannelMessage = await sendTargetChannelMessage(api, targetChannel, { msg: 'This message' }); await api.post('/permissions.update', { permissions: [{ _id: 'preview-c-room', roles: ['admin', 'user', 'anonymous'] }] }); }); test.afterAll(async ({ api }) => { await api.post('/channels.delete', { roomName: targetChannel }); await api.post('/permissions.update', { permissions: [{ _id: 'preview-c-room', roles: ['admin', 'user', 'anonymous'] }] }); }); test.describe('User', () => { test.use({ storageState: Users.user1.state }); test('should let user preview public rooms messages', async () => { await poDirectory.goto(); await poDirectory.openChannel(targetChannel); await expect(poHomeChannel.content.lastUserMessageBody).toContainText(targetChannelMessage); }); test('should disable all composer toolbar actions during channel preview', async () => { await poDirectory.goto(); await poDirectory.openChannel(targetChannel); await poHomeChannel.content.waitForChannel(); await expect(poHomeChannel.composer.btnJoinRoom).toBeVisible(); const actions = await poHomeChannel.composer.allPrimaryActions.all(); await Promise.all( actions.map(async (action) => { await expect(action).toBeDisabled(); }), ); }); test('should let user view direct rooms', async ({ api }) => { await api.post('/permissions.update', { permissions: [{ _id: 'preview-c-room', roles: ['admin'] }] }); await createDirectMessage(api); await poHomeChannel.goto(); await poHomeChannel.navbar.openChat(Users.user2.data.username); await expect(poHomeChannel.composer.btnJoinRoom).not.toBeVisible(); await expect(poHomeChannel.composer.inputMessage).toBeEnabled(); }); test('should not let user role preview public rooms', async ({ api }) => { await api.post('/permissions.update', { permissions: [{ _id: 'preview-c-room', roles: ['admin'] }] }); await poDirectory.goto(); await poDirectory.openChannel(targetChannel); await expect(poHomeChannel.btnJoinChannel).toBeVisible(); await expect(poHomeChannel.content.lastUserMessageBody).not.toBeVisible(); }); }); test.describe('App', () => { test.skip(!IS_EE, 'Premium Only'); test.use({ storageState: Users.userNotAllowedByApp.state }); test('should prevent user from join the room', async ({ api, page }) => { await api.post('/permissions.update', { permissions: [{ _id: 'preview-c-room', roles: ['admin', 'user', 'anonymous'] }] }); await poDirectory.goto(); await poDirectory.openChannel(targetChannel); await expect(poHomeChannel.content.lastUserMessageBody).toContainText(targetChannelMessage); await poHomeChannel.composer.btnJoinRoom.click(); await expect( page.locator('[role="alert"]', { hasText: 'TEST OF NOT ALLOWED USER', }), ).toBeVisible(); }); test('should prevent user from join the room without preview permission', async ({ api, page }) => { await api.post('/permissions.update', { permissions: [{ _id: 'preview-c-room', roles: ['admin'] }] }); await poDirectory.goto(); await poDirectory.openChannel(targetChannel); await expect(poHomeChannel.content.lastUserMessageBody).not.toBeVisible(); await poHomeChannel.btnJoinChannel.click(); await expect( page.locator('[role="alert"]', { hasText: 'TEST OF NOT ALLOWED USER', }), ).toBeVisible(); }); }); });