Skip to content

Commit

Permalink
Merge pull request #35 from Arquisoft/develop-QuestionGenerator
Browse files Browse the repository at this point in the history
Prototype 1.1
  • Loading branch information
alexfdzs authored Mar 11, 2024
2 parents 4a4a9b3 + 2b24f2a commit 5ed16c4
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 23 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- run: npm --prefix questionsgenerator test -- --coverage
- run: npm --prefix historial test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ jobs:
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- run: npm --prefix questionsgenerator test -- --coverage
- run: npm --prefix historial test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
6 changes: 3 additions & 3 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function App() {


<Container component="main" maxWidth="xs">

<CssBaseline />
{showLogin ? <Login /> : <AddUser />}
<Typography component="div" align="center" sx={{ marginTop: 2 }}>
Expand All @@ -33,6 +34,7 @@ function App() {
)}

</Typography>

</Container>
);
}
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/components/GetQuestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const GetQuestion = () => {
{index + 1}.
</Typography>
<Button
data-testid={`answer${index}Button`}
variant="contained"
sx={{ backgroundColor: 'dimgrey', fontWeight: 'bold', '&:hover': { backgroundColor: 'black' }}}
key={index}
Expand All @@ -181,6 +182,7 @@ const GetQuestion = () => {
<div>
{/* Button to request a new question It will be disabled when the question is not answered */}
<Button
data-testid="nextQuestionButton"
variant="contained"
style={{ width: '100%', fontWeight: 'bold' }}
onClick={getQuestion}
Expand Down
69 changes: 57 additions & 12 deletions webapp/src/components/GetQuestion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,81 @@ const mockAxios = new MockAdapter(axios);
describe('GetQuestion component', () => {
beforeEach(() => {
mockAxios.reset();
});

it('should show the question', async () => {
mockAxios.onPost('http://localhost:8000/getQuestion').reply(200, {
question: 'Test question',
correctAnswerLabel: 'Test correct answer',
answerLabelSet: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test answer 4']
answerLabelSet: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer']
});


mockAxios.onPost('http://localhost:8000/saveHistorial').reply(200, {
});
});

it('Should render question and answer buttons', async () => {
render(
<Router>
<Question />
</Router>);


// Esperar a que la pregunta aparezca en el documento
// Wait for the question to appear in the document
await waitFor(() => screen.getByText('Test question'));


// Comprobar que hay 5 botones, 4 de las respuestas y 1 del next question
// Check that there are 5 buttons, 4 for the answers and 1 for the next question
const buttons = await screen.findAllByRole('button');
expect(buttons.length).toBe(5);
expect(buttons.length).toBe(7);

// Comprobar que la pregunta y las respuestas están en la pantalla
// Check that the question and answers are on the screen
expect(screen.getByText('Test question')).toBeInTheDocument();
expect(screen.getByText('Test answer 1')).toBeInTheDocument();
expect(screen.getByText('Test answer 2')).toBeInTheDocument();
expect(screen.getByText('Test answer 3')).toBeInTheDocument();
expect(screen.getByText('Test answer 4')).toBeInTheDocument();
expect(screen.getByText('Test correct answer')).toBeInTheDocument();
});

it('Should play and guess the correct answer', async () => {
render(
<Router>
<Question />
</Router>);

// Wait for the question to appear in the document
await waitFor(() => screen.getByText('Test question'));

// Click the correct answer
fireEvent.click(screen.getByText('Test correct answer'));

// Wait for feedback to be rendered
await waitFor(() => expect(screen.getByText('You have won! Congratulations!')).toBeInTheDocument());
});

it('Should play and select an incorrect answer', async () => {
render(
<Router>
<Question />
</Router>);

// Wait for the question to appear in the document
await waitFor(() => screen.getByText('Test question'));

// Click the correct answer
fireEvent.click(screen.getByText('Test answer 1'));

// Wait for feedback to be rendered
await waitFor(() => expect(screen.getByText('You lost! Try again :(')).toBeInTheDocument());
});

});
/*
jest.mock('axios');
beforeEach(() => {
axios.post.mockResolvedValue({
data: {
question: 'What is the capital of France?',
correctAnswerLabel: 'Paris',
answerLabelSet: ['Paris', 'London', 'Madrid', 'Lisbon']
}
});
});
expect(screen.getByTestId('answer0Button')).toBeInTheDocument();
*/
4 changes: 0 additions & 4 deletions webapp/src/components/Record.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ const Record = () => {
navigate("/home", {state: {username}});
};

/*const llamaHistorial = () => {
getHistorialForLoggedUser();
}*/

useEffect(() => {
getHistorialForLoggedUser();
}, []);
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/components/Record.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('Record component', () => {
<Record />
</Router>);

await waitFor(() => screen.getByText(/Here you can see your record! All about your past games and all!/i));

const linkElement = screen.getByText(/Here you can see your record! All about your past games and all!/i);
expect(linkElement).toBeInTheDocument();

Expand Down

0 comments on commit 5ed16c4

Please sign in to comment.