-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test(utils): increase test coverage * stories: increase coverage * test(util): increase * test: providers * tests: hooks * chore(docs): small change about test * stories: add "effects" * stories: increase component tested * stories: add `LinkTabs` * test: next-data * chore(COLLABORATOR_GUIDE): apply review * Fix: typo "Github" -> "GitHub" Co-authored-by: Claudio W <[email protected]> Signed-off-by: Augustin Mauroy <[email protected]> * clean: story of `Event` * remove useless comment * test: use mock on `getBitness` * test: fix * test(util): increase * test(hooks): increase * fix: typo * refracto: `useBottomScrollListener.test.mjs` * re-add this test * fix ci ? * please ci * fix import * ci will work ? * fix ? * fix(docs) * fix: rebase --------- Signed-off-by: Augustin Mauroy <[email protected]> Signed-off-by: Claudio W <[email protected]> Co-authored-by: Claudio W <[email protected]>
- Loading branch information
1 parent
cf31daf
commit c3f9c12
Showing
36 changed files
with
821 additions
and
49 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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
||
import LinkTabs from '@/components/Common/LinkTabs'; | ||
|
||
type Story = StoryObj<typeof LinkTabs>; | ||
type Meta = MetaObj<typeof LinkTabs>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
label: 'Select Tab', | ||
tabs: [ | ||
{ | ||
key: 'package', | ||
label: 'Package Manager', | ||
link: '/package-manager', | ||
}, | ||
{ | ||
key: 'prebuilt', | ||
label: 'Prebuilt Installer', | ||
link: '/prebuilt-installer', | ||
}, | ||
{ | ||
key: 'source', | ||
label: 'Source Code', | ||
link: '/source-code', | ||
}, | ||
], | ||
activeTab: 'prebuilt', | ||
children: <p>Tab content goes here</p>, | ||
}, | ||
}; | ||
|
||
export default { component: LinkTabs } as Meta; |
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,10 @@ | ||
import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
||
import Ellipsis from '@/components/Common/Pagination/Ellipsis'; | ||
|
||
type Story = StoryObj<typeof Ellipsis>; | ||
type Meta = MetaObj<typeof Ellipsis>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export default { component: Ellipsis } as Meta; |
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
40 changes: 40 additions & 0 deletions
40
components/Common/Pagination/PaginationListItem/index.stories.tsx
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,40 @@ | ||
import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
||
import PaginationListItem from '@/components/Common/Pagination/PaginationListItem'; | ||
|
||
type Story = StoryObj<typeof PaginationListItem>; | ||
type Meta = MetaObj<typeof PaginationListItem>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
url: '#', | ||
pageNumber: 1, | ||
currentPage: 2, | ||
totalPages: 2, | ||
}, | ||
decorators: [ | ||
Story => ( | ||
<ul className="list-none"> | ||
<Story /> | ||
</ul> | ||
), | ||
], | ||
}; | ||
|
||
export const CurrentPage: Story = { | ||
args: { | ||
url: '#', | ||
pageNumber: 1, | ||
currentPage: 1, | ||
totalPages: 1, | ||
}, | ||
decorators: [ | ||
Story => ( | ||
<ul className="list-none"> | ||
<Story /> | ||
</ul> | ||
), | ||
], | ||
}; | ||
|
||
export default { component: PaginationListItem } as Meta; |
36 changes: 36 additions & 0 deletions
36
components/Containers/Sidebar/SidebarGroup/index.stories.tsx
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,36 @@ | ||
import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
||
import SidebarGroup from '@/components/Containers/Sidebar/SidebarGroup'; | ||
|
||
type Story = StoryObj<typeof SidebarGroup>; | ||
type Meta = MetaObj<typeof SidebarGroup>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
groupName: 'Example Group', | ||
items: [ | ||
{ label: 'Item 1', link: '/item1' }, | ||
{ label: 'Item 2', link: '/item2' }, | ||
{ label: 'Item 3', link: '/item3' }, | ||
], | ||
}, | ||
}; | ||
|
||
export const CustomGroup: Story = { | ||
args: { | ||
groupName: 'Custom Group', | ||
items: [ | ||
{ label: 'Custom Item 1', link: '/custom-item1' }, | ||
{ label: 'Custom Item 2', link: '/custom-item2' }, | ||
], | ||
}, | ||
}; | ||
|
||
export const EmptyGroup: Story = { | ||
args: { | ||
groupName: 'Empty Group', | ||
items: [], | ||
}, | ||
}; | ||
|
||
export default { component: SidebarGroup } as Meta; |
15 changes: 15 additions & 0 deletions
15
components/Containers/Sidebar/SidebarItem/index.stories.tsx
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,15 @@ | ||
import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
||
import SidebarItem from '@/components/Containers/Sidebar/SidebarItem'; | ||
|
||
type Story = StoryObj<typeof SidebarItem>; | ||
type Meta = MetaObj<typeof SidebarItem>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
label: 'Example Item', | ||
link: '/example', | ||
}, | ||
}; | ||
|
||
export default { component: SidebarItem } as Meta; |
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,30 @@ | ||
import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
||
import DownloadButton from '@/components/Downloads/DownloadButton'; | ||
|
||
type Story = StoryObj<typeof DownloadButton>; | ||
type Meta = MetaObj<typeof DownloadButton>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
release: { | ||
currentStart: '2023-04-18', | ||
ltsStart: '2023-10-24', | ||
maintenanceStart: '2024-10-22', | ||
endOfLife: '2026-04-30', | ||
status: 'Active LTS', | ||
major: 20, | ||
version: '20.11.0', | ||
versionWithPrefix: 'v20.11.0', | ||
codename: 'Iron', | ||
isLts: true, | ||
npm: '10.2.4', | ||
v8: '11.3.244.8', | ||
releaseDate: '2024-01-09', | ||
modules: '115', | ||
}, | ||
children: 'Download Node.js', | ||
}, | ||
}; | ||
|
||
export default { component: DownloadButton } as Meta; |
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,18 @@ | ||
import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
||
import Event from '@/components/MDX/Calendar/Event'; | ||
|
||
type Story = StoryObj<typeof Event>; | ||
type Meta = MetaObj<typeof Event>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
start: { date: '2024-02-19T12:30:00.000Z' }, | ||
end: { date: '2024-02-19T16:00:00.000Z' }, | ||
summary: 'Example Event', | ||
location: 'Event Location', | ||
description: 'This is an example event description.', | ||
}, | ||
}; | ||
|
||
export default { component: Event } as Meta; |
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,11 @@ | ||
import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
||
export const GlowingBackdrop: StoryObj = { | ||
render: () => <div className="glowingBackdrop" />, | ||
}; | ||
|
||
export const H1Special: StoryObj = { | ||
render: () => <h1 className="special">Special H1</h1>, | ||
}; | ||
|
||
export default { title: 'Design System' } as MetaObj; |
38 changes: 38 additions & 0 deletions
38
hooks/react-client/__tests__/useBottomScrollListener.test.mjs
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,38 @@ | ||
import { fireEvent, renderHook } from '@testing-library/react'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import useBottomScrollListener from '@/hooks/react-client/useBottomScrollListener'; | ||
|
||
describe('useBottomScrollListener', () => { | ||
it('should call the callback when the scroll reaches the bottom', () => { | ||
const callback = jest.fn(); | ||
renderHook(() => useBottomScrollListener(callback)); | ||
|
||
act(() => { | ||
fireEvent.scroll(window, { | ||
target: { scrollY: 100, innerHeight: 200, scrollHeight: 200 }, | ||
}); | ||
}); | ||
|
||
// timout is needed because the callback is called in the next tick | ||
setTimeout(() => { | ||
expect(callback).toHaveBeenCalled(); | ||
}, 1); | ||
}); | ||
|
||
it('should not call the callback when the scroll does not reach the bottom', () => { | ||
const callback = jest.fn(); | ||
renderHook(() => useBottomScrollListener(callback)); | ||
|
||
act(() => { | ||
fireEvent.scroll(window, { | ||
target: { scrollY: 100, innerHeight: 200, scrollHeight: 300 }, | ||
}); | ||
}); | ||
|
||
// timout is needed because the callback is called in the next tick | ||
setTimeout(() => { | ||
expect(callback).not.toHaveBeenCalled(); | ||
}, 1); | ||
}); | ||
}); |
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,45 @@ | ||
import { renderHook, act } from '@testing-library/react'; | ||
|
||
import useClickOutside from '@/hooks/react-client/useClickOutside'; | ||
|
||
describe('useClickOutside', () => { | ||
it('should call the callback function when clicked outside the element', () => { | ||
const fn = jest.fn(); | ||
const { rerender } = renderHook(() => | ||
useClickOutside({ current: null }, fn) | ||
); | ||
|
||
const mockEvent = new MouseEvent('click', { bubbles: true }); | ||
const mockElement = document.createElement('div'); | ||
|
||
rerender({ current: mockElement }, fn); | ||
|
||
act(() => { | ||
document.dispatchEvent(mockEvent); | ||
}); | ||
|
||
setTimeout(() => { | ||
expect(fn).toHaveBeenCalledTimes(1); | ||
}, 1); | ||
}); | ||
|
||
it('should not call the callback function when clicked inside the element', () => { | ||
const fn = jest.fn(); | ||
const { rerender } = renderHook(() => | ||
useClickOutside({ current: null }, fn) | ||
); | ||
|
||
const mockEvent = new MouseEvent('click', { bubbles: true }); | ||
const mockElement = document.createElement('div'); | ||
const mockChildElement = document.createElement('button'); | ||
mockElement.appendChild(mockChildElement); | ||
|
||
rerender({ current: mockElement }, fn); | ||
|
||
act(() => { | ||
mockChildElement.dispatchEvent(mockEvent); | ||
}); | ||
|
||
expect(fn).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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,26 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
|
||
import useClientContext from '@/hooks/react-client/useClientContext'; | ||
import { MatterContext } from '@/providers/matterProvider'; | ||
|
||
describe('useClientContext', () => { | ||
it('should return client context values', () => { | ||
const mockContextValue = { | ||
pathname: '/example-path', | ||
frontmatter: { title: 'Example Title', date: '2024-02-17' }, | ||
headings: ['Heading 1', 'Heading 2'], | ||
readingTime: 5, | ||
filename: 'example.md', | ||
}; | ||
|
||
const wrapper = ({ children }) => ( | ||
<MatterContext.Provider value={mockContextValue}> | ||
{children} | ||
</MatterContext.Provider> | ||
); | ||
|
||
const { result } = renderHook(() => useClientContext(), { wrapper }); | ||
|
||
expect(result.current).toEqual(mockContextValue); | ||
}); | ||
}); |
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
Oops, something went wrong.