Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pagebakers committed Nov 18, 2023
1 parent 6ac8c54 commit 5af8914
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 99 deletions.
104 changes: 8 additions & 96 deletions packages/saas-ui-core/src/navbar/navbar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import * as React from 'react'
import { act, render } from '@testing-library/react'
import { render, testStories } from '@saas-ui/test-utils'

import {
Navbar,
NavbarBrand,
NavbarItem,
NavbarContent,
NavbarMenuToggle,
NavbarMenu,
NavbarMenuItem,
} from './index'
import { Navbar, NavbarBrand, NavbarItem, NavbarContent } from './index'

import * as stories from './navbar.stories'

testStories<typeof stories>(stories)

describe('Navbar', () => {
it('should render correctly', () => {
Expand All @@ -28,7 +24,7 @@ describe('Navbar', () => {
it('should render correctly with brand', () => {
const wrapper = render(
<Navbar>
<NavbarBrand data-testid="navbar-test">ACME</NavbarBrand>
<NavbarBrand data-testid="navbar-test">Saas UI</NavbarBrand>
</Navbar>
)

Expand All @@ -40,9 +36,7 @@ describe('Navbar', () => {
<Navbar>
<NavbarContent data-testid="navbar-content-test">
<NavbarItem>Dashboard</NavbarItem>
<NavbarItem>Team</NavbarItem>
<NavbarItem>Deployments</NavbarItem>
<NavbarItem>Activity</NavbarItem>
<NavbarItem>Contacts</NavbarItem>
<NavbarItem>Settings</NavbarItem>
</NavbarContent>
</Navbar>
Expand All @@ -52,86 +46,4 @@ describe('Navbar', () => {

expect(navbarContent.children.length).toBe(5)
})

it('should render correctly with menu', () => {
const items = ['item1', 'item2', 'item3', 'item4', 'item5']

const wrapper = render(
<Navbar data-testid="navbar-test">
<NavbarMenuToggle data-testid="navbar-toggle-test" />
<NavbarContent data-testid="navbar-content-test">
<NavbarItem>Dashboard</NavbarItem>
<NavbarItem>Team</NavbarItem>
<NavbarItem>Deployments</NavbarItem>
<NavbarItem>Activity</NavbarItem>
<NavbarItem>Settings</NavbarItem>
</NavbarContent>
<NavbarMenu data-testid="navbar-menu-test">
{items.map((item, index) => (
<NavbarMenuItem key={`${item}-${index}`}>{item}</NavbarMenuItem>
))}
</NavbarMenu>
</Navbar>
)

const toggle = wrapper.getByTestId('navbar-toggle-test')

act(() => {
toggle.click()
})

const menu = wrapper.getByTestId('navbar-menu-test')

expect(menu.children.length).toBe(items.length)
})

it('should call on onChange when toggle is clicked', () => {
const onChange = jest.fn()

const wrapper = render(
<Navbar data-testid="navbar-test">
<NavbarMenuToggle
data-testid="navbar-toggle-test"
onChange={onChange}
/>
<NavbarContent data-testid="navbar-content-test">
<NavbarItem>Dashboard</NavbarItem>
<NavbarItem>Team</NavbarItem>
<NavbarItem>Deployments</NavbarItem>
<NavbarItem>Activity</NavbarItem>
<NavbarItem>Settings</NavbarItem>
</NavbarContent>
</Navbar>
)

const toggle = wrapper.getByTestId('navbar-toggle-test')

act(() => {
toggle.click()
})

expect(onChange).toHaveBeenCalled()
})

it('should render correctly with custom toggle icon', () => {
const wrapper = render(
<Navbar data-testid="navbar-test">
<NavbarMenuToggle
data-testid="navbar-toggle-test"
icon={<span>test</span>}
/>
<NavbarContent data-testid="navbar-content-test">
<NavbarItem>Dashboard</NavbarItem>
<NavbarItem>Team</NavbarItem>
<NavbarItem>Deployments</NavbarItem>
<NavbarItem>Activity</NavbarItem>
<NavbarItem>Settings</NavbarItem>
</NavbarContent>
</Navbar>
)

const toggle = wrapper.getByTestId('navbar-toggle-test')

expect(toggle).toHaveTextContent('test')
})
})
2 changes: 1 addition & 1 deletion packages/saas-ui-core/src/navbar/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type MotionProps = Pick<
>

export interface NavbarProps
extends Omit<UseNavbarProps, 'hideOnScroll'>,
extends Omit<UseNavbarProps, 'hideOnScroll' | 'ref'>,
Omit<HTMLChakraProps<'div'>, keyof MotionProps | 'height'>,
MotionProps,
ThemingProps<'SuiNavbar'> {
Expand Down
2 changes: 1 addition & 1 deletion packages/saas-ui-core/src/persona/persona.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'

import { render, testStories } from '@saas-ui/test-utils'
import * as stories from '../stories/persona.stories'
import * as stories from './persona.stories'

testStories<typeof stories>(stories)
2 changes: 1 addition & 1 deletion packages/saas-ui-core/src/property/property.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'

import { render, testStories } from '@saas-ui/test-utils'
import * as stories from '../stories/property.stories'
import * as stories from './property.stories'

const { Basic } = testStories<typeof stories>(stories)

Expand Down

0 comments on commit 5af8914

Please sign in to comment.