Skip to content

Commit

Permalink
finish tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh committed Oct 16, 2023
1 parent e7992ff commit 6a7abd6
Showing 1 changed file with 193 additions and 0 deletions.
193 changes: 193 additions & 0 deletions apps/meteor/tests/e2e/message-mentions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import { faker } from '@faker-js/faker';

import { Users } from './fixtures/userStates';
import { HomeChannel } from './page-objects';
import { createTargetPrivateChannel } from './utils';
import { test, expect } from './utils/test';


test.use({ storageState: Users.admin.state });

const getMentionText = (username: string, kind?: number): string => {
if (kind === 1) {
return `You mentioned @${username}, but they're not in this room.`;
}
if (kind === 2) {
return `You mentioned @${username}, but they're not in this room. You can ask a room admin to add them.`;
}
if (kind === 3) {
return `You mentioned ${username}, but they're not in this room. You let them know via DM.`;
}
return `Hello @${username}, how are you`;
};

test.describe.serial('message-mentions', () => {
let poHomeChannel: HomeChannel;

Expand All @@ -20,4 +37,180 @@ test.describe.serial('message-mentions', () => {
await expect(poHomeChannel.content.messagePopupUsers.locator('role=listitem >> text="all"')).toBeVisible();
await expect(poHomeChannel.content.messagePopupUsers.locator('role=listitem >> text="here"')).toBeVisible();
});

test.describe('users not in channel', () => {
let targetChannel: string;
let targetChannel2: string;
test.beforeAll(async ({ api }) => {
targetChannel = await createTargetPrivateChannel(api);
});

test('all actions', async ({ page }) => {
const adminPage = new HomeChannel(page);
const mentionText = getMentionText(Users.user1.data.username, 1);

await test.step('receive bot message', async () => {
await adminPage.sidenav.openChat(targetChannel);
await adminPage.content.sendMessage(getMentionText(Users.user1.data.username));
await expect(adminPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText);
});

await test.step('show "Do nothing" action', async () => {
await expect(adminPage.content.lastUserMessage.locator('button >> text="Do nothing"')).toBeVisible();
});
await test.step('show "Add them" action', async () => {
await expect(adminPage.content.lastUserMessage.locator('button >> text="Add them"')).toBeVisible();
});
await test.step('show "Let them know" action', async () => {
await expect(adminPage.content.lastUserMessage.locator('button >> text="Let them know"')).toBeVisible();
});

await test.step('dismiss', async () => {
await adminPage.content.lastUserMessage.locator('button >> text="Do nothing"').click();
});

await test.step('receive second bot message', async () => {
await adminPage.content.sendMessage(getMentionText(Users.user1.data.username));
await expect(adminPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText);
});
await test.step('send message to users', async () => {
await adminPage.content.lastUserMessage.locator('button >> text="Let them know"').click();
await expect(adminPage.content.lastUserMessageBody).toContainText(getMentionText(Users.user1.data.username, 3));
});

await test.step('receive third bot message', async () => {
await adminPage.content.sendMessage(getMentionText(Users.user1.data.username));
await expect(adminPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText);
});
await test.step('add users to room', async () => {
await adminPage.content.lastUserMessage.locator('button >> text="Add them"').click();
await expect(adminPage.content.lastSystemMessageBody).toContainText('added');
});
});

test.describe(() => {
test.use({ storageState: Users.user1.state });

test('dismiss and share message actions', async ({ page }) => {
const mentionText = getMentionText(Users.user2.data.username, 1);
const userPage = new HomeChannel(page);

await test.step('receive bot message', async () => {
await userPage.sidenav.openChat(targetChannel);
await userPage.content.sendMessage(getMentionText(Users.user2.data.username));
await expect(userPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText);
});

await test.step('show "Do nothing" action', async () => {
await expect(userPage.content.lastUserMessage.locator('button >> text="Do nothing"')).toBeVisible();
});
await test.step('show "Let them know" action', async () => {
await expect(userPage.content.lastUserMessage.locator('button >> text="Let them know"')).toBeVisible();
});
await test.step('not show "Add them action', async () => {
await expect(userPage.content.lastUserMessage.locator('button >> text="Add them"')).not.toBeVisible();
});

await test.step('dismiss', async () => {
await userPage.content.lastUserMessage.locator('button >> text="Do nothing"').click();
});

await test.step('receive second bot message', async () => {
await userPage.sidenav.openChat(targetChannel);
await userPage.content.sendMessage(getMentionText(Users.user2.data.username));
await expect(userPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText);
});
await test.step('send message to users', async () => {
await userPage.content.lastUserMessage.locator('button >> text="Let them know"').click();
await expect(userPage.content.lastUserMessageBody).toContainText(getMentionText(Users.user2.data.username, 3));
});
});
})

test.describe(() => {
test.use({ storageState: Users.user1.state });
test.beforeAll(async ({ api }) => {
expect((await api.post('/permissions.update', { permissions: [{ '_id': 'create-d', 'roles': ['admin'] }] })).status()).toBe(200);
});

test.afterAll(async ({ api }) => {
expect((await api.post('/permissions.update', { permissions: [{ '_id': 'create-d', 'roles': ['admin', 'user', 'bot', 'app'] }] })).status()).toBe(200);
});

test('dismiss and add users actions', async ({ page }) => {
const mentionText = getMentionText(Users.user2.data.username, 1);
const userPage = new HomeChannel(page);

await test.step('create private room', async () => {
targetChannel2 = faker.string.uuid();

await poHomeChannel.sidenav.openNewByLabel('Channel');
await poHomeChannel.sidenav.inputChannelName.type(targetChannel2);
await poHomeChannel.sidenav.btnCreate.click();

await expect(page).toHaveURL(`/group/${targetChannel2}`);
})

await test.step('receive bot message', async () => {
await userPage.sidenav.openChat(targetChannel2);
await userPage.content.sendMessage(getMentionText(Users.user2.data.username));
await expect(userPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText);
});
await test.step('show "Do nothing" action', async () => {
await expect(userPage.content.lastUserMessage.locator('button >> text="Do nothing"')).toBeVisible();
});
await test.step('show "Add them" action', async () => {
await expect(userPage.content.lastUserMessage.locator('button >> text="Add them"')).toBeVisible();
});
await test.step('not show "Let them know" action', async () => {
await expect(userPage.content.lastUserMessage.locator('button >> text="Let them know"')).not.toBeVisible();
});

await test.step('dismiss', async () => {
await userPage.content.lastUserMessage.locator('button >> text="Do nothing"').click();
});

await test.step('receive second bot message', async () => {
await userPage.sidenav.openChat(targetChannel2);
await userPage.content.sendMessage(getMentionText(Users.user2.data.username));
await expect(userPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(mentionText);
});
await test.step('add users to room', async () => {
await userPage.content.lastUserMessage.locator('button >> text="Add them"').click();
await expect(userPage.content.lastSystemMessageBody).toContainText('added');
});
});
});

test.describe(() => {
test.use({ storageState: Users.user2.state });
test.beforeAll(async ({ api }) => {
expect((await api.post('/permissions.update', { permissions: [{ '_id': 'create-d', 'roles': ['admin'] }] })).status()).toBe(200);
});

test.afterAll(async ({ api }) => {
expect((await api.post('/permissions.update', { permissions: [{ '_id': 'create-d', 'roles': ['admin', 'user', 'bot', 'app'] }] })).status()).toBe(200);
});
test('no actions', async ({ page }) => {
const userPage = new HomeChannel(page);

await test.step('receive bot message', async () => {
await userPage.sidenav.openChat(targetChannel2);
await userPage.content.sendMessage(getMentionText(Users.user3.data.username));
await expect(userPage.content.lastUserMessage.locator('.rcx-message-block')).toContainText(getMentionText(Users.user3.data.username, 2));
});

await test.step('not show "Do nothing" action', async () => {
await expect(userPage.content.lastUserMessage.locator('button >> text="Do nothing"')).not.toBeVisible();
});
await test.step('not show "Add them" action', async () => {
await expect(userPage.content.lastUserMessage.locator('button >> text="Add them"')).not.toBeVisible();
});
await test.step('not show "Let them know" action', async () => {
await expect(userPage.content.lastUserMessage.locator('button >> text="Let them know"')).not.toBeVisible();
});
});
})

})
});

0 comments on commit 6a7abd6

Please sign in to comment.