-
Notifications
You must be signed in to change notification settings - Fork 5
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
test: add tests for privacy-policy banner #1297
base: dev
Are you sure you want to change the base?
Conversation
WalkthroughWalkthroughThe changes involve the addition of unit tests for the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
✅ Deploy Preview for staging-dacade ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (2)
- tests/components/banner/PrivacyPolicy.test.tsx (1 hunks)
- src/components/banner/PrivacyPolicy.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
- src/components/banner/PrivacyPolicy.tsx
Additional comments not posted (4)
__tests__/components/banner/PrivacyPolicy.test.tsx (4)
1-4
: Setup and imports are appropriate for the test environment.The imports and mocks are correctly set up for testing the
PrivacyPolicyBanner
component. This setup ensures that the component's dependencies are appropriately isolated during testing.Also applies to: 8-19
21-24
: Good use of test structure and mock management.The
describe
block correctly organizes tests for thePrivacyPolicyBanner
, and the use ofbeforeEach
to clear mocks helps maintain clean test states.
26-32
: Test case correctly verifies component rendering.The test ensures that the
PrivacyPolicyBanner
is rendered when it is supposed to, based on the Redux state. This is a crucial check for the visibility condition of the banner.
34-42
: Test case effectively checks user interaction and UI update.This test appropriately simulates a user clicking the close button and verifies that the
PrivacyPolicyBanner
is no longer rendered, which is a key behavior of the component.
jest.mock("next-i18next", () => ({ | ||
useTranslation: () => ({ | ||
t: (key: string) => key === "signup-page.privacy" ? "Translated Privacy Policy" : key, | ||
}), | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since packages like this are usually tested, we don't need to mock them
it("should accept the cookies policy and not render PrivacyPolicy after the user clicks on the close button", () => { | ||
const { queryByTestId } = renderWithRedux(<PrivacyPolicyBanner />, { | ||
banner: { showCookiePolicy: false }, | ||
}); | ||
const closeButton = screen.getByTestId("closeButton"); | ||
expect(closeButton).toBeInTheDocument(); | ||
fireEvent.click(closeButton); | ||
expect(queryByTestId("PrivacyPolicy")).not.toBeInTheDocument(); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test case should be splitted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also specify whether this test is for the "privacy-page" banner or the "privacy-policy" page on the PR name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (1)
- tests/components/banner/PrivacyPolicy.test.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
- tests/components/banner/PrivacyPolicy.test.tsx
@@ -33,18 +33,18 @@ export default function PrivacyPolicyBanner(): ReactElement { | |||
|
|||
if (showBanner) | |||
return ( | |||
<div className="fixed bottom-0 left-0 right-0 z-999 flex flex-row justify-center md:justify-between bg-brand"> | |||
<div data-testid="PrivacyPolicy" className="fixed bottom-0 left-0 right-0 z-999 flex flex-row justify-center md:justify-between bg-brand"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make data-testid a prop
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should render PrivacyPolicy", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it("should render PrivacyPolicy", () => { | |
it("should render PrivacyPolicyBanner when showCookiePolicy is true", () => { |
@@ -0,0 +1,37 @@ | |||
import "@testing-library/jest-dom"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the test also for not rendering the banner when showCookiePolicy
is false
it("should render the close button", () => { | ||
const { getByTestId } = renderWithRedux(<PrivacyPolicyBanner />, { | ||
banner: { showCookiePolicy: false }, | ||
}); | ||
const closeButton = getByTestId("closeButton"); | ||
expect(closeButton).toBeInTheDocument(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add this test in should render PrivacyPolicyBanner when showCookiePolicy is true
, because it should test if the component is rendered with all the right elements
<div className="z-50 lg:h-8 h-7 lg:w-8 w-7 flex items-center text-white rounded-full lg:border-solid lg:border lg:border-white hover:bg-blue-700 bg-transparent cursor-pointer place-content-center"> | ||
<div className="flex absolute lg:relative lg:p-6 md:py-0 lg:justify-center right-0 top-0 lg:items-center items-center" onClick={onAcceptCookiesPolicy}> | ||
<div | ||
data-testid="closeButton" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the data-testid should be on the parent div, since it's the one that has an onClose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (3)
- tests/components/banner/PrivacyPolicy.test.tsx (1 hunks)
- jest.config.js (1 hunks)
- src/components/banner/PrivacyPolicy.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- tests/components/banner/PrivacyPolicy.test.tsx
- src/components/banner/PrivacyPolicy.tsx
Additional comments not posted (1)
jest.config.js (1)
31-31
: LGTM!The new mapping in the
moduleNameMapper
section is correctly added and enhances the module resolution capabilities of Jest.
Submit a pull request
Replace any ":question:" below with information about your pull request.
Pull Request Details
This PR adds a unity tests for the privacy policy banner
❓
Breaking Changes
Describe what features are broken by this pull request and why, if any.
#1107
Other Relevant Information
Provide any other important details below.