Skip to content

Commit

Permalink
Merge branch 'master' into e2e_laura
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Mario committed Apr 27, 2024
2 parents 4fecee7 + 67c897f commit becbd1e
Show file tree
Hide file tree
Showing 23 changed files with 603 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public AnswersAreEntitiesWithSubProperties(String propertyId, QuestionType type,
this.PROPERTY_TO_CHECK = propertyToCheck;
}

/* The value of the Snak is deprecated and no longer implemented or updated, but since we are simply
* checking whether is null or not is not important
*/
@SuppressWarnings("deprecation")
@Override
public String getRightAnswer(Map<String, List<Statement>> claims, String propertyId) throws Exception {
if(claims.get(propertyId)==null) {
Expand All @@ -31,6 +35,8 @@ public String getRightAnswer(Map<String, List<Statement>> claims, String propert
for(Snak s : sg.getSnaks()) {
String value = getIdFromLink(s.getPropertyId().toString());
if(value.equals(PROPERTY_TO_CHECK)) {
if(s.getValue()==null)
return processRightAnswer(st);
valid = false;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.wikidata.wdtk.datamodel.interfaces.Statement;
import org.wikidata.wdtk.datamodel.interfaces.Value;
Expand Down Expand Up @@ -49,6 +50,24 @@ public List<String> getWrongAnswers(String rightAnswer) {
for(String s : original) {
result.add(String.valueOf((int) Float.parseFloat(s)));
}
return ensureAllAnswersAreDiferent(result);
}

private List<String> ensureAllAnswersAreDiferent(List<String> answers){
List<String> result = new ArrayList<>();
for(String answer : answers) {
if(!result.contains(answer))
result.add(answer);
else {
Random rn = new Random();
while(result.contains(answer)) {
int realAnswer = Integer.parseInt(answer);
int half = realAnswer /2;
int newValue = rn.nextInt(half, realAnswer+half);
answer = String.valueOf(newValue);
}
}
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import main.java.questionGenerator.question.answers.formatAnswers.AddUnitsFormater;
import main.java.questionGenerator.question.answers.formatAnswers.EmbellishNumbersFormater;
import main.java.questionGenerator.question.answers.formatAnswers.RemoveEFromNumber;
import main.java.questionGenerator.question.answers.formatAnswers.SetAmountOfDecimals;

public class SizeGenerator extends AnswersAreNotEntites {

Expand Down Expand Up @@ -45,7 +46,7 @@ private String getRightAnswerEntity(String url) {
@Override
public List<String> decorateAnswers(List<String> answers) {
AnswerFormater formater = new RemoveEFromNumber(new EmbellishNumbersFormater(
new AddUnitsFormater(null, "km^2")));
new SetAmountOfDecimals(new AddUnitsFormater(null, "km^2"), 2)));
return formater.format(answers);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main.java.questionGenerator.question.answers.formatAnswers;

import java.util.ArrayList;
import java.util.List;

import main.java.questionGenerator.question.answers.AbstractFormater;
import main.java.questionGenerator.question.answers.AnswerFormater;

public class SetAmountOfDecimals extends AbstractFormater {

private int amount;

public SetAmountOfDecimals(AnswerFormater formater, int amount) {
super(formater);
this.amount = amount;
}

@Override
public List<String> format(List<String> answers) {
List<String> result = new ArrayList<>();
for(String answer : answers) {
String[] splitted = split(answer);
if(splitted.length==0)
result.add(answer);
else {
String decimalPart = formatDecimalPart(splitted[1]);
result.add(splitted[0] + '.' + decimalPart);
}
}
return end(result);
}

private String[] split(String answer) {
String[] result = {"", ""};
int position = 0;
for(char c : answer.toCharArray()) {
if(c=='.')
position = 1;
else
result[position] += c;
}
return result;
}

private String formatDecimalPart(String decimalPart) {
if(decimalPart.length()<amount) {
int diference = amount - decimalPart.length();
for(int i=0; i<diference; i++) {
decimalPart += "0";
}
}
else if(decimalPart.length()>amount) {
char[] aux = decimalPart.toCharArray();
decimalPart = "";
for(int i=0; i<amount; i++) {
decimalPart += aux[i];
}
}
return decimalPart;
}

}
9 changes: 0 additions & 9 deletions webapp/e2e/features/competitiveGame.feature

This file was deleted.

12 changes: 10 additions & 2 deletions webapp/e2e/features/gameMenu.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
Feature: Game Menu page functionality
Scenario: There should be visible three links
Given I am on the game menu
Then three buttons should be visible
Given I am on the game menu
Then three buttons should be visible
Scenario: New Game should go to game configurator
Given I am on the game menu
When I click on New Game
Then I should be in the game configurator
Scenario: Ranking should go to ranking view
Given I am on the game menu
When I click on Ranking
Then I should be in the ranking
Scenario: View Historical Data should go to historical data
Given I am on the game menu
When I click on View Historical Data
Then I should be in the historical data
29 changes: 29 additions & 0 deletions webapp/e2e/features/questionGame.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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
Scenario: Create Customized Game should go to /questions
Given I am on the game configurator
When I click on new customized game
Then I am in /questions
Scenario: Create Customized Game of Capital questions
Given I am on the game configurator
When I click select Capital and I create a new customized game
Then I get Capital questions
Scenario: Create Customized Game of Language questions
Given I am on the game configurator
When I click select Language and I create a new customized game
Then I get Language questions
Scenario: Create Customized Game of Population questions
Given I am on the game configurator
When I click select Population and I create a new customized game
Then I get Population questions
Scenario: Create Customized Game of Size questions
Given I am on the game configurator
When I click select Size and I create a new customized game
Then I get Size questions
Scenario: Create Customized Game of Head of Goverment questions
Given I am on the game configurator
When I click select Head of Goverment and I create a new customized game
Then I get Head of Goverment questions
9 changes: 9 additions & 0 deletions webapp/e2e/features/revealAnswers.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Question View answers
Scenario: Create Competitive Game and reveal correct answer color
Given I am on the game configurator and create a competitive game
When I let the counter end
Then Correct Color appears
Scenario: Create Competitive Game and reveal wrong answer colors
Given I am on the game configurator and create a competitive game
When I let the counter end
Then Incorrect Color appears
24 changes: 24 additions & 0 deletions webapp/e2e/steps/gameMenu.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,29 @@ defineFeature(feature, test => {
await expect(page).toMatchElement('.GameConfiguratorDiv');
});
});
test('Ranking should go to ranking view', ({ given, when, then }) => {
given('I am on the game menu', async () => {
await page.goto('http://localhost:3000/menu');
await page.waitForSelector('.divMenu');
});
when('I click on Ranking', async () => {
await page.click('#ranking');
});
then('I should be in the ranking', async () => {
await expect(page).toMatchElement('.table');
});
});
test('View Historical Data should go to historical data', ({ given, when, then }) => {
given('I am on the game menu', async () => {
await page.goto('http://localhost:3000/menu');
await page.waitForSelector('.divMenu');
});
when('I click on View Historical Data', async () => {
await page.click('#historical');
});
then('I should be in the historical data', async () => {
await expect(page).toMatchElement('.globalHistoricalView');
});
});

});
150 changes: 150 additions & 0 deletions webapp/e2e/steps/questionGame.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature } = require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions;

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

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

let page;
let browser;

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

defineFeature(feature, test => {

beforeAll(async () => {
browser = await puppeteer.launch({
headless: "new",
slowMo: 20,
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');
});
});

test('Create Customized 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 customized game', async () => {
await page.click('.linkButton');
});
then('I am in /questions', async () => {
await expect(page).toMatchElement('.questionContainer');
});
});

test('Create Customized Game of Capital 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 select Capital and I create a new customized game', async () => {
await page.select('#select', 'CAPITAL');
await page.click('.linkButton');//click on capital
});
then('I get Capital questions', async () => {
//await expect(page).toMatchElement('.topPanel');
const questionContainer = await page.$('.topPanel');
const questionText = await page.evaluate(questionContainer => questionContainer.textContent, questionContainer);
const containsCapital = /Capital/i.test(questionText);
expect(containsCapital).toBe(true);
});
});

test('Create Customized Game of Language 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 select Language and I create a new customized game', async () => {
await page.select('#select', 'LANGUAGE');
await page.click('.linkButton');
});
then('I get Language questions', async () => {
//await expect(page).toMatchElement('.topPanel');
const questionContainer = await page.$('.topPanel');
const questionText = await page.evaluate(questionContainer => questionContainer.textContent, questionContainer);
const containsCapital = /Language/i.test(questionText);
expect(containsCapital).toBe(true);
});
});
test('Create Customized Game of Population 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 select Population and I create a new customized game', async () => {
await page.select('#select', 'POPULATION');
await page.click('.linkButton');
});
then('I get Population questions', async () => {
//await expect(page).toMatchElement('.topPanel');
const questionContainer = await page.$('.topPanel');
const questionText = await page.evaluate(questionContainer => questionContainer.textContent, questionContainer);
const containsCapital = /Population/i.test(questionText);
expect(containsCapital).toBe(true);
});
});
test('Create Customized Game of Size 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 select Size and I create a new customized game', async () => {
await page.select('#select', 'SIZE');
await page.click('.linkButton');
});
then('I get Size questions', async () => {
//await expect(page).toMatchElement('.topPanel');
const questionContainer = await page.$('.topPanel');
const questionText = await page.evaluate(questionContainer => questionContainer.textContent, questionContainer);
const containsCapital = /Size/i.test(questionText);
expect(containsCapital).toBe(true);
});
});
test('Create Customized Game of Head of Goverment 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 select Head of Goverment and I create a new customized game', async () => {
await page.select('#select', 'HEAD_OF_GOVERMENT');
await page.click('.linkButton');
});
then('I get Head of Goverment questions', async () => {
//await expect(page).toMatchElement('.topPanel');
const questionContainer = await page.$('.topPanel');
const questionText = await page.evaluate(questionContainer => questionContainer.textContent, questionContainer);
const containsCapital = /Head of Goverment/i.test(questionText);
expect(containsCapital).toBe(true);
});
});

});
Loading

0 comments on commit becbd1e

Please sign in to comment.