Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
E2E_EMAIL = "a@a.com"
E2E_PASSWORD = "a"
MAINUSER_PASS="a"
MAINUSER_MAIL="a@a.org"
SECONDUSER_PASS="b"
SECONDUSER_MAIL="b@b.org"
LINK="localhost:4000"
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
.env
node_modules
test-results
package-lock.json
.vscode
.env
.vscode

# Playwright
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}
153 changes: 139 additions & 14 deletions Chat.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { test, expect, firefox, chromium } from '@playwright/test';
import { login, logout, randomString } from './generic';
import { idfy, login, logout, newWindow, randomString, register } from './generic';
import { createGroup, deleteGroup, gotoGroup, joinGroup } from './group';
import 'dotenv/config'

test('Group-Chat', async ({ page }) => {
await login(page);

const rand = Math.random().toString(36).slice(2, 10);
const group = { name: 'Test Group Chat' + rand, public: true };
const group = { name: 'test-group-chat' + randomString(), public: true };

await createGroup(page, group);

const browser = await chromium.launch();
const bContext = await browser.newContext();
const bPage = await bContext.newPage();

await login(bPage, { email: 'b@b.se', password: 'b' });
const bPage = await newWindow();
await login(bPage, { email: process.env.SECONDUSER_MAIL, password: process.env.SECONDUSER_PASS });
await joinGroup(bPage, group);

await page.reload();
Expand All @@ -38,17 +35,17 @@ test('Group-Chat', async ({ page }) => {
await bPage.getByRole('button', { name: 'open chat' }).click();
await bPage.getByPlaceholder('Search chatters').click();
await bPage.getByPlaceholder('Search chatters').fill(group.name);
await bPage.getByRole('button', { name: group.name }).click();
await bPage.getByRole('button', { name: group.name }).first().click();
await page.waitForTimeout(300);
await bPage.getByPlaceholder('Write a message...').fill('Hello!! :D');
await bPage.getByPlaceholder('Write a message...').press('Enter');
await page.waitForTimeout(300);

expect(page.getByText('Hello!! :D').nth(1)).toBeVisible();
expect(page.getByText('Hello!! :D').nth(2)).toBeVisible();
await expect(page.getByText('Hello!! :D').nth(1)).toBeVisible();
await expect(page.getByText('Hello!! :D').nth(2)).toBeVisible();

expect(bPage.getByText('Hello!! :D').nth(1)).toBeVisible();
expect(bPage.getByText('Hello!! :D').nth(2)).toBeVisible();
await expect(bPage.getByText('Hello!! :D').nth(1)).toBeVisible();
await expect(bPage.getByText('Hello!! :D').nth(2)).toBeVisible();

await gotoGroup(page, group);
await deleteGroup(page, group);
Expand All @@ -65,7 +62,7 @@ test('Direct-Chat-Via-Group', async ({ page }) => {
const bContext = await browser.newContext();
const bPage = await bContext.newPage();

await login(bPage, { email: 'b@b.se', password: 'b' });
await login(bPage, { email: process.env.SECONDUSER_MAIL, password: process.env.SECONDUSER_PASS });
await joinGroup(bPage, group);
await gotoGroup(bPage, group);

Expand All @@ -92,3 +89,131 @@ test('Direct-Chat-Via-Group', async ({ page }) => {

await deleteGroup(page, group);
});

test('Workgroup-Chat', async ({ page }) => {
await login(page);

const group = { name: 'Test Group Chat Workgroup' + randomString(), public: true };

await createGroup(page, group);

const bPage = await newWindow();

await login(bPage, { email: process.env.SECONDUSER_MAIL, password: process.env.SECONDUSER_PASS });
await joinGroup(bPage, group);
await gotoGroup(bPage, group);

await page.getByRole('button', { name: 'Work Groups' }).click();
await page.getByRole('button', { name: '+ Add Workgroup' }).click();
await page.getByLabel('Name').click();

const workgroup = 'Workgroup for chatting in yay' + randomString()
await page.getByLabel('Name').fill(workgroup);
await page.getByRole('button', { name: 'Create', exact: true }).click();
await page.getByRole('button', { name: 'Join', exact: true }).click();

await bPage.getByRole('button', { name: 'Work Groups' }).click();
await bPage.getByRole('button', { name: 'Join', exact: true }).click();

await page.reload();
await page.getByRole('button', { name: 'open chat' }).click();

await page.getByPlaceholder('Search chatters').click();
await page.getByPlaceholder('Search chatters').fill(workgroup);
await page.getByRole('button', { name: workgroup }).click();
await page.getByPlaceholder('Write a message...').click();
await page.getByPlaceholder('Write a message...').fill('Hello!! :D');
await page.locator('form > button:nth-child(2)').click();
await page.getByPlaceholder('Write a message...').click();

// await bPage.reload();
await bPage.getByRole('button', { name: 'open chat' }).click();
await bPage.getByPlaceholder('Search chatters').click();
await bPage.getByPlaceholder('Search chatters').fill(workgroup);
await bPage.getByRole('button', { name: workgroup }).click();
await bPage.getByPlaceholder('Write a message...').fill('Hello!! :D');
await bPage.getByPlaceholder('Write a message...').press('Enter');

await expect(page.getByText('Hello!! :D').nth(1)).toBeVisible();
await expect(page.getByText('Hello!! :D').nth(2)).toBeVisible();

await expect(bPage.getByText('Hello!! :D').nth(1)).toBeVisible();
await expect(bPage.getByText('Hello!! :D').nth(2)).toBeVisible();

await page.getByRole('button', { name: 'Close modal' }).click();

});

// TODO Fix this, will require finessing with registring new users
test('Group-Chat-Creation', async ({ page }) => {
await login(page)

// Testing error functionality
await page.getByRole('button', { name: 'open chat' }).click();
await page.getByRole('button', { name: '+ New Group' }).click();
await page.getByRole('button', { name: 'Cancel' }).click();
await page.getByRole('button', { name: '+ New Group' }).click();
await page.getByRole('button', { name: 'Confirm' }).click();
await expect(page.getByText('Failed to created group chat')).toBeVisible();

// Have other users chat
const bPage = await newWindow();
await login(bPage, { email: process.env.SECONDUSER_MAIL, password: process.env.SECONDUSER_PASS })

const cPage = await newWindow();
const { username } = await register(cPage);

// Creating the group and checking that it was created
// await page.getByRole('button', { name: 'avatar bb, a_edited' }).click();
await page.locator(`[id="chat-${process.env.SECONDUSER_NAME},-${process.env.MAINUSER_NAME}"]`).getByRole('button', { name: 'Add User' }).click();

await page.getByRole('button', { name: 'avatar + Invite user' }).nth(1).click();
await page.getByRole('textbox', { name: 'User to invite' }).click();
await page.getByRole('textbox', { name: 'User to invite' }).fill(username);
await page.getByRole('button', { name: 'Add Me!', exact: true }).click();
await page.getByRole('button', { name: 'Close modal' }).nth(3).click();
await page.getByRole('button', { name: 'Confirm' }).click();
await expect(page.getByText('Failed to created group chat')).not.toBe;


const groupname = `${process.env.MAINUSER_NAME}, ${process.env.SECONDUSER_NAME}, ${username}`;
// Write messages and check that they are visible
await page.getByPlaceholder('Write a message...').click();
await page.getByPlaceholder('Write a message...').fill('Hello!! :D');
await page.waitForTimeout(300);
await page.locator('form > button:nth-child(2)').click();
await page.getByPlaceholder('Write a message...').click();
await page.waitForTimeout(300);

await bPage.getByRole('button', { name: 'open chat' }).click();
await bPage.getByPlaceholder('Search chatters').click();
await bPage.getByPlaceholder('Search chatters').fill(groupname);
await bPage.getByRole('button', { name: groupname }).first().click();
await page.waitForTimeout(300);
await bPage.getByPlaceholder('Write a message...').fill('Hello!! :D');
await bPage.getByPlaceholder('Write a message...').press('Enter');
await page.waitForTimeout(300);

await cPage.getByRole('button', { name: 'open chat' }).click();
await cPage.getByPlaceholder('Search chatters').click();
await cPage.getByPlaceholder('Search chatters').fill(groupname);
await cPage.getByRole('button', { name: groupname }).first().click();
await page.waitForTimeout(300);
await cPage.getByPlaceholder('Write a message...').fill('Hello!! :D');
await cPage.getByPlaceholder('Write a message...').press('Enter');
await page.waitForTimeout(300);


await expect(page.getByText('Hello!! :D').nth(1)).toBeVisible();
await expect(page.getByText('Hello!! :D').nth(2)).toBeVisible();
await expect(page.getByText('Hello!! :D').nth(3)).toBeVisible();

await expect(bPage.getByText('Hello!! :D').nth(1)).toBeVisible();
await expect(bPage.getByText('Hello!! :D').nth(2)).toBeVisible();
await expect(bPage.getByText('Hello!! :D').nth(3)).toBeVisible();

await expect(cPage.getByText('Hello!! :D').nth(1)).toBeVisible();
await expect(cPage.getByText('Hello!! :D').nth(2)).toBeVisible();
await expect(cPage.getByText('Hello!! :D').nth(3)).toBeVisible();

})
18 changes: 12 additions & 6 deletions Delegation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { login, randomString } from './generic';
import { createPoll, createProposal, fastForward, goToPost, vote } from './poll';
import { createGroup, deleteGroup, gotoGroup, joinGroup } from './group';
import { becomeDelegate } from './delegation';
import { idfy } from './generic';
import 'dotenv/config'
import { assignPermission, createPermission } from './permission';
import { idfy } from './generic';

Expand All @@ -22,7 +24,7 @@ test('Become-Delegate', async ({ page }) => {
test('Delegation-Poll', async ({ page }) => {
await login(page);

const group = { name: 'Test Group Delegation', public: true };
const group = { name: 'Test Group Delegation' + randomString(), public: true };

await createGroup(page, group);

Expand All @@ -34,12 +36,15 @@ test('Delegation-Poll', async ({ page }) => {
const bContext = await browser.newContext();
const bPage = await bContext.newPage();

await login(bPage, { email: 'b@b.se', password: 'b' });
await login(bPage, { email: process.env.SECONDUSER_MAIL, password: process.env.SECONDUSER_PASS });
await joinGroup(bPage, group);

await page.waitForTimeout(1000);
await bPage.getByRole('link', { name: 'Delegations' }).click();
await bPage.locator('#delegate-group-select').selectOption({ label: group.name });
await bPage.getByRole('button', { name: 'Delegations' }).click();
// await bPage.locator('#delegate-group-select').selectOption({ label: group.name });
await bPage.getByRole('textbox', { name: '0/' }).click();
await bPage.getByRole('textbox', { name: '0/' }).fill(group.name);

await page.waitForTimeout(1000);
await bPage.getByRole('button', { name: 'Uncategorised' }).click();
await page.waitForTimeout(1000);
Expand All @@ -49,8 +54,9 @@ test('Delegation-Poll', async ({ page }) => {
await gotoGroup(page, group);
await page.getByRole('button', { name: 'Edit Group' }).dispatchEvent('click');
//Give b voting rights
// await createPermission(page, group, [2]);
// await assignPermission(page, group, "Test Permission", "bb");
const permission_name = "Test Permission" + randomString();
await createPermission(page, group, [2], permission_name);
await assignPermission(page, group, permission_name, process.env.SECONDUSER_NAME);

await gotoGroup(page, group);

Expand Down
Loading
Loading