Skip to content

Commit

Permalink
create endpoint in ReviewPage
Browse files Browse the repository at this point in the history
  • Loading branch information
nora-kauczor committed Nov 19, 2024
1 parent d06f846 commit d1a6062
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,23 @@ public static List<String> getCorrectAnswers(String word, Language language) {
String rightSideOfSlashWithoutArticle = getWordWithoutArticle(word, language);
String leftSideOfSlashWithEndingOfRightSide = getLeftSideOfSlashWithEndingOfRightSide(word);
String wordWithoutArticle = getWordWithoutArticle(word, language);
// without brackets but with brackets' content
String wordWithoutBrackets = getWordWithoutBrackets(word);
String wordWithoutArticleWithoutBrackets = getWordWithoutArticle(wordWithoutBrackets, language);
String wordWithoutBracketsRunTwice = getWordWithoutBrackets(wordWithoutBrackets);
// without brackets and without brackets' content
String wordWithoutBracketsRunTwiceWithoutArticle = getWordWithoutArticle(wordWithoutBracketsRunTwice, language);
String wordWithoutBracketsAndWithoutContent = getWordWithoutBracketsAndWithoutBracketsContent(word);
String wordWithoutArticleWithoutBracketsAndWithoutContent = getWordWithoutArticle(wordWithoutBracketsAndWithoutContent, language);
String wordWithoutBracketsAndWithoutContentRunTwice = getWordWithoutBracketsAndWithoutBracketsContent(wordWithoutBracketsAndWithoutContent);
String wordWithoutBracketsAndWithoutContentRunTwiceWithoutArticle = getWordWithoutArticle(wordWithoutBracketsAndWithoutContentRunTwice, language);
return List.of(
word,
leftSideOfSlash,
leftSideOfSlashWithoutArticle,
rightSideOfSlash,
rightSideOfSlashWithoutArticle,
leftSideOfSlashWithEndingOfRightSide,
//
wordWithoutArticle,
wordWithoutBrackets,
wordWithoutArticleWithoutBrackets,
wordWithoutBracketsRunTwiceWithoutArticle,
wordWithoutBracketsRunTwice,
wordWithoutBracketsAndWithoutContent,
wordWithoutArticleWithoutBracketsAndWithoutContent,
wordWithoutBracketsAndWithoutContentRunTwiceWithoutArticle,
wordWithoutBracketsAndWithoutContentRunTwice
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,30 @@

class CorrectAnswersTest {

// @Test
// void getCorrectAnswers_shouldReturnListOfCorrectAnswers_whenCalledWithWordAndLanguage(){
// String word = "un(e) professeur(e)";
// Language language = Language.FRENCH;
// String expected = List.of(word, word, word, word, word, word,
// "professeur(e)", )
// }
@Test
void getCorrectAnswers_shouldReturnListOfCorrectAnswers_whenCalledWithWordAndLanguage() {
String word = "un(e) professeur(e)";
Language language = Language.FRENCH;
List<String> expected = List.of(word, word, "professeur(e)", word, "professeur(e)", word,
"professeur(e)",
"professeure",
"une professeure",
"professeur",
"un professeur");
List<String> actual = CorrectAnswers.getCorrectAnswers(word, language);
assertEquals(expected, actual);
}

@Test
void getCorrectAnswers_shouldReturnListOfCorrectAnswers_whenCalledWithWordAndLanguage2() {
String word = "une table";
Language language = Language.FRENCH;
List<String> expected = List.of(word, word, "table", word, "table", word,
"table", "table",
word, "table", word);
List<String> actual = CorrectAnswers.getCorrectAnswers(word, language);
assertEquals(expected, actual);
}

@Test
void getLeftSideOfSlash_shouldReturnBeau_whenCalledWithBeauBelle() {
Expand Down Expand Up @@ -67,7 +84,7 @@ void getLeftSideOfSlashWithEndingOfRightSide_shouldReturnBeauBelle_whenCalledWit

@Test
void
getWordWithoutArticle_shouldReturnSueno_whenCalledWithElSuenoAndSpanish(){
getWordWithoutArticle_shouldReturnSueno_whenCalledWithElSuenoAndSpanish() {
String word = "el sueño";
String expected = "sueño";
String actual = CorrectAnswers.getWordWithoutArticle(word, Language.SPANISH);
Expand All @@ -77,39 +94,39 @@ void getLeftSideOfSlashWithEndingOfRightSide_shouldReturnBeauBelle_whenCalledWit

@Test
void
getWordWithoutArticle_shouldReturnProfesseure_whenCalledWithUneProfesseure(){
getWordWithoutArticle_shouldReturnProfesseure_whenCalledWithUneProfesseure() {
String word = "un(e) professeur(e)";
String expected = "professeur(e)";
String actual = CorrectAnswers.getWordWithoutArticle(word, Language.SPANISH);
assertEquals(expected, actual);
}

@Test
void getWordWithoutBrackets_shouldReturnContente_whenCalledWithContente(){
void getWordWithoutBrackets_shouldReturnContente_whenCalledWithContente() {
String word = "content(e)";
String expected = "contente";
String actual = CorrectAnswers.getWordWithoutBrackets(word);
assertEquals(expected, actual);
}

@Test
void getWordWithoutBrackets_shouldReturnLaLiberte_whenCalledWithLaLiberte(){
void getWordWithoutBrackets_shouldReturnLaLiberte_whenCalledWithLaLiberte() {
String word = "la liberté";
String expected = "la liberté";
String actual = CorrectAnswers.getWordWithoutBrackets(word);
assertEquals(expected, actual);
}

@Test
void getWordWithoutBracketsAndWithoutBracketsContent_shouldReturnContent_whenCalledWithContente(){
void getWordWithoutBracketsAndWithoutBracketsContent_shouldReturnContent_whenCalledWithContente() {
String word = "content(e)";
String expected = "content";
String actual = CorrectAnswers.getWordWithoutBracketsAndWithoutBracketsContent(word);
assertEquals(expected, actual);
}

@Test
void getWordWithoutBracketsAndWithoutBracketsContent_shouldReturnLaLiberte_whenCalledWithLaLiberte(){
void getWordWithoutBracketsAndWithoutBracketsContent_shouldReturnLaLiberte_whenCalledWithLaLiberte() {
String word = "la liberté";
String expected = "la liberté";
String actual = CorrectAnswers.getWordWithoutBracketsAndWithoutBracketsContent(word);
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function App() {
const [displayNewVocabsPopUp, setDisplayNewVocabsPopUp] = useState(false)
const navigate = useNavigate()

console.log(vocabsToReview)

useEffect(() => {
getUserId()
Expand Down Expand Up @@ -95,7 +94,6 @@ function App() {
response.data.idsOfVocabsToReview)
.filter(innerArray => innerArray[1] === false)
.map(innerArray => innerArray[0]);
console.log(response.data)
if (vocabs.length < 1) {
console.error(
"Couldn't get vocabs to review because vocabs was empty.");
Expand All @@ -120,9 +118,7 @@ function App() {
axios.put(`/api/review/${id}?language=${language}`)
.then(() => {
console.log(`Vocab with ID ${id} was marked as reviewed for today.`)
// setTimeout(() => {
getVocabsToReview()
// }, 10000);
})
.catch(error => {
console.error(error)
Expand Down
27 changes: 15 additions & 12 deletions frontend/src/pages/ReviewPage/ReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import CardContainer from "../../components/CardContainer/CardContainer.tsx";
import {Vocab} from "../../types/Vocab.ts";
import {useNavigate} from "react-router-dom";
import Confetti from 'react-confetti';
import {
getInputWithoutExtraSpaces
} from "./utils/getInputWithoutExtraSpaces.ts";
import {getRightAnswers} from "./utils/getRightAnswer.ts";
import {toast} from "react-toastify";
import 'react-toastify/dist/ReactToastify.css';
import axios from "axios";
Expand Down Expand Up @@ -51,19 +47,26 @@ export default function ReviewPage(props: Readonly<Props>) {
}
}

function checkAnswer(id: string, userInput: string): boolean {
let isAnswerCorrect = false;
axios.get(`/api/check/${id}?answer=${userInput}`)
.then(response => isAnswerCorrect = response.data)
.catch(error => console.error(error))
return isAnswerCorrect;
async function checkAnswer(id: string, userInput: string): Promise<boolean | undefined> {
const inputWithCodedSpaces = userInput.replace(/ /g, "%20")
try
{
const response = await axios.get(
`/api/check/${id}?answer=${inputWithCodedSpaces}`)
return response.data;
} catch (error) {
console.error(error)
return undefined;
}
}

function handleClickShowAnswer() {
async function handleClickShowAnswer() {
if (!currentVocab || !currentVocab.id) {
return
}
const answerCorrect:boolean = checkAnswer(currentVocab?.id, userInput);
const answerCorrect: boolean | undefined = await checkAnswer(
currentVocab?.id, userInput);
if (answerCorrect === undefined) {return}
if (answerCorrect) {
setDisplayAnswer(true)
setShowFireworks(true)
Expand Down

0 comments on commit d1a6062

Please sign in to comment.