Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

562 2 tests #563

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

562 2 tests #563

wants to merge 5 commits into from

Conversation

el-riber
Copy link
Contributor

@el-riber el-riber commented Nov 21, 2024

This is a pull request!

Subject: Test Implementation for FormPage Component

Test Goals for FormPage:

The goal of these tests was to verify the functionality and behavior of the FormPage component, ensuring a smooth and reliable user experience. The following objectives were targeted:

Rendering Validation:

Confirm that all essential elements of the form (e.g., input fields for Name, Gender, Email, Size, and the Submit button) render correctly and are visible to the user.
User Interaction Testing:

Simulate user input into all form fields to ensure that data is captured correctly.
Validate that the form submission works as expected by checking if the submitted data is logged correctly in the console (mocked for the test).
These tests help ensure that the FormPage works as intended and provides a solid foundation for further development or enhancements.

Let me know if you need further details or improvements!

test:
npm test form-page.test.tsx

Subject: Test Goals for EditUserRolePage Component

Objective: The purpose of the tests for the EditUserRolePage component is to ensure its core functionality works as intended and that different user roles are handled correctly. This includes testing the behavior of the page for admin users and non-admin users, as well as verifying the data flow and error handling.

Test Goals:

Admin User Access:

Verify that admin users can access the EditUserRolePage.
Ensure the UserCard components are correctly displayed with user data fetched from the API.
Non-Admin User Restriction:

Ensure that non-admin users see an UnauthorizedPageMessage and cannot access the admin functionality.
Data Fetching:

Mock the API response to confirm that the user data is fetched and displayed correctly.
Test how the component handles errors or missing tokens during the data-fetching process.
Error Handling:

Ensure the page gracefully handles missing or invalid tokens by rendering the appropriate error message.
Component Integration:

Verify the integration of child components like UserCard and UnauthorizedPageMessage using mocks.

npm test edit-user-role-page.test.tsx

Screenshot (35)
Screenshot (39)

ps: We implemented unit tests for two untested pages: FormPage and EditUserRolePage. The tests focused on ensuring key functionalities worked as expected. For FormPage, we tested the rendering of form fields, handling of user inputs, and form submission behavior. For EditUserRolePage, we tested role-based access control, verifying that admin users could view and interact with user data while non-admin users were shown an unauthorized message. Challenges included resolving path alias issues for mocking components, which required updates to tsconfig.json and jest.config.js. Dynamic routing in EditUserRolePage also posed difficulties, which we addressed by mocking API calls and router behavior. Despite these challenges, the tests were successfully implemented and verified through a detailed pull request, ensuring the functionality of these pages is now well-covered.

@el-riber el-riber linked an issue Nov 21, 2024 that may be closed by this pull request
2 tasks
@SeattleColleges SeattleColleges deleted a comment from socket-security bot Nov 21, 2024
@el-riber
Copy link
Contributor Author

Screenshot (41)
Screenshot (42)
As you can see, the problem that github presents appeared to me, but I fixed it. On my computer it is working perfectly, so if you have any tips I will accept them. Maybe I had to change some dependency. All the changes made I put comments in the code. I have nothing to fix on my computer because it is working for me.
Screenshot (35)
Screenshot (39)

Copy link
Contributor

@Asfand00 Asfand00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @el-riber, I assume this is the QA testing, I tested your branch and came across the mock error at first in your edit-user-role-page.test.tsx file like you encountered as well but that error is happening because both of your test.tsx files are at the root level like in this image:
belindas-2tests-files

then your edit-user-role-page.test.tsx file would look like this with the proper fix:
belindas-2tests-corrections

then my test will pass as so:
belindas-2tests-test-pass

You should put these files in the test/unit directory like in the first image and follow the format, also I'm not sure why there's two form-page.test.tsx files. they're both the same file so I think you should delete the one at the root level and keep the one in the test directory. You should put the edit-user-role-page.test.tsx file under the test directory too and follow the format for the other files (by putting each test.tsx file in their own directory).

once you make these changes you may have to double check the edit-user-role-page.test.tsx file again and correct those two lines again (in the second image) with the proper import format though if you didn't change them then it should be fine.

I will approve once these changes are made, thanks for the work @el-riber

Copy link

socket-security bot commented Nov 25, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] network +6 721 kB jefflau

View full report↗︎

Copy link
Contributor

@miqo1385 miqo1385 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this pull request in my end by running "npm test form-page.test.tsx", and all test passed.

Screenshot 2024-11-30 at 1 24 56 PM

@IsaacJrTypes
Copy link
Contributor

Good job on utilizing mocks in these tests. I will approve once Ozzie's changes have been addressed. Great catch! @Asfand00

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.

2 tests
5 participants