Skip to content

Commit

Permalink
Merge pull request #387 from 2019-2020-ps6/383-cross-offices-tests
Browse files Browse the repository at this point in the history
383 cross offices tests
  • Loading branch information
ozeliurs authored Jun 14, 2023
2 parents e9b1571 + 1f5d671 commit 5f0756e
Show file tree
Hide file tree
Showing 20 changed files with 396 additions and 37 deletions.
7 changes: 4 additions & 3 deletions apps/front-end/back-office-e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PlaywrightTestConfig } from '@playwright/test';

import { baseConfig } from '../../../playwright.config.base';
import { environment, protocol } from '@webonjour/shared/environments';

const config: PlaywrightTestConfig = {
...baseConfig,
Expand All @@ -12,9 +13,9 @@ const config: PlaywrightTestConfig = {
),
use: {
...baseConfig.use,
ignoreHTTPSErrors: true,
video: 'on-first-retry',
screenshot: 'only-on-failure',
baseURL: `${protocol(environment.back_office.secure)}://${
environment.back_office.domain
}`,
},
};

Expand Down
31 changes: 31 additions & 0 deletions apps/front-end/back-office-e2e/src/quiz/quiz.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ test.describe('Quiz', () => {
test('should edit quiz', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.updateQuiz(QUIZ_UPDATED_NAME);

await fixtures.quizPage.goto();
Expand All @@ -45,6 +46,7 @@ test.describe('Quiz', () => {
DEFAULT_QUIZ_COUNT + 1
);
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await expect(
await fixtures.quizEditPage.quizGeneralTitle.inputValue()
).toBe(QUIZ_UPDATED_NAME);
Expand All @@ -53,9 +55,11 @@ test.describe('Quiz', () => {
test('should add question to quiz', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.questionAddPage.addQuestion('Question 1', 'CHOICE');
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().waitFor({
state: 'visible',
});
Expand All @@ -65,12 +69,15 @@ test.describe('Quiz', () => {
test('should edit question', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.questionEditPage.page.waitForLoadState('networkidle');
await fixtures.questionEditPage.updateQuestion('Question 2');
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await expect(
await fixtures.questionEditPage.questionGeneralTitle.inputValue()
).toBe('Question 2');
Expand All @@ -79,7 +86,9 @@ test.describe('Quiz', () => {
test('should add answer to question', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.answerPage.addAnswer('Answer 1', true);
// wait for answer to be visible
await fixtures.answerPage.answers.last().waitFor({
Expand All @@ -92,11 +101,15 @@ test.describe('Quiz', () => {
test('should edit answer', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.answerPage.updateAnswer(0, 'Answer 2', false);
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await expect(
await fixtures.answerPage.answers
.first()
Expand All @@ -109,18 +122,24 @@ test.describe('Quiz', () => {
test('should delete answer', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.answerPage.deleteAnswer(0);
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
expect(await fixtures.answerPage.answers.count()).toBe(0);
});

test('should add clue to question', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.cluePage.addClue('Clue 1');
// wait for clue to be visible
await fixtures.cluePage.clues.last().waitFor({
Expand All @@ -132,11 +151,15 @@ test.describe('Quiz', () => {
test('should edit clue', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.cluePage.updateClue(0, 'Clue 2');
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await expect(
await fixtures.cluePage.clues.first().locator('td').first().innerText()
).toBe('Clue 2');
Expand All @@ -145,27 +168,35 @@ test.describe('Quiz', () => {
test('should delete clue', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.cluePage.deleteClue(0);
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
expect(await fixtures.cluePage.clues.count()).toBe(0);
});

test('should delete question', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.questions.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.questionEditPage.deleteQuestion();
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
expect(await fixtures.quizEditPage.questions.count()).toBe(0);
});

test('should delete quiz', async ({ fixtures }) => {
await fixtures.quizPage.goto();
await fixtures.quizPage.quizzes.last().click();
await fixtures.quizPage.page.waitForLoadState('networkidle');
await fixtures.quizEditPage.deleteQuiz();
expect(await fixtures.quizPage.quizzes.count()).toBe(DEFAULT_QUIZ_COUNT);
});
Expand Down
5 changes: 4 additions & 1 deletion apps/front-end/back-office/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "front-end-back-office:build:production"
"browserTarget": "front-end-back-office:build:production",
"port": 4200,
"host": "0.0.0.0"
},
"development": {
"host": "127.0.0.1",
"port": 4200,
"browserTarget": "front-end-back-office:build:development"
}
},
Expand Down
22 changes: 22 additions & 0 deletions apps/front-end/cross-office-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"jest/no-done-callback": "off"
}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {
"jest/no-done-callback": "off"
}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
18 changes: 18 additions & 0 deletions apps/front-end/cross-office-e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { PlaywrightTestConfig } from '@playwright/test';

import { baseConfig } from '../../../playwright.config.base';

const config: PlaywrightTestConfig = {
...baseConfig,
globalSetup: require.resolve(
'apps/front-end/cross-office-e2e/src/support/global-setup.ts'
),
globalTeardown: require.resolve(
'apps/front-end/cross-office-e2e/src/support/global-teardown.ts'
),
use: {
...baseConfig.use,
},
};

export default config;
56 changes: 56 additions & 0 deletions apps/front-end/cross-office-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "front-end-cross-office-e2e",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/front-end/cross-office-e2e/src",
"projectType": "application",
"targets": {
"front-end-serve": {
"executor": "@angular-devkit/architect:allOf",
"options": {
"targets": [
{
"target": "front-end-back-office:serve"
},
{
"target": "front-end-front-office:serve"
}
]
}
},
"e2e": {
"executor": "@mands/nx-playwright:playwright-executor",
"options": {
"ui": true,
"e2eFolder": "apps/front-end/cross-office-e2e",
"packageRunner": "npx",
"devServerTarget": "front-end-cross-office-e2e:front-end-serve"
},
"configurations": {
"ci": {
"ui": false
},
"development": {}
}
},
"ts-check": {
"executor": "nx:run-commands",
"options": {
"commands": [
{
"command": "tsc --build --force --verbose apps/undefined-e2e/tsconfig.json"
}
]
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"apps/front-end/cross-office-e2e/**/*.{ts,tsx,js,jsx}"
]
}
}
},
"tags": []
}
31 changes: 31 additions & 0 deletions apps/front-end/cross-office-e2e/src/app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect } from '@playwright/test';
import { test } from '@webonjour/fixtures-e2e';

test.describe('cross-office', () => {
test.afterEach(async ({ backOfficePage, frontOfficePage }) => {
await backOfficePage.close();
await frontOfficePage.close();
});

test('back should work', async ({ BackOffice }) => {
await BackOffice.loginPage.goto();
expect(true).toBeTruthy();
});

test('front should work', async ({ FrontOffice }) => {
await FrontOffice.floorSelectionPage.goto();
expect(true).toBeTruthy();
});

test('floor selection should work', async ({ FrontOffice }) => {
await FrontOffice.floorSelectionPage.goto();
await FrontOffice.floorSelectionPage.selectFloor(0);
expect(true).toBeTruthy();
});

test('using both', async ({ BackOffice, FrontOffice }) => {
await BackOffice.loginPage.goto();
await FrontOffice.floorSelectionPage.goto();
expect(true).toBeTruthy();
});
});
63 changes: 63 additions & 0 deletions apps/front-end/cross-office-e2e/src/support/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint-disable */
import axios from 'axios';
import { subProcess, subProcessSync } from 'subspawn';
import { environment, protocol } from '@webonjour/shared/environments';

var __TEARDOWN_MESSAGE__: string;

module.exports = async function () {
// Start services that the app needs to run (e.g. database, docker-compose, etc.).
console.log('\nSetting up...\n');

let executor = 'docker-compose';

// Check if docker compose is installed
try {
subProcessSync('docker-compose --version', true);
} catch (e) {
executor = 'podman-compose';
try {
subProcessSync('podman-compose --version', true);
} catch (e) {
executor = 'docker compose';
try {
subProcessSync('docker compose --version', true);
} catch (e) {
console.log('Please install docker-compose or podman-compose');
process.exit(1);
}
}
}

subProcessSync(`${executor} -f docker-compose.yml up -d`, true);
// wait for the database to start
for (let i = 0; i < 200; i++) {
try {
// subProcessSync("npx prisma migrate dev deploy", true);
subProcessSync('npx prisma migrate reset --force', true);
subProcessSync('npx prisma generate', true);
break;
} catch (e) {
console.log('Waiting for database to start...');
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
subProcess('API', 'npx nx serve backend-api', true);

axios.defaults.baseURL = `${protocol(environment.api.secure)}://${
environment.api.domain
}`;
console.log('axios.defaults.baseURL', axios.defaults.baseURL);
// wait for the server to start
for (let i = 0; i < 200; i++) {
try {
await axios.get(`/health`);
break;
} catch (e) {
console.log('Waiting for server to start...');
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
// Hint: Use `globalThis` to pass variables to global teardown.
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
};
Loading

0 comments on commit 5f0756e

Please sign in to comment.