From ad8981311e07ea3165f968756962d689da75a95d Mon Sep 17 00:00:00 2001 From: Pedro Limeres <113518495+plg22@users.noreply.github.com> Date: Sat, 27 Apr 2024 19:25:33 +0200 Subject: [PATCH 1/5] Non used classes deleted --- webapp/src/components/Game/Trivia/Dice.tsx | 31 ----- webapp/src/components/ui/alert-dialog.tsx | 139 --------------------- webapp/src/components/ui/popover.tsx | 26 ---- 3 files changed, 196 deletions(-) delete mode 100644 webapp/src/components/Game/Trivia/Dice.tsx delete mode 100644 webapp/src/components/ui/alert-dialog.tsx delete mode 100644 webapp/src/components/ui/popover.tsx diff --git a/webapp/src/components/Game/Trivia/Dice.tsx b/webapp/src/components/Game/Trivia/Dice.tsx deleted file mode 100644 index 7a3e69d..0000000 --- a/webapp/src/components/Game/Trivia/Dice.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import React, { useEffect, useRef } from 'react' -import ReactDice, { ReactDiceRef } from 'react-dice-complete' - -type props = { - setDiceResult: (diceResult: number) => void -} - - -export const Dice = (props:props) => { - - const reactDice = useRef(null) - - - function rollDone(num: number) : void { - props.setDiceResult(num) - } - - - - return ( - - ) -} \ No newline at end of file diff --git a/webapp/src/components/ui/alert-dialog.tsx b/webapp/src/components/ui/alert-dialog.tsx deleted file mode 100644 index 0aca662..0000000 --- a/webapp/src/components/ui/alert-dialog.tsx +++ /dev/null @@ -1,139 +0,0 @@ -import * as React from "react" -import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog" - -import { cn } from "../../lib/utils" -import { buttonVariants } from "./button" - -const AlertDialog = AlertDialogPrimitive.Root - -const AlertDialogTrigger = AlertDialogPrimitive.Trigger - -const AlertDialogPortal = AlertDialogPrimitive.Portal - -const AlertDialogOverlay = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) -AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName - -const AlertDialogContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - - - - -)) -AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName - -const AlertDialogHeader = ({ - className, - ...props -}: React.HTMLAttributes) => ( -
-) -AlertDialogHeader.displayName = "AlertDialogHeader" - -const AlertDialogFooter = ({ - className, - ...props -}: React.HTMLAttributes) => ( -
-) -AlertDialogFooter.displayName = "AlertDialogFooter" - -const AlertDialogTitle = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) -AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName - -const AlertDialogDescription = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) -AlertDialogDescription.displayName = - AlertDialogPrimitive.Description.displayName - -const AlertDialogAction = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) -AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName - -const AlertDialogCancel = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) -AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName - -export { - AlertDialog, - AlertDialogPortal, - AlertDialogOverlay, - AlertDialogTrigger, - AlertDialogContent, - AlertDialogHeader, - AlertDialogFooter, - AlertDialogTitle, - AlertDialogDescription, - AlertDialogAction, - AlertDialogCancel, -} diff --git a/webapp/src/components/ui/popover.tsx b/webapp/src/components/ui/popover.tsx deleted file mode 100644 index b2cd9a6..0000000 --- a/webapp/src/components/ui/popover.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import * as React from "react" -import * as PopoverPrimitive from "@radix-ui/react-popover" - -import { cn } from "../../lib/utils" - -const Popover = PopoverPrimitive.Root - -const PopoverTrigger = PopoverPrimitive.Trigger - -const PopoverContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( - - - -)) -PopoverContent.displayName = PopoverPrimitive.Content.displayName - -export { Popover, PopoverTrigger, PopoverContent } From fb706b8a3eb2466dfa88e6cac367f6a4a8129fa0 Mon Sep 17 00:00:00 2001 From: Pedro Limeres <113518495+plg22@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:20:37 +0200 Subject: [PATCH 2/5] Two more tests --- .../components/Game/Trivia/categories.test.ts | 30 +++++++++++++ .../Game/Trivia/trivia_service.test.js | 42 +++++++++++++++++++ .../components/Game/Trivia/trivia_service.ts | 29 ++++++------- 3 files changed, 85 insertions(+), 16 deletions(-) create mode 100644 webapp/src/components/Game/Trivia/categories.test.ts create mode 100644 webapp/src/components/Game/Trivia/trivia_service.test.js diff --git a/webapp/src/components/Game/Trivia/categories.test.ts b/webapp/src/components/Game/Trivia/categories.test.ts new file mode 100644 index 0000000..60a27fe --- /dev/null +++ b/webapp/src/components/Game/Trivia/categories.test.ts @@ -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(); + }); +}); \ No newline at end of file diff --git a/webapp/src/components/Game/Trivia/trivia_service.test.js b/webapp/src/components/Game/Trivia/trivia_service.test.js new file mode 100644 index 0000000..f5b9136 --- /dev/null +++ b/webapp/src/components/Game/Trivia/trivia_service.test.js @@ -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?"); + }); +}); \ No newline at end of file diff --git a/webapp/src/components/Game/Trivia/trivia_service.ts b/webapp/src/components/Game/Trivia/trivia_service.ts index 1841236..4b98fc1 100644 --- a/webapp/src/components/Game/Trivia/trivia_service.ts +++ b/webapp/src/components/Game/Trivia/trivia_service.ts @@ -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 => { - 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 => { - 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 => { - 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 => { - 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 => { - 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]; } From 3df2ec19a246c5a4ad3eb62e4661701155788cff Mon Sep 17 00:00:00 2001 From: Pedro Limeres <113518495+plg22@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:28:58 +0200 Subject: [PATCH 3/5] Change sonar props --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 00b11ca..1783e45 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -10,7 +10,7 @@ sonar.host.url=https://sonarcloud.io sonar.language=js sonar.projectName=wiq_en3a -sonar.coverage.exclusions=**/*.test.js +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/** From f8cf8f2c3f5b2ea70c3c13a9de7db8a2865454ba Mon Sep 17 00:00:00 2001 From: Pedro Limeres <113518495+plg22@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:30:00 +0200 Subject: [PATCH 4/5] Delete empty class --- webapp/src/stores/playing-store copy.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 webapp/src/stores/playing-store copy.ts diff --git a/webapp/src/stores/playing-store copy.ts b/webapp/src/stores/playing-store copy.ts deleted file mode 100644 index e69de29..0000000 From a22c7d5960dcbb1cfe8689cfaee69480f5181fc6 Mon Sep 17 00:00:00 2001 From: Pedro Limeres <113518495+plg22@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:40:10 +0200 Subject: [PATCH 5/5] MInor fix in statistics e2e --- webapp/e2e/steps/statistics.steps.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webapp/e2e/steps/statistics.steps.js b/webapp/e2e/steps/statistics.steps.js index 531305c..c2e3e8f 100644 --- a/webapp/e2e/steps/statistics.steps.js +++ b/webapp/e2e/steps/statistics.steps.js @@ -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: "test4@gmail.com" }); }); })