Skip to content

Redux#4

Open
EmelyanovSI wants to merge 51 commits intotests-contextfrom
redux
Open

Redux#4
EmelyanovSI wants to merge 51 commits intotests-contextfrom
redux

Conversation

@EmelyanovSI
Copy link
Copy Markdown
Owner

@EmelyanovSI EmelyanovSI commented Nov 18, 2023

  1. Task
  2. Screenshot:
    image
    image
  3. Deploy
  4. Done 19.11.2023 / deadline 20.11.2023
  5. Score: 100 / 100
  • Redux is integrated to the app with the help of Redux Toolkit - 25 points
  • Search is saved in the store - 5 points
  • Items per page is saved in the store - 5 points
  • View mode is saved in the store - 10 points
  • Loading indicators are shown, loading flags are saved in the store, - 10 points
  • When either search or items per page is changed, application makes a new call using RTK Query to fetch the data - 25 points
  • Tests had been modified to test the functionality using Redux and RTK Query - 20 points

The useAppParams hook is added to the hooks directory. It imports the AppParams type from the '@/types' module and the useParams hook from 'react-router-dom'. This hook is used to retrieve the parameters from the URL.

The useAppSearchParams hook is also added to the hooks directory. It imports the setLimit, setSearch, useAppDispatch, and useAppSelector functions from the '@/redux' module, as well as the useEffect and useSearchParams hooks from 'react' and 'react-router-dom' respectively. This hook is used to manage the search and limit parameters in the application state based on the URL search parameters. It listens for changes in the search and limit values and dispatches actions to update the state accordingly. The updated search and limit values are returned from the hook.
…o handle pagination and search functionality in animal API
… function

The functions `getSearchFromStorage` and `setSearchFromStorage` were removed as they were not being used in the codebase.

The `getOriginalPath` function was simplified and renamed to `generateAppPath`. It now accepts an optional `AppParams` object as a parameter and generates a path based on the provided `page` and `details` values. The function uses the `generatePath` function from `react-router-dom` to generate the path.
The animal.ts file was deleted as it was no longer being used in the project. This commit removes the file from the codebase to improve code cleanliness and reduce unnecessary files.
The Checkbox component is a reusable component that allows users to select or deselect an option. It takes in the following props:
- `label`: a string representing the label of the checkbox
- `checked`: a boolean indicating whether the checkbox is checked or not
- `onChange`: a callback function that is called when the checkbox is toggled

The component renders a label element with a checkbox input and a label text. The appearance of the checkbox changes based on its checked state. When the checkbox is clicked, the `onChange` callback is called with the updated checked state.
…e application

The Status enum is added to represent different statuses in the application. It includes the following values: Idle, Pending, Fulfilled, and Rejected. This enum will be used to track the status of various operations in the application.
The Checkbox component was missing unit tests. This commit adds unit tests for the Checkbox component to ensure that it renders correctly with the default state and handles checkbox change correctly.
This commit adds tests for the MainPage component. The tests cover the following scenarios:

1. Renders empty CardList component:
   - Mocks the useAppParams and useOutletContext hooks to return the necessary values.
   - Renders the MainPage component wrapped in a MemoryRouter.
   - Asserts that the listbox element and the "Not found." text are present.

2. Renders the CardList component and calls navigate on card click:
   - Mocks the useAppParams and useOutletContext hooks to return the necessary values.
   - Renders the MainPage component wrapped in a MemoryRouter.
   - Asserts that the card element is present.
   - Simulates a click event on the card element.
   - Asserts that the navigate function is called with the correct pathname.

3. Calls navigate on CardList wrapper click:
   - Mocks the useAppParams and useOutletContext hooks to return the necessary values.
   - Renders the MainPage component wrapped in a MemoryRouter.
   - Asserts that the wrapper element is present.
   - Simulates a click event on the wrapper element.
   - Asserts that the navigate function is called with the correct pathname and relative options.
- Add unit tests to ensure that the DetailsLayout component renders without crashing.
- Add unit tests to ensure that the close button click event is handled correctly.
@EmelyanovSI EmelyanovSI self-assigned this Nov 18, 2023
@netlify
Copy link
Copy Markdown

netlify bot commented Nov 18, 2023

Deploy Preview for emelyanovsi-redux ready!

Name Link
🔨 Latest commit 49072d7
🔍 Latest deploy log https://app.netlify.com/sites/emelyanovsi-redux/deploys/655960b6ee9fe40008936f3c
😎 Deploy Preview https://deploy-preview-4--emelyanovsi-redux.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

- Import necessary modules and libraries for testing
- Add cleanup function to clean up after each test
- Add beforeAll function to start the mock server and handle unhandled requests as errors
- Add afterEach function to reset the mock server handlers and reset the API state in the Redux store
- Add afterAll function to close the mock server after all tests are done
- Added a new file `handlers.ts` to define mock handlers for animal API requests.
- Created a mock page object and a mock animal object to use in the response.
- Defined a mock response object `mockRes` with the mock page, animal, and sort data.
- Exported an array of mock handlers in `handlers.ts` to be used by the mock server.
- Added a new file `index.ts` to export the mock server and handlers.
- Created a new file `server.ts` to set up the mock server using `msw/node` and the exported mock handlers.
@EmelyanovSI EmelyanovSI changed the base branch from main to tests-context November 30, 2023 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant