-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fuselage-toastbar): Add RTL support (#1389)
Co-authored-by: Júlia Jaeger Foresti <[email protected]> Co-authored-by: Tasso Evangelista <[email protected]>
- Loading branch information
1 parent
2bf5b18
commit 8c80efc
Showing
6 changed files
with
226 additions
and
71 deletions.
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,5 @@ | ||
--- | ||
"@rocket.chat/fuselage-toastbar": minor | ||
--- | ||
|
||
feat(fuselage-toastbar): Add RTL support |
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
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 |
---|---|---|
@@ -1,12 +1,65 @@ | ||
import { composeStories } from '@storybook/testing-react'; | ||
import { render } from '@testing-library/react'; | ||
import { render, getByRole, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import * as stories from './stories'; | ||
import * as stories from './ToastBar.stories'; | ||
import ToastBarProvider from './ToastBarProvider'; | ||
|
||
const { ToastBarWithData } = composeStories(stories); | ||
const { Default, TopEnd } = composeStories(stories, { | ||
decorators: [ | ||
(Story) => ( | ||
<ToastBarProvider> | ||
<Story /> | ||
</ToastBarProvider> | ||
), | ||
], | ||
}); | ||
|
||
const topEndStyle = { | ||
top: '0', | ||
right: '0', | ||
}; | ||
|
||
const topStartStyle = { | ||
top: '0', | ||
left: '0', | ||
}; | ||
|
||
describe('[fuselage-toastbar rendering]', () => { | ||
test('should display ToastBar on the top right of the screen by default', async () => { | ||
render(<TopEnd />); | ||
const toast = screen.queryByRole('alert'); | ||
const toastContainer = toast?.parentElement?.parentElement?.parentElement; | ||
|
||
expect(toastContainer).toHaveStyle(topEndStyle); | ||
}); | ||
|
||
test('should display ToastBar on the top right of the screen', async () => { | ||
document.body.setAttribute('dir', 'ltr'); | ||
render(<TopEnd />); | ||
const toast = screen.queryByRole('alert'); | ||
const toastContainer = toast?.parentElement?.parentElement?.parentElement; | ||
|
||
expect(toastContainer).toHaveStyle(topEndStyle); | ||
}); | ||
|
||
test('should display ToastBar on the top left of the screen', async () => { | ||
document.body.setAttribute('dir', 'rtl'); | ||
render(<TopEnd />); | ||
const toast = screen.queryByRole('alert'); | ||
const toastContainer = toast?.parentElement?.parentElement?.parentElement; | ||
|
||
expect(toastContainer).toHaveStyle(topStartStyle); | ||
}); | ||
}); | ||
|
||
describe('[fuselage-toastbar interacting]', () => { | ||
test('should dispatch the ToastBar on click', async () => { | ||
const { container } = render(<Default />); | ||
const button = getByRole(container, 'button'); | ||
|
||
describe('[ToastBarWithData Component]', () => { | ||
it('renders without crashing', () => { | ||
render(<ToastBarWithData />); | ||
userEvent.click(button); | ||
const toasts = screen.queryAllByRole('alert'); | ||
toasts.forEach((toast) => expect(toast).toBeInTheDocument()); | ||
}); | ||
}); |
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,137 @@ | ||
import { Button } from '@rocket.chat/fuselage'; | ||
import type { Meta, Story } from '@storybook/react'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { useToastBarDispatch } from './ToastBarContext'; | ||
|
||
export default { | ||
title: 'view/ToastBar', | ||
parameters: { | ||
layout: 'centered', | ||
actions: { argTypesRegex: '^on.*' }, | ||
}, | ||
} as Meta; | ||
|
||
const DEFAULT_MESSAGE = 'Lorem Ipsum'; | ||
|
||
export const Default: Story = () => { | ||
const [counter, setCounter] = useState(0); | ||
const dispatchToastMessage = useToastBarDispatch(); | ||
|
||
const messageArray = [ | ||
'Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ipsam nihi Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ipsam nihi', | ||
'Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ipsam nihi Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ipsam nihi', | ||
'Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ipsam nihi Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ipsam nihi', | ||
DEFAULT_MESSAGE, | ||
'Lorem ipsum dolor, sit amet consectetur adipisicing elit.', | ||
]; | ||
|
||
const handleToast = () => { | ||
dispatchToastMessage({ | ||
type: 'success', | ||
message: messageArray[counter], | ||
}); | ||
|
||
dispatchToastMessage({ | ||
type: 'error', | ||
message: messageArray[counter], | ||
time: 10, | ||
position: 'bottom-start', | ||
}); | ||
|
||
if (counter === messageArray.length - 1) { | ||
return setCounter(0); | ||
} | ||
|
||
return setCounter((prevState) => prevState + 1); | ||
}; | ||
|
||
return ( | ||
<Button primary onClick={handleToast}> | ||
Dispatch ToastBar | ||
</Button> | ||
); | ||
}; | ||
|
||
export const TopStart: Story = () => { | ||
const dispatchToastMessage = useToastBarDispatch(); | ||
|
||
const handleDispatch = () => | ||
dispatchToastMessage({ | ||
type: 'success', | ||
message: DEFAULT_MESSAGE, | ||
position: 'top-start', | ||
}); | ||
|
||
useEffect(() => { | ||
handleDispatch(); | ||
}, []); | ||
|
||
return ( | ||
<Button primary onClick={handleDispatch}> | ||
Dispatch ToastBar | ||
</Button> | ||
); | ||
}; | ||
|
||
export const TopEnd: Story = () => { | ||
const dispatchToastMessage = useToastBarDispatch(); | ||
|
||
const handleDispatch = () => | ||
dispatchToastMessage({ | ||
type: 'success', | ||
message: DEFAULT_MESSAGE, | ||
}); | ||
|
||
useEffect(() => { | ||
handleDispatch(); | ||
}, []); | ||
|
||
return ( | ||
<Button primary onClick={handleDispatch}> | ||
Dispatch ToastBar | ||
</Button> | ||
); | ||
}; | ||
|
||
export const BottomStart: Story = () => { | ||
const dispatchToastMessage = useToastBarDispatch(); | ||
|
||
const handleDispatch = () => | ||
dispatchToastMessage({ | ||
type: 'success', | ||
message: DEFAULT_MESSAGE, | ||
position: 'bottom-start', | ||
}); | ||
|
||
useEffect(() => { | ||
handleDispatch(); | ||
}, []); | ||
|
||
return ( | ||
<Button primary onClick={handleDispatch}> | ||
Dispatch ToastBar | ||
</Button> | ||
); | ||
}; | ||
|
||
export const BottomEnd: Story = () => { | ||
const dispatchToastMessage = useToastBarDispatch(); | ||
|
||
const handleDispatch = () => | ||
dispatchToastMessage({ | ||
type: 'success', | ||
message: DEFAULT_MESSAGE, | ||
position: 'bottom-end', | ||
}); | ||
|
||
useEffect(() => { | ||
handleDispatch(); | ||
}, []); | ||
|
||
return ( | ||
<Button primary onClick={handleDispatch}> | ||
Dispatch ToastBar | ||
</Button> | ||
); | ||
}; |
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
This file was deleted.
Oops, something went wrong.