generated from RealDevSquad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 7
new feature notifications in UI completed with styling and tests #53
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
Open
ivinayakg
wants to merge
9
commits into
RealDevSquad:develop
Choose a base branch
from
ivinayakg:feature/notifications-ui
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ab3cdad
new feature notifications in UI completed with styling and tests succ…
ivinayakg 3bd6e47
styling of the feature now migrated to tailwind CSS from CSS modules
ivinayakg 65243a9
changes requested by @harshith-venkatesh are done
ivinayakg cc5d4d3
new changes, refactoring.
ivinayakg 522a1e2
notification component migrated to Context API, test cases are remaining
ivinayakg cf1fd1a
default value in context added, test cases updated
ivinayakg 4213a19
changes done as suggested with new test cases added
ivinayakg f56dd04
Requested Changes are done
ivinayakg cb18b87
requested changes done
ivinayakg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,32 @@ | ||
| import { NOTIFICATION_TEXT_COLOR } from "../../Constant/constant"; | ||
| import { useNotificationContext } from "../../Context/NotificationContext"; | ||
|
|
||
| const NotificationContainer = () => { | ||
| const { notificationQueue } = useNotificationContext(); | ||
|
|
||
| return ( | ||
| <div | ||
| data-testid="notificationcontainer" | ||
| className="flex justify-center items-center flex-col-reverse fixed top-4 w-max gap-2 transition-[height] duration-300 ease-[cubic-bezier(0.165, 0.84, 0.44, 1)]" | ||
| //this piece of code will increase or decrease the height of the wrapper accr to the no. of notifications present | ||
| style={{ height: `${notificationQueue.length * 2.5}rem` }} | ||
| > | ||
| {notificationQueue.map((notification, index) => ( | ||
| <div | ||
ivinayakg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| key={index} | ||
| data-testid="notificationchild" | ||
| className="flex justify-start items-center min-w-full w-max bg-white font-['Helvetica', 'sans-serif'] font-medium text-base capitalize rounded px-2.5 py-1.5" | ||
| style={{ | ||
| backgroundColor: `${ | ||
| NOTIFICATION_TEXT_COLOR[notification.type.toUpperCase()] | ||
| }`, | ||
| }} | ||
ivinayakg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| > | ||
| <h3 role={"alert"}>{notification.message}</h3> | ||
| </div> | ||
ivinayakg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ))} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default NotificationContainer; | ||
This file contains hidden or 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,13 @@ | ||
| export const FOOTER = { | ||
| "COPYRIGHT": "Copyright 2022-2023", | ||
| "RDS_WEBSITE": "RDS Website", | ||
| "DISCORD_SERVER":"Discord server" | ||
| } | ||
| COPYRIGHT: "Copyright 2022-2023", | ||
ivinayakg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| RDS_WEBSITE: "RDS Website", | ||
| DISCORD_SERVER: "Discord server", | ||
| }; | ||
|
|
||
| export const NOTIFICATION_TEXT_COLOR = { | ||
| SUCCESS: "rgb(95, 214, 95)", | ||
| WARNING: "rgb(238, 241, 41)", | ||
| ERROR: "rgb(253, 81, 81)", | ||
| }; | ||
|
|
||
| export const NOTIFICATION_TIMEOUT = 2000; | ||
ivinayakg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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,38 @@ | ||
| import { createContext, useContext, useState } from "react"; | ||
| import { NOTIFICATION_TIMEOUT } from "../Constant/constant"; | ||
|
|
||
| export const NotificationContext = createContext({ | ||
| createNotifcation() {}, | ||
| notificationQueue: [], | ||
| }); | ||
|
|
||
| export const useNotificationContext = () => useContext(NotificationContext); | ||
|
|
||
| const NotificationProvider = ({ children }) => { | ||
| const [notificationQueue, setNotificationQueue] = useState([]); | ||
|
|
||
| /** | ||
| * | ||
| * @param {type : string, message : string} notificationContent | ||
| */ | ||
| const createNotifcation = (notificationContent) => { | ||
| setNotificationQueue((prev) => [...prev, notificationContent]); | ||
|
|
||
| setTimeout(() => { | ||
| setNotificationQueue((prev) => { | ||
| let [, ...data] = prev; | ||
| return data; | ||
| }); | ||
| }, NOTIFICATION_TIMEOUT); | ||
| }; | ||
|
|
||
| return ( | ||
| <NotificationContext.Provider | ||
| value={{ createNotifcation, notificationQueue }} | ||
| > | ||
| {children} | ||
| </NotificationContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| export default NotificationProvider; |
This file contains hidden or 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 hidden or 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,82 @@ | ||
| import { render, screen, waitFor } from "@testing-library/react"; | ||
| import "@testing-library/jest-dom"; | ||
|
|
||
| import NotificationContainer from "../Components/notification"; | ||
| import { | ||
| NOTIFICATION_TIMEOUT, | ||
| NOTIFICATION_TEXT_COLOR, | ||
| } from "../Constant/constant"; | ||
| import { NotificationContext } from "../Context/NotificationContext"; | ||
| import React from "react"; | ||
|
|
||
| const customRender = (ui, { value, ...options }) => | ||
| render( | ||
| <NotificationContext.Provider value={value}> | ||
| {ui} | ||
| </NotificationContext.Provider>, | ||
| options | ||
| ); | ||
|
|
||
| let notificationContent = { message: "Hello World", type: "success" }; | ||
|
|
||
| let mockNotificationContext = {}; | ||
|
|
||
| beforeEach(() => { | ||
| mockNotificationContext = { | ||
| notificationQueue: [], | ||
| createNotifcation(data) { | ||
| this.notificationQueue = [data, ...this.notificationQueue]; | ||
|
|
||
| setTimeout(() => { | ||
| let [, ...data] = this.notificationQueue; | ||
| this.notificationQueue = data; | ||
| }, NOTIFICATION_TIMEOUT); | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| mockNotificationContext = {}; | ||
| }); | ||
|
|
||
| describe("Notification Component", () => { | ||
| it("should check if the notification wrapper renders", async () => { | ||
| render(<NotificationContainer />); | ||
| expect(screen.getByTestId("notificationcontainer")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("should check the function cycle of the notification component", async () => { | ||
| mockNotificationContext.createNotifcation(notificationContent); | ||
| customRender(<NotificationContainer />, { value: mockNotificationContext }); | ||
|
|
||
| let notificationChild = await waitFor(() => | ||
| screen.getByTestId("notificationchild") | ||
| ); | ||
|
|
||
| expect(notificationChild).toHaveTextContent(notificationContent.message); | ||
| }); | ||
|
|
||
| it("should check if the color rendered is the same one as passed", async () => { | ||
| mockNotificationContext.createNotifcation(notificationContent); | ||
| customRender(<NotificationContainer />, { value: mockNotificationContext }); | ||
|
|
||
| let notificationChild = await waitFor(() => | ||
| screen.getByTestId("notificationchild") | ||
| ); | ||
| expect(notificationChild.style.backgroundColor).toEqual( | ||
ivinayakg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| NOTIFICATION_TEXT_COLOR[notificationContent.type.toUpperCase()] | ||
ivinayakg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| }); | ||
| it("should check if the heading rendered as h3", async () => { | ||
| mockNotificationContext.createNotifcation(notificationContent); | ||
| customRender(<NotificationContainer />, { value: mockNotificationContext }); | ||
|
|
||
| let notificationChild = await waitFor(() => | ||
| screen.getByTestId("notificationchild") | ||
| ); | ||
| expect(screen.getByRole("alert").nodeName).toEqual('H3') | ||
| expect(screen.getByRole("alert")).toHaveTextContent( | ||
| notificationContent.message | ||
| ); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.