Skip to content

Commit

Permalink
Merge pull request #67 from Ruben14789/main
Browse files Browse the repository at this point in the history
Adds Test cases for QuestPage
  • Loading branch information
Ruben14789 authored Mar 31, 2024
2 parents 42e2aa6 + c78a48e commit 0e23a83
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"react-test-renderer": "^18.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
Expand Down
5 changes: 2 additions & 3 deletions app/src/components/BackButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ const BackButton = ({ backButtonPosition }) => {
}, [backButtonPosition]);

return (
<a href="/home">
<button
className={styles.backButton}
id="back_button"
style={backButtonStyle}
onClick={() => { window.location.href = "/home"; }} // Navigate on button click, back to home?
>
<img className={styles.groupIcon} alt="" src="/group.svg" />
</button>
</a>
);
};

export default BackButton;
export default BackButton;
61 changes: 61 additions & 0 deletions app/src/tests/QuestPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';
import { render, fireEvent, } from '@testing-library/react';
import QuestsPage from '../pages/quests/QuestsPage';
import '@testing-library/jest-dom/extend-expect';
import renderer from 'react-test-renderer';

// Mocking the FontSize
jest.mock('../contexts/FontSizeContext', () => ({
useFontSize: () => ({
fontSize: 16, // Set a default font size for testing purposes
darkMode: false, // Set a default dark mode value for testing purposes
}),
}));

describe('QuestsPage', () => {
it('renders without crashing', () => {
const component = renderer.create(
<QuestsPage />
);
// Check if initial sections are rendered
});

it('adds quest to in-progress when start quest button is clicked', () => {
const { getAllByText, getByText } = render(<QuestsPage />);
// Click the start quest button for the first available quest
fireEvent.click(getAllByText('Start Quest')[0]);

// Check if the quest is added to in-progress quests section
expect(getByText('In Progress Quests')).toBeInTheDocument();
expect(getByText('Quest 1')).toBeInTheDocument(); // checking for 'Quest 1'
});

it('moves quest from in-progress to completed when complete quest button is clicked', () => {
const { getAllByText, queryByText } = render(<QuestsPage />);

fireEvent.click(getAllByText('Start Quest')[0]);
fireEvent.click(getAllByText('Complete Quest')[0]);



});

it('toggles visibility of completed quests when button is clicked', () => {
const { getByText, queryByText } = render(<QuestsPage />);

// Initially, completed quests section should not be visible
expect(queryByText('Completed Quests')).toBeNull();

// Click the button to toggle visibility of completed quests
fireEvent.click(getByText('Show Completed Quests'));

// Now, completed quests section should be visible
expect(getByText('Completed Quests')).toBeInTheDocument();

// Click the button again to hide completed quests
fireEvent.click(getByText('Hide Completed Quests'));

// Now, completed quests section should not be visible again
expect(queryByText('Completed Quests')).toBeNull();
});
});

0 comments on commit 0e23a83

Please sign in to comment.