Skip to content

Commit

Permalink
Merge pull request #234 from Arquisoft/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
angelmaciasr authored Apr 27, 2024
2 parents 645e629 + 096235d commit ca7ca9e
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 214 deletions.
3 changes: 2 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ sonar.host.url=https://sonarcloud.io
sonar.language=js
sonar.projectName=wiq_en3a

sonar.coverage.exclusions=**/*.test.js, **/*.test.tsx

sonar.coverage.exclusions=**/*.test.js, **/*.test.ts, **/*.test.tsx
sonar.sources=webapp/src/components,users,wikidataservice,gatewayservice
sonar.sourceEncoding=UTF-8
sonar.exclusions=node_modules/**
Expand Down
3 changes: 2 additions & 1 deletion webapp/e2e/steps/statistics.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ defineFeature(feature, test => {
});

then('The app shows the statistics page', async () => {
await expect(page).toMatchElement("#statsHeader", { text: "Statistics page" });
await expect(page).toMatchElement(".h1-statistics", { text: "test4" });
await expect(page).toMatchElement(".h2-statistics", { text: "[email protected]" });
});
})

Expand Down
31 changes: 0 additions & 31 deletions webapp/src/components/Game/Trivia/Dice.tsx

This file was deleted.

30 changes: 30 additions & 0 deletions webapp/src/components/Game/Trivia/categories.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { getCategoryWithNumber, getCategoryColor, getCategoryColorWithNumber } from './categories';

describe('Test Category Functions', () => {
test('getCategoryWithNumber should return correct category', () => {
expect(getCategoryWithNumber(1)).toBe('Sports');
expect(getCategoryWithNumber(2)).toBe('Science');
});

test('getCategoryWithNumber should return undefined for non-existent number', () => {
expect(getCategoryWithNumber(6)).toBeUndefined();
});

test('getCategoryColor should return correct color', () => {
expect(getCategoryColor('Sports')).toBe('#1f71b3');
expect(getCategoryColor('Science')).toBe('#61a33a');
});

test('getCategoryColor should return undefined for non-existent category', () => {
expect(getCategoryColor('Math')).toBeUndefined();
});

test('getCategoryColorWithNumber should return correct color for a number', () => {
expect(getCategoryColorWithNumber(1)).toBe('#1f71b3');
expect(getCategoryColorWithNumber(2)).toBe('#61a33a');
});

test('getCategoryColorWithNumber should return undefined for non-existent number', () => {
expect(getCategoryColorWithNumber(6)).toBeUndefined();
});
});
42 changes: 42 additions & 0 deletions webapp/src/components/Game/Trivia/trivia_service.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const axios = require('axios');
import {expect, jest, test} from '@jest/globals';

import {
getSportQuestions,
getScienceQuestions,
getHistoryQuestions,
getGeographyQuestions,
getEntertainmentQuestions
} from './trivia_service';

jest.mock('axios', () => {
return {
get: () => {return {data: [{
"text": "What is the capital of France?",
"answers": ["London", "Berlin", "Paris", "Madrid"],
"correctAnswer": 2
}] }}}})

describe('Test Question Functions', () => {

test('getSportQuestions should return a question', async () => {
const question = await getSportQuestions();
expect(question.text).toBe("What is the capital of France?");
});
test('getSportQuestions should return a question', async () => {
const question = await getScienceQuestions();
expect(question.text).toBe("What is the capital of France?");
});
test('getSportQuestions should return a question', async () => {
const question = await getHistoryQuestions();
expect(question.text).toBe("What is the capital of France?");
});
test('getSportQuestions should return a question', async () => {
const question = await getGeographyQuestions();
expect(question.text).toBe("What is the capital of France?");
});
test('getSportQuestions should return a question', async () => {
const question = await getEntertainmentQuestions();
expect(question.text).toBe("What is the capital of France?");
});
});
29 changes: 13 additions & 16 deletions webapp/src/components/Game/Trivia/trivia_service.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
import { Question } from "@/src/services/question-service";
import axios from 'axios';

let url = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';



const getString = (string : string) : string => {
return "/Get" + string + "Questions";
}

export const getSportQuestions = async (): Promise<Question> => {
const response = await fetch(url + getString("Sport"));
const data = await response.json();
console.log(data);
return data[0];
const response = await axios.get(url + getString("Sport"));
return response.data[0];
};

export const getScienceQuestions = async (): Promise<Question> => {
const response = await fetch(url + getString("Chemistry"));
const data = await response.json();
return data[0];
const response = await axios.get(url + getString("Chemistry"));
return response.data[0];
};

export const getHistoryQuestions = async (): Promise<Question> => {
const response = await fetch(url + getString("History"));
const data = await response.json();
return data[0];
const response = await axios.get(url + getString("History"));
return response.data[0];
};

export const getGeographyQuestions = async (): Promise<Question> => {
const response = await fetch(url + getString("Geography"));
const data = await response.json();
return data[0];
const response = await axios.get(url + getString("Geography"));
return response.data[0];
};

export const getEntertainmentQuestions = async (): Promise<Question> => {
const response = await fetch(url + getString("Entertainment"));
const data = await response.json();
return data[0];
const response = await axios.get(url + getString("Entertainment"));
return response.data[0];
}


Expand Down
139 changes: 0 additions & 139 deletions webapp/src/components/ui/alert-dialog.tsx

This file was deleted.

26 changes: 0 additions & 26 deletions webapp/src/components/ui/popover.tsx

This file was deleted.

Empty file.

0 comments on commit ca7ca9e

Please sign in to comment.