Skip to content

Commit

Permalink
Merge pull request #127 from Arquisoft/99-e2e-testing
Browse files Browse the repository at this point in the history
99 e2e testing
  • Loading branch information
Mister-Mario authored Apr 25, 2024
2 parents 287aabf + 4709fc8 commit 5faed58
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
5 changes: 5 additions & 0 deletions webapp/e2e/features/competitiveGame.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Game Configurator and Competitive Game functionality
Scenario: Create Competitive Game should go to /questions
Given I am on the game configurator
When I click on new competitive game
Then I am in /questions
50 changes: 50 additions & 0 deletions webapp/e2e/steps/competitiveGame.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature } = require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions;

const feature = loadFeature('./features/competitiveGame.feature');

const { register, login, logout } = require("../utils");

let page;
let browser;

const email = "[email protected]";
const username = "testUser"
const password = "testUserPassword"

defineFeature(feature, test => {

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

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

await register(page, email, username, password);
});

beforeEach(async () => {
await logout(page);
await login(page, username, password);
})

test('Create Competitive Game should go to /questions', ({ given,when, then }) => {
given('I am on the game configurator', async () => {
await page.goto('http://localhost:3000/configurator');
await page.waitForSelector('.GameConfiguratorDiv');
});
when('I click on new competitive game', async () => {
await page.click('#competitive');
});
then('I am in /questions', async () => {
await expect(page).toMatchElement('.questionContainer');
});
});

});
9 changes: 8 additions & 1 deletion webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,14 @@ async function loadQuestions() {
}]

//No need of loading questions for these tests
//await Question.bulkSave(questions);
await questions.forEach(async question =>{
let dbQuestion = new Question();
dbQuestion.question=question.question;
dbQuestion.answers=question.answers;
dbQuestion.language=question.language;
dbQuestion.type=question.type;
await dbQuestion.save();
});
}

startServer();
2 changes: 1 addition & 1 deletion webapp/src/components/GameConfigurator/GameConfigurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function ButtonCustomized({t,handleClick}) {
function ButtonCompetitive({t}){

return (
<Link className="linkButton" to="/questions">
<Link className="linkButton" id="competitive" to="/questions">
<h3>{t("gameConfigurator.play_competi")}</h3>
</Link>
);
Expand Down
5 changes: 4 additions & 1 deletion webapp/src/components/questionView/QuestionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ class QuestionGenerator{
let response;
if(type==="COMPETITIVE"){
response = await axios.get(this.apiUrl + '/' + lang, {headers : {'token':token}});
}else{
}else if(type==="ALL"){
response = await axios.get(this.apiUrl + '/' + lang + '/' +amount, {headers : {'token':token}});
}
else{
response = await axios.get(this.apiUrl + '/' + lang + '/' +amount + '/' + type, {headers : {'token':token}});
}
console.log(response)
Expand Down

0 comments on commit 5faed58

Please sign in to comment.