generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into improve-responsiveness
- Loading branch information
Showing
11 changed files
with
288 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM grafana/grafana | ||
|
||
# Copying the provisioning files | ||
COPY ./provisioning /etc/grafana/provisioning | ||
|
||
# Exposing Grafana server port | ||
EXPOSE 9091 | ||
|
||
# Running Grafana server | ||
CMD [ "grafana-server" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM prom/prometheus | ||
|
||
# Copying the configuration file | ||
COPY prometheus.yml /etc/prometheus/prometheus.yml | ||
|
||
# Exposing Prometheus server port | ||
EXPOSE 9090 | ||
|
||
# Running Prometheus | ||
ENTRYPOINT [ "prometheus", "--config.file=/etc/prometheus/prometheus.yml" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = { | ||
testMatch: ["**/steps/*.js"], | ||
testTimeout: 30000, | ||
setupFilesAfterEnv: ["expect-puppeteer"] | ||
setupFilesAfterEnv: ["expect-puppeteer"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen, waitFor } from '@testing-library/react'; | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import GameMultiPlayer from './GameMultiPlayer'; | ||
|
||
const mockAxios = new MockAdapter(axios); | ||
|
||
describe('Multiplayer Lobby component', () => { | ||
|
||
beforeEach(() => { | ||
mockAxios.reset(); | ||
}); | ||
|
||
it('user creates a party', async () => { | ||
|
||
const mockResponse = { data: [ | ||
{ | ||
uuid: '1', | ||
question: '56*54-3', | ||
correctAnswer: '3021', | ||
incorrectAnswer1: '3000', | ||
incorrectAnswer2: '3022', | ||
incorrectAnswer3: '3031', | ||
} | ||
] }; | ||
mockAxios.onPost('http://localhost:8000/createGame/en').reply(200, mockResponse); | ||
|
||
// Mock local storage | ||
Object.defineProperty(window, 'localStorage', { value: { | ||
getItem: jest.fn((key) => { | ||
return key === 'username' ? 'userForTest' : key === 'score' ? '0' : key === 'uuid' ? '2222' : null; | ||
}), | ||
} }); | ||
|
||
const multiplayer = render( | ||
<GameMultiPlayer/> | ||
); | ||
// Wait for the Snackbar to be open | ||
await waitFor(() => { | ||
expect(screen.getByTestId("menu-multiplayer")).toBeInTheDocument(); | ||
}); | ||
|
||
|
||
fireEvent.click(screen.getByTestId("multiplayer-create-party-button")); | ||
|
||
expect(screen.getByTestId("lobby-multiplayer")).toBeInTheDocument(); | ||
}); | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
webapp/src/components/game/multiplayer/LobbyMultiplayer.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen, waitFor } from '@testing-library/react'; | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import LobbyMultiPlayer from './LobbyMultiPlayer'; | ||
|
||
// Mock Axios | ||
const mockAxios = new MockAdapter(axios); | ||
|
||
describe('LobbyMultiPlayer component', () => { | ||
// Mock props | ||
const mockProps = { | ||
socket: { emit: jest.fn() }, | ||
handleCurrentStage: jest.fn(), | ||
partyCode: '123456', | ||
users: [{ uuid: '1', username: 'user1', totalPoints: 0, isAdmin: true }], | ||
}; | ||
|
||
beforeEach(() => { | ||
mockAxios.reset(); | ||
}); | ||
|
||
it('renders lobby with correct elements', async () => { | ||
const {getAllByTestId} = render(<LobbyMultiPlayer {...mockProps} />); | ||
|
||
// Ensure player items are rendered | ||
|
||
const players = getAllByTestId("player-item"); | ||
|
||
// Check if there is one player | ||
expect(players.length).toBeGreaterThan(0); | ||
|
||
}); | ||
|
||
it('clicking exit lobby button calls handleCurrentStage', async () => { | ||
render(<LobbyMultiPlayer {...mockProps} />); | ||
|
||
fireEvent.click(screen.getByTestId("exit-lobby-button")); | ||
|
||
expect(mockProps.handleCurrentStage).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
it('clicking start game button emits updateQuestions event', async () => { | ||
const mockResponse = { data: [ | ||
{ | ||
uuid: '1', | ||
question: '56*54-3', | ||
correctAnswer: '3021', | ||
incorrectAnswer1: '3000', | ||
incorrectAnswer2: '3022', | ||
incorrectAnswer3: '3031', | ||
} | ||
] }; | ||
mockAxios.onPost('http://localhost:8000/createGame/en').reply(200, mockResponse); | ||
Object.defineProperty(window, 'localStorage', { value: { | ||
getItem: jest.fn((key) => { | ||
return key === 'uuid' ? "1" : key === 'lang' ? "en" : null; | ||
}), | ||
} }); | ||
|
||
render(<LobbyMultiPlayer {...mockProps} />); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId("start-game-button")).toBeInTheDocument(); | ||
}); | ||
|
||
fireEvent.click(screen.getByTestId("start-game-button")); | ||
|
||
await waitFor(() => { | ||
expect(mockProps.socket.emit).toHaveBeenCalledWith('updateQuestions', '123456', expect.any(Object)); | ||
}); | ||
}); | ||
|
||
}); |
46 changes: 46 additions & 0 deletions
46
webapp/src/components/game/multiplayer/MenuMultiplayer.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen, waitFor } from '@testing-library/react'; | ||
import MenuMultiplayer from './MenuMultiplayer'; | ||
|
||
describe('MenuMultiplayer component', () => { | ||
// Mock props | ||
const mockProps = { | ||
socket: { emit: jest.fn() }, | ||
handleCurrentStage: jest.fn(), | ||
handlePartyCode: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
localStorage.clear(); | ||
}); | ||
|
||
it('renders menu with correct elements', () => { | ||
render(<MenuMultiplayer {...mockProps} />); | ||
|
||
// Ensure header and buttons are rendered | ||
expect(screen.getByTestId("title-menu-multiplayer")).toBeInTheDocument(); | ||
expect(screen.getByTestId("multiplayer-create-party-button")).toBeInTheDocument(); | ||
expect(screen.getByTestId("multiplayer-join-party-code")).toBeInTheDocument(); | ||
expect(screen.getByTestId("multiplayer-join-party-button" )).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls createParty function when create party button is clicked', () => { | ||
render(<MenuMultiplayer {...mockProps} />); | ||
|
||
fireEvent.click(screen.getByTestId('multiplayer-create-party-button')); | ||
|
||
expect(mockProps.handleCurrentStage).toHaveBeenCalledWith(2); | ||
expect(mockProps.socket.emit).toHaveBeenCalledWith('createParty', expect.any(Object)); | ||
}); | ||
|
||
it('calls joinParty function with typed code when join party button is clicked', () => { | ||
render(<MenuMultiplayer {...mockProps} />); | ||
|
||
fireEvent.change(screen.getByTestId('multiplayer-join-party-code'), { target: { value: '123456' } }); | ||
fireEvent.click(screen.getByTestId('multiplayer-join-party-button')); | ||
|
||
expect(mockProps.handlePartyCode).toHaveBeenCalledWith('123456'); | ||
expect(mockProps.socket.emit).toHaveBeenCalledWith('joinParty', '123456', expect.any(Object)); | ||
}); | ||
}); |
Oops, something went wrong.