From bc59b7b7da5a73768cfa9090f8dca9853bd08a6d Mon Sep 17 00:00:00 2001 From: uo289267 Date: Thu, 25 Apr 2024 12:43:03 +0200 Subject: [PATCH 1/4] Added new steps --- webapp/e2e/features/competitiveGame.feature | 5 ++ webapp/e2e/steps/competitiveGame.steps.js | 50 +++++++++++++++++++ webapp/e2e/test-environment-setup.js | 4 +- .../GameConfigurator/GameConfigurator.js | 2 +- 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 webapp/e2e/features/competitiveGame.feature create mode 100644 webapp/e2e/steps/competitiveGame.steps.js diff --git a/webapp/e2e/features/competitiveGame.feature b/webapp/e2e/features/competitiveGame.feature new file mode 100644 index 00000000..073860be --- /dev/null +++ b/webapp/e2e/features/competitiveGame.feature @@ -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 \ No newline at end of file diff --git a/webapp/e2e/steps/competitiveGame.steps.js b/webapp/e2e/steps/competitiveGame.steps.js new file mode 100644 index 00000000..037bd8b7 --- /dev/null +++ b/webapp/e2e/steps/competitiveGame.steps.js @@ -0,0 +1,50 @@ +const puppeteer = require('puppeteer'); +const { defineFeature, loadFeature } = require('jest-cucumber'); +const setDefaultOptions = require('expect-puppeteer').setDefaultOptions; + +const feature = loadFeature('./features/gameMenu.feature'); + +const { register, login, logout } = require("../utils"); + +let page; +let browser; + +const email = "testUser@example.com"; +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, 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'); + }); + }); + +}); diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index efd12b6e..349be901 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -12,14 +12,14 @@ async function startServer() { mongoserver = await MongoMemoryServer.create(); //Populate db - await loadQuestions(); + //await loadQuestions(); const mongoUri = mongoserver.getUri(); process.env.MONGODB_URI = mongoUri; process.env.MONGODB_URI_QUESTIONS = mongoUri; questionservice = await require("../../questionservice/question-service") recordservice = await require("../../users/recordservice/record-service"); - userservice = await require("../../users/userservice/user-service"); + //userservice = await require("../../users/userservice/user-service"); authservice = await require("../../users/authservice/auth-service"); gatewayservice = await require("../../gatewayservice/gateway-service"); } diff --git a/webapp/src/components/GameConfigurator/GameConfigurator.js b/webapp/src/components/GameConfigurator/GameConfigurator.js index 4a536729..5ab12b27 100644 --- a/webapp/src/components/GameConfigurator/GameConfigurator.js +++ b/webapp/src/components/GameConfigurator/GameConfigurator.js @@ -79,7 +79,7 @@ function ButtonCustomized({t,handleClick}) { function ButtonCompetitive({t}){ return ( - +

{t("gameConfigurator.play_competi")}

); From baa22ada34077cfa698c06a32592bb49d9f700f4 Mon Sep 17 00:00:00 2001 From: uo289267 Date: Thu, 25 Apr 2024 13:00:40 +0200 Subject: [PATCH 2/4] Fixed e2e --- webapp/e2e/steps/competitiveGame.steps.js | 6 +++--- webapp/e2e/test-environment-setup.js | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/webapp/e2e/steps/competitiveGame.steps.js b/webapp/e2e/steps/competitiveGame.steps.js index 037bd8b7..082c0cf9 100644 --- a/webapp/e2e/steps/competitiveGame.steps.js +++ b/webapp/e2e/steps/competitiveGame.steps.js @@ -2,7 +2,7 @@ const puppeteer = require('puppeteer'); const { defineFeature, loadFeature } = require('jest-cucumber'); const setDefaultOptions = require('expect-puppeteer').setDefaultOptions; -const feature = loadFeature('./features/gameMenu.feature'); +const feature = loadFeature('./features/competitiveGame.feature'); const { register, login, logout } = require("../utils"); @@ -17,7 +17,7 @@ defineFeature(feature, test => { beforeAll(async () => { browser = await puppeteer.launch({ - headless: "new", + headless: false, slowMo: 40, defaultViewport: { width: 1920, height: 1080 }, args: ['--window-size=1920,1080'] @@ -34,7 +34,7 @@ defineFeature(feature, test => { await login(page, username, password); }) - test('Create Competitive Game should go to /questions', ({ given, then }) => { + 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'); diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index 349be901..44e73ddb 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -12,14 +12,14 @@ async function startServer() { mongoserver = await MongoMemoryServer.create(); //Populate db - //await loadQuestions(); + await loadQuestions(); const mongoUri = mongoserver.getUri(); process.env.MONGODB_URI = mongoUri; process.env.MONGODB_URI_QUESTIONS = mongoUri; questionservice = await require("../../questionservice/question-service") recordservice = await require("../../users/recordservice/record-service"); - //userservice = await require("../../users/userservice/user-service"); + userservice = await require("../../users/userservice/user-service"); authservice = await require("../../users/authservice/auth-service"); gatewayservice = await require("../../gatewayservice/gateway-service"); } @@ -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(); From ec4ddb63b4db7f9c48768b3474750aea4fcb761f Mon Sep 17 00:00:00 2001 From: uo289267 Date: Thu, 25 Apr 2024 13:07:12 +0200 Subject: [PATCH 3/4] dont forget the new for headless --- webapp/e2e/steps/competitiveGame.steps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/e2e/steps/competitiveGame.steps.js b/webapp/e2e/steps/competitiveGame.steps.js index 082c0cf9..95f41dad 100644 --- a/webapp/e2e/steps/competitiveGame.steps.js +++ b/webapp/e2e/steps/competitiveGame.steps.js @@ -17,7 +17,7 @@ defineFeature(feature, test => { beforeAll(async () => { browser = await puppeteer.launch({ - headless: false, + headless: "new", slowMo: 40, defaultViewport: { width: 1920, height: 1080 }, args: ['--window-size=1920,1080'] From 4709fc8e7578d31f43b59a8d54cfa5261bfb9d7b Mon Sep 17 00:00:00 2001 From: uo289267 Date: Thu, 25 Apr 2024 13:14:31 +0200 Subject: [PATCH 4/4] Fixed All for question configurator --- webapp/src/components/questionView/QuestionGenerator.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/webapp/src/components/questionView/QuestionGenerator.js b/webapp/src/components/questionView/QuestionGenerator.js index ec7a1b6d..5ede8c08 100644 --- a/webapp/src/components/questionView/QuestionGenerator.js +++ b/webapp/src/components/questionView/QuestionGenerator.js @@ -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)