Skip to content

Commit

Permalink
fix(AVO-3195): add t65
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-emsens-shd committed May 28, 2024
1 parent 21bd794 commit e36a121
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"test:e2e:debug:t62": "cross-env PWDEBUG=console dotenv -e ../.env.qas npx playwright test tests/t62-opdracht-onderwijsniveau-beide.spec",
"test:e2e:debug:t63": "cross-env PWDEBUG=console dotenv -e ../.env.qas npx playwright test tests/t63-opdracht-onderwijsniveau-lager.spec",
"test:e2e:debug:t64": "cross-env PWDEBUG=console dotenv -e ../.env.qas npx playwright test tests/t64-opdracht-onderwijsniveau-secundair.spec",
"test:e2e:debug:t65": "cross-env PWDEBUG=console dotenv -e ../.env.qas npx playwright test tests/t65-opdracht-delen.spec",
"test:e2e:debug:beheer:t05": "cross-env PWDEBUG=console dotenv -e ../.env.qas npx playwright test tests/beheer/t05-beheer-navigeer-naar-bewerkpagina.spec",
"test:e2e:debug:beheer:t06": "cross-env PWDEBUG=console dotenv -e ../.env.qas npx playwright test tests/beheer/t06-beheer-gebruiker-activeren.spec",
"test:e2e:debug:beheer:t07": "cross-env PWDEBUG=console dotenv -e ../.env.qas npx playwright test tests/beheer/t07-beheer-gebruiker-deactiveren.spec",
Expand Down
211 changes: 211 additions & 0 deletions tests/tests/t65-opdracht-delen.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import { expect, type Page, test } from '@playwright/test';

import { cleanupTestdata } from '../helpers/cleanup';
import { goToPageAndAcceptCookies } from '../helpers/go-to-page-and-accept-cookies';
import { loginOnderwijsAvo } from '../helpers/login-onderwijs-avo';
import { logoutOnderwijsAvo } from '../helpers/logout-onderwijs-avo';

/**
* This test requires `PROXY_E2E=true`
* https://github.com/viaacode/avo2-proxy/commit/ae4e79f3b1c4826f5c81ba570b15d904990d43b7
* https://github.com/viaacode/avo2-proxy/commit/9b9b740fea4b66478d850da4de8a1d74da8d845e
*/

test.afterEach(async ({ page }, testInfo) => {
if (testInfo.status !== testInfo.expectedStatus) {
console.log(`Did not run as expected`);
await cleanupTestdata(page);
}
});

test('T65: opdracht delen van lesgever lager naar lesgever secundair', async ({ page }) => {
await shareAssignmentAndAccept(
page,
{
user: process.env.TEST_LESGEVER_LAGER_GEBRUIKER_USER as string,
pass: process.env.TEST_LESGEVER_LAGER_GEBRUIKER_PASS as string,
},
{
user: process.env.TEST_LESGEVER_SECUNDAIR_GEBRUIKER_USER as string,
pass: process.env.TEST_LESGEVER_SECUNDAIR_GEBRUIKER_PASS as string,
},
false
);
});

test('T65: opdracht delen van lesgever secundair naar lesgever lager', async ({ page }) => {
await shareAssignmentAndAccept(
page,
{
user: process.env.TEST_LESGEVER_SECUNDAIR_GEBRUIKER_USER as string,
pass: process.env.TEST_LESGEVER_SECUNDAIR_GEBRUIKER_PASS as string,
},
{
user: process.env.TEST_LESGEVER_LAGER_GEBRUIKER_USER as string,
pass: process.env.TEST_LESGEVER_LAGER_GEBRUIKER_PASS as string,
},
false
);
});

test('T65: opdracht delen van lesgever lager naar lesgever beide', async ({ page }) => {
await shareAssignmentAndAccept(
page,
{
user: process.env.TEST_LESGEVER_LAGER_GEBRUIKER_USER as string,
pass: process.env.TEST_LESGEVER_LAGER_GEBRUIKER_PASS as string,
},
{
user: process.env.TEST_LESGEVER_BEIDE_GEBRUIKER_USER as string,
pass: process.env.TEST_LESGEVER_BEIDE_GEBRUIKER_PASS as string,
},
true
);
});

test('T65: opdracht delen van lesgever secundair naar lesgever beide', async ({ page }) => {
await shareAssignmentAndAccept(
page,
{
user: process.env.TEST_LESGEVER_SECUNDAIR_GEBRUIKER_USER as string,
pass: process.env.TEST_LESGEVER_SECUNDAIR_GEBRUIKER_PASS as string,
},
{
user: process.env.TEST_LESGEVER_BEIDE_GEBRUIKER_USER as string,
pass: process.env.TEST_LESGEVER_BEIDE_GEBRUIKER_PASS as string,
},
true
);
});

async function createAssignmentWithTitle(page: Page) {
// Click mijn werkruimte
await page.getByRole('link', { name: 'Mijn werkruimte' }).click();

// Go to assignments tab
await page.click('div[data-id="opdrachten"]');

// Create new assignment
await page.getByRole('button', { name: 'Nieuwe opdracht' }).click();

// Check if banner appeared
await expect(page.locator('div.c-sticky-bar')).toContainText('Wijzigingen opslaan?');

await page.waitForTimeout(1000);

// Save changes
await page.getByRole('button', { name: 'Opslaan' }).click();

// Edit assignment
await page.getByRole('button', { name: 'Bewerken' }).click();

// Open input title
await page
.locator(
'div.o-container-vertical.o-container-vertical--small > div > div > div.c-toolbar__left > div > div > h2 > div > div'
)
.nth(1)
.click();

// Enter title
const date = new Date();
const assignmentTitle = 'Aangemaakt door automatische test ' + date;
await page.locator('input[placeholder="Geef een titel in"]').nth(1).fill(assignmentTitle);
await page.click('div.c-content-input__submit');

await page.waitForTimeout(1000);

// Save changes
await page.getByRole('button', { name: 'Opslaan' }).click();

return page.url();
}

async function goToShareWithColleagues(page: Page) {
// Click "Delen"
await page.click(
'div.u-hide-lt-bp2 > div > div.o-container-vertical.o-container-vertical--small > div > div > div.c-toolbar__right > div > div.u-hide-lt-bp2 > div > div.c-share-dropdown.c-dropdown.c-dropdown__trigger > button'
);

// Click "Collega's"
await page.click('.c-share-dropdown + .c-dropdown__content-open .c-tab-item:first-child');

await page.waitForTimeout(1000);
}

async function shareAssignmentWith(page: Page, email: string, role = 1) {
// enter contributor email
await page
.locator('.c-share-dropdown + .c-dropdown__content-open .c-add-colleague input')
.nth(0)
.fill(email);

// open role selection
await page.click(
'.c-share-dropdown + .c-dropdown__content-open .c-add-colleague .c-dropdown__trigger'
);

await page.click(
`.c-share-dropdown + .c-dropdown__content-open .c-add-colleague .c-dropdown__content-open .c-menu__item:nth-child(${role})`
);

await page.waitForTimeout(1000);

// submit add contributor
await page.click('.c-share-dropdown + .c-dropdown__content-open .c-add-colleague__button');

// confirm warning
await page.click('.c-modal-context--visible .c-button-toolbar .c-button--primary');

await page.waitForTimeout(5000);
}

async function acceptAssignmentInvitation(page: Page, assignmentId: string) {
// Go to assignment page with token
await page.goto(
`${process.env.TEST_CLIENT_ENDPOINT}opdrachten/${assignmentId}?inviteToken=${assignmentId}`
);

await page.waitForTimeout(1000);

// click "Toevoegen"
await page.click('.c-sticky-bar__cta ~ button:nth-child(3)');
}

async function shareAssignmentAndAccept(
page: Page,
from: { user: string; pass: string },
to: { user: string; pass: string },
shouldBeEditable?: boolean
) {
const url = process.env.TEST_CLIENT_ENDPOINT as string;
const title = process.env.TEST_CLIENT_TITLE as string;

await goToPageAndAcceptCookies(page, url, title);

await loginOnderwijsAvo(page, url, from.user, from.pass);

const assignmentUrl = await createAssignmentWithTitle(page);
const assignmentId = assignmentUrl.match(/opdrachten\/(.*)\/bewerk/)?.[1];

expect(assignmentId).toBeTruthy();

await page.waitForTimeout(5000);

await goToShareWithColleagues(page);
await shareAssignmentWith(page, to.user);

await logoutOnderwijsAvo(
page,
from.user === (process.env.TEST_LESGEVER_SECUNDAIR_GEBRUIKER_USER as string)
);

await loginOnderwijsAvo(page, url, to.user, to.pass);

await acceptAssignmentInvitation(page, assignmentId as string);

// Check "Bewerken" button
await expect(page.locator('.c-header .c-button--primary').nth(0)).toBeVisible({
visible: shouldBeEditable,
});
}

0 comments on commit e36a121

Please sign in to comment.