-
Notifications
You must be signed in to change notification settings - Fork 6
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
[DTRA-1047] henry/dtra-1047/feat: snackbar UI #56
Merged
Merged
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
701e0a7
feat: snackbar ui initial commit
henry-deriv 31f678c
fix: change height of canvas for better visibility
henry-deriv 0aaaca6
fix: revert package.json and package-lock.json
henry-deriv 8ae6155
fix: revert main.tsx to head of main branch
henry-deriv caa3c53
fix: revert main.tsx to head of main branch
henry-deriv 1cbc167
test: test cases
henry-deriv 1daa569
fix: re-add package and package-lock
henry-deriv 01e37d6
fix: revert main.tsx
henry-deriv 575b92d
fix: revert main.tsx
henry-deriv 41b941b
fix: merge main
henry-deriv 21964fb
Merge branch 'main' into henry/dtra-1047/snackbar-component
henry-deriv 9c55468
fix: comments
henry-deriv 6235344
test: add snapshot tests
henry-deriv 7b5432d
fix: remove package-lock
henry-deriv 7adc494
fix: make snackbar compatible with small screen size
henry-deriv b6135ce
fix: empty commit
henry-deriv 7b04ad1
fix: breakpoints mixin bug
henry-deriv 34b5fc7
fix: merge master
henry-deriv 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 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,43 @@ | ||
import { StandalonePlaceholderRegularIcon } from "@deriv/quill-icons/Standalone"; | ||
import { Snackbar } from "."; | ||
import React, { useState } from "react"; | ||
|
||
export const SnackbarWrapper = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const handleActionClick = () => { | ||
console.log("clicked"); | ||
henry-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
handleClose(); | ||
kate-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
const handleOpen = () => { | ||
setIsOpen(true); | ||
}; | ||
|
||
const handleClose = () => { | ||
setTimeout(() => { | ||
henry-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setIsOpen(false); | ||
}, 1000); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<button onClick={handleOpen} style={{ color: "white" }}> | ||
henry-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Click me | ||
</button> | ||
<Snackbar | ||
icon={ | ||
<StandalonePlaceholderRegularIcon | ||
fill="#ffffff" | ||
iconSize="sm" | ||
/> | ||
} | ||
message="Unable to upload selected photos. \n The app will retry in 5 seconds." | ||
henry-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
actionText="Action" | ||
onActionClick={handleActionClick} | ||
isOpen={isOpen} | ||
onClose={handleClose} | ||
/> | ||
</div> | ||
); | ||
}; |
178 changes: 178 additions & 0 deletions
178
lib/components/Snackbar/__tests__/__snapshots__/snackbar.test.tsx.snap
This file contains 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,178 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Snackbar calls onActionClick when action button is clicked 1`] = ` | ||
<div> | ||
<div | ||
class="snackbar fast-animation" | ||
> | ||
<div | ||
class="snackbar__message--container" | ||
> | ||
<p | ||
class="quill-typography__body-text__size--sm__weight--regular__decoration--default quill-typography__color--default snackbar__message" | ||
> | ||
Test message | ||
</p> | ||
</div> | ||
<button | ||
style="color: rgb(255, 255, 255); padding: 4px;" | ||
type="button" | ||
> | ||
Action | ||
</button> | ||
<button | ||
style="color: rgb(255, 255, 255); padding: 4px;" | ||
type="button" | ||
> | ||
x | ||
</button> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Snackbar calls onClose after a certain duration when Snackbar is open 1`] = ` | ||
<div> | ||
<div | ||
class="snackbar slow-animation" | ||
> | ||
<div | ||
class="snackbar__message--container" | ||
> | ||
<p | ||
class="quill-typography__body-text__size--sm__weight--regular__decoration--default quill-typography__color--default snackbar__message" | ||
> | ||
Test message | ||
</p> | ||
</div> | ||
<button | ||
style="color: rgb(255, 255, 255); padding: 4px;" | ||
type="button" | ||
> | ||
x | ||
</button> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Snackbar calls onClose when close button is clicked 1`] = ` | ||
<div> | ||
<div | ||
class="snackbar fast-animation" | ||
> | ||
<div | ||
class="snackbar__message--container" | ||
> | ||
<p | ||
class="quill-typography__body-text__size--sm__weight--regular__decoration--default quill-typography__color--default snackbar__message" | ||
> | ||
Test message | ||
</p> | ||
</div> | ||
<button | ||
style="color: rgb(255, 255, 255); padding: 4px;" | ||
type="button" | ||
> | ||
x | ||
</button> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Snackbar renders correctly with custom icon 1`] = ` | ||
<div> | ||
<div | ||
class="snackbar slow-animation" | ||
> | ||
<div | ||
class="snackbar__icon--container" | ||
> | ||
<img | ||
alt="Custom Icon" | ||
data-testid="custom-icon" | ||
src="custom-icon.svg" | ||
/> | ||
</div> | ||
<div | ||
class="snackbar__message--container" | ||
> | ||
<p | ||
class="quill-typography__body-text__size--sm__weight--regular__decoration--default quill-typography__color--default snackbar__message" | ||
> | ||
Test message | ||
</p> | ||
</div> | ||
<button | ||
style="color: rgb(255, 255, 255); padding: 4px;" | ||
type="button" | ||
> | ||
x | ||
</button> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Snackbar renders correctly without action button 1`] = ` | ||
<div> | ||
<div | ||
class="snackbar slow-animation" | ||
> | ||
<div | ||
class="snackbar__message--container" | ||
> | ||
<p | ||
class="quill-typography__body-text__size--sm__weight--regular__decoration--default quill-typography__color--default snackbar__message" | ||
> | ||
Test message | ||
</p> | ||
</div> | ||
<button | ||
style="color: rgb(255, 255, 255); padding: 4px;" | ||
type="button" | ||
> | ||
x | ||
</button> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Snackbar renders correctly without close button 1`] = ` | ||
<div> | ||
<div | ||
class="snackbar slow-animation" | ||
> | ||
<div | ||
class="snackbar__message--container" | ||
> | ||
<p | ||
class="quill-typography__body-text__size--sm__weight--regular__decoration--default quill-typography__color--default snackbar__message" | ||
> | ||
Test message | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Snackbar renders with default props 1`] = ` | ||
<div> | ||
<div | ||
class="snackbar slow-animation" | ||
> | ||
<div | ||
class="snackbar__message--container" | ||
> | ||
<p | ||
class="quill-typography__body-text__size--sm__weight--regular__decoration--default quill-typography__color--default snackbar__message" | ||
> | ||
Test message | ||
</p> | ||
</div> | ||
<button | ||
style="color: rgb(255, 255, 255); padding: 4px;" | ||
type="button" | ||
> | ||
x | ||
</button> | ||
</div> | ||
</div> | ||
`; |
This file contains 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,109 @@ | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import { Snackbar } from ".."; | ||
|
||
describe("Snackbar", () => { | ||
it("renders with default props", () => { | ||
const { container } = render( | ||
<Snackbar | ||
message="Test message" | ||
henry-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isOpen={true} | ||
onClose={jest.fn()} | ||
/>, | ||
); | ||
expect(screen.getByText("Test message")).toBeInTheDocument(); | ||
henry-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
it("calls onActionClick when action button is clicked", () => { | ||
const onActionClickMock = jest.fn(); | ||
const { container } = render( | ||
<Snackbar | ||
message="Test message" | ||
actionText="Action" | ||
isOpen={true} | ||
onActionClick={onActionClickMock} | ||
onClose={jest.fn()} | ||
/>, | ||
); | ||
|
||
fireEvent.click(screen.getByText("Action")); | ||
henry-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(onActionClickMock).toHaveBeenCalled(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
it("calls onClose when close button is clicked", () => { | ||
const onCloseMock = jest.fn(); | ||
const { container } = render( | ||
<Snackbar | ||
message="Test message" | ||
isOpen={true} | ||
onClose={onCloseMock} | ||
/>, | ||
); | ||
|
||
fireEvent.click(screen.getByText("x")); | ||
expect(onCloseMock).toHaveBeenCalled(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
it("calls onClose after a certain duration when Snackbar is open", async () => { | ||
jest.useFakeTimers(); | ||
|
||
const onCloseMock = jest.fn(); | ||
const { container } = render( | ||
<Snackbar | ||
message="Test message" | ||
isOpen={true} | ||
onClose={onCloseMock} | ||
/>, | ||
); | ||
|
||
jest.advanceTimersByTime(3000); | ||
expect(onCloseMock).toHaveBeenCalled(); | ||
expect(container).toMatchSnapshot(); | ||
|
||
jest.useRealTimers(); | ||
henry-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
it("renders correctly with custom icon", () => { | ||
const customIcon = ( | ||
<img | ||
src="custom-icon.svg" | ||
alt="Custom Icon" | ||
data-testid="custom-icon" | ||
/> | ||
); | ||
const { container } = render( | ||
<Snackbar | ||
icon={customIcon} | ||
message="Test message" | ||
isOpen={true} | ||
onClose={jest.fn()} | ||
/>, | ||
); | ||
|
||
expect(screen.getByTestId("custom-icon")).toBeInTheDocument(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
it("renders correctly without action button", () => { | ||
const { container } = render( | ||
<Snackbar | ||
message="Test message" | ||
isOpen={true} | ||
onClose={() => {}} | ||
/>, | ||
); | ||
|
||
expect(screen.queryByText("Action")).toBeNull(); | ||
henry-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
it("renders correctly without close button", () => { | ||
const { container } = render( | ||
<Snackbar | ||
message="Test message" | ||
isOpen={true} | ||
onClose={jest.fn()} | ||
hasCloseButton={false} | ||
/>, | ||
); | ||
|
||
expect(screen.queryByText("x")).toBeNull(); | ||
henry-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.
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.
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's weird but i couldn't find the place where this component is used..
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.
its just a wrapper to pass functions into the component to work for now. For the next task it'll be used.