Skip to content

Commit

Permalink
Merge pull request #89 from Arquisoft/87-e2e-test
Browse files Browse the repository at this point in the history
Finished the issue
  • Loading branch information
uo289267 authored Apr 14, 2024
2 parents 9e11fd4 + d0f8d61 commit 6a31274
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 36 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,20 @@ jobs:
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
e2e-tests:
needs: [unit-tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix questionservice install
- run: npm --prefix users/recordservice install
- run: npm --prefix users/authservice install
- run: npm --prefix users/userservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
30 changes: 23 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,26 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
e2e-tests:
needs: [unit-tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix questionservice install
- run: npm --prefix users/recordservice install
- run: npm --prefix users/authservice install
- run: npm --prefix users/userservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
docker-push-webapp:
name: Push webapp Docker Image to GitHub Packages
runs-on: ubuntu-latest
needs: [unit-tests]
needs: [e2e-tests]
permissions:
contents: read
packages: write
Expand All @@ -52,7 +68,7 @@ jobs:
docker-push-authservice:
name: Push auth service Docker Image to GitHub Packages
runs-on: ubuntu-latest
needs: [unit-tests]
needs: [e2e-tests]
permissions:
contents: read
packages: write
Expand All @@ -69,7 +85,7 @@ jobs:
docker-push-userservice:
name: Push user service Docker Image to GitHub Packages
runs-on: ubuntu-latest
needs: [unit-tests]
needs: [e2e-tests]
permissions:
contents: read
packages: write
Expand All @@ -86,7 +102,7 @@ jobs:
docker-push-recordservice:
name: Push record service Docker Image to GitHub Packages
runs-on: ubuntu-latest
needs: [unit-tests]
needs: [e2e-tests]
permissions:
contents: read
packages: write
Expand All @@ -103,7 +119,7 @@ jobs:
docker-push-gatewayservice:
name: Push gateway service Docker Image to GitHub Packages
runs-on: ubuntu-latest
needs: [unit-tests]
needs: [e2e-tests]
permissions:
contents: read
packages: write
Expand All @@ -120,7 +136,7 @@ jobs:
docker-push-questionservice:
name: Push question service Docker Image to GitHub Packages
runs-on: ubuntu-latest
needs: [unit-tests]
needs: [e2e-tests]
permissions:
contents: read
packages: write
Expand All @@ -137,7 +153,7 @@ jobs:
docker-push-questiongenerator:
name: Push question generator Docker Image to GitHub Packages
runs-on: ubuntu-latest
needs: [unit-tests]
needs: [e2e-tests]
permissions:
contents: read
packages: write
Expand Down
3 changes: 1 addition & 2 deletions webapp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ RUN npm run build
RUN npm install serve

#Execute npm run prod to run the server
CMD [ "npm", "run", "prod" ]
#CMD ["npm", "start"]
CMD [ "npm", "run", "prod" ]
2 changes: 1 addition & 1 deletion webapp/e2e/features/home.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Feature: Home page functionality

Scenario: Closing the text container
Given I am on the home page
When I click on the toggle button to close
When I click on the toggle button to open and then I click it to close
Then The text container should be visible

41 changes: 35 additions & 6 deletions webapp/e2e/steps/home.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,61 @@ let browser;
defineFeature(feature, test => {

beforeAll(async () => {
browser = await puppeteer.launch({ headless: false });
browser = await puppeteer.launch({
slowMo: 20,
defaultViewport: { width: 1920, height: 1080 },
args: ['--window-size=1920,1080']
});

page = await browser.newPage();
setDefaultOptions({ timeout: 10000 });
});

test('The text container is initially visible', ({ given, then }) => {
given('I am on the home page', async () => {
await page.goto('http://localhost:3000/home');
await page.waitForSelector('.general');
});

then('The text container should be visible', async () => {
await expect(page).toMatchElement('.text-container.visible');
});
});

test('Opening the text container', ({ given, when, then }) => {
given('I am on the home page', async () => {
await page.goto('http://localhost:3000/home');
await page.waitForSelector('.general');
});

when('I click on the toggle button to open', async () => {
await page.click('#toggleOpen');
await page.click('label[for="toggleOpen"]');
});

then('The text container should be hidden', async () => {
await expect(page).toMatchElement('.text-container.hidden');
});
/*
when('I click on the toggle button to close', async () => {
await page.click('#toggleClose');
});

test('Closing the text container', ({ given, when, then }) => {
given('I am on the home page', async () => {
await page.goto('http://localhost:3000/home');
await page.waitForSelector('.general');
});

when('I click on the toggle button to open and then I click it to close', async () => {

await page.click('label[for="toggleOpen"]');

// Wait for label to be render, visible : true
await page.waitForSelector(`label[for="toggleClose"]`, {visible: true});
await page.click('label[for="toggleClose"]');

});

then('The text container should be visible', async () => {
await expect(page).toMatchElement('.text-container.visible');
});*/
});
});

afterAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
WAIT UNTIL REGISTER IS FINALIZED (Add email)

const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
Expand Down
27 changes: 15 additions & 12 deletions webapp/src/components/HistoricalData/HistoricalView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useState } from 'react';
import React, { useState } from 'react';
import {useTranslation} from "react-i18next";
import HistoryRecordRetriever from './HistoryRecordRetriever';
import { useUserContext } from '../loginAndRegistration/UserContext';
Expand All @@ -10,23 +10,26 @@ const retriever = new HistoryRecordRetriever();


export default function HistoricalView() {
const [records, setRecords]= useState([]);
const [records, setRecords]= useState(null);
const[t] = useTranslation("global");
const {user} = useUserContext();

const getRecords = async ()=>{
try {
var jsonRecords = await retriever.getRecords(user.username);
var recordsArray = jsonRecords.games;
setRecords(recordsArray);
} catch (error) {
console.log(error);
}
const getRecords = async ()=>{
try {
var jsonRecords = await retriever.getRecords(user.username);
var recordsArray = jsonRecords.games;
setRecords(recordsArray);
} catch (error) {
console.log(error);
}
}
useEffect(() => {getRecords()}, []);

if(records === null)
getRecords();

return (
<div className='globalHistoricalView'>
{(records && records.length != 0) ? records.map((record, index) => (
{(records && records.length !== 0) ? records.map((record, index) => (
<HistoricalGameElement key={index} record={record} t={t} />
)): <p>{t("historicalView.no_games_played")}</p>}
</div>
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function Home() {
<figure id="welcomeMessage">
<figcaption>
<h1>
<label htmlFor="toggleOpen" title={t("home.clickOpen")} id={t("home.clickOpen")}></label>
<label htmlFor="toggleClose" title={t("home.clickClose")} id={t("home.click")}></label>
<label htmlFor="toggleOpen" title={t("home.clickOpen")}></label>
<label htmlFor="toggleClose" title={t("home.clickClose")}></label>
<b>
W
<Link to="/instructions" title={t("home.how_to_play")}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CreationHistoricalRecord{
}

addQuestion(statement, answers, answerGiven, correctAnswer, numQuestion) {
if(this.record.game.questions.length == numQuestion){
if(this.record.game.questions.length === numQuestion){
this.record.game.questions.push({
question: statement,
answers: answers,
Expand Down
10 changes: 6 additions & 4 deletions webapp/src/components/questionView/QuestionView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QuestionGenerator from './QuestionGenerator';
import CreationHistoricalRecord from './CreationHistoricalRecord';
import { useEffect, useState } from 'react';
import { useState } from 'react';
import "../../custom.css";
import React from "react";
import Countdown from 'react-countdown';
Expand All @@ -15,7 +15,7 @@ const questionGenerator = new QuestionGenerator();
var points = 0;
function QuestionView(){
const [numQuestion, setnumQuestion] = useState(-1);
const [questions, setQuestions] = useState([]);
const [questions, setQuestions] = useState(null);
const[t, i18n] = useTranslation("global");
const {user} = useUserContext();

Expand Down Expand Up @@ -62,7 +62,7 @@ function QuestionView(){
});
}
function computePointsForQuestion(correctAnswer, answerGiven){
if(answerGiven==correctAnswer){
if(answerGiven===correctAnswer){
points+=100;
}else if(points-50>=0){
points-=50;
Expand Down Expand Up @@ -98,7 +98,9 @@ function QuestionView(){

}

useEffect(() => {generateQuestions(numQuestion)}, []);
if(questions === null)
generateQuestions(numQuestion)


return (
<div className="question-view-container">
Expand Down

0 comments on commit 6a31274

Please sign in to comment.