Skip to content

Commit

Permalink
fix(corel): update bundles table test
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Jul 8, 2024
1 parent e0156ec commit efca9b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export const BundleMenuButton = ({bundle}: Props) => {
setIsPerformingOperation(true)
await deleteBundle(bundle._id)
setIsPerformingOperation(false)
if (router.state.bundleId) {
if (router.state.bundleName) {
// navigate back to bundle overview
router.navigate({bundleId: undefined})
router.navigate({bundleName: undefined})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {BundlesTable} from '../BundlesTable'

jest.mock('sanity/router', () => ({
...(jest.requireActual('sanity/router') || {}),
useRouter: jest.fn().mockReturnValue({state: {bundleId: '123'}, navigate: jest.fn()}),
useRouter: jest.fn().mockReturnValue({state: {bundleName: '123'}, navigate: jest.fn()}),
}))

jest.mock('../../../../store/bundles/useBundleOperations', () => ({
Expand Down Expand Up @@ -67,17 +67,17 @@ describe('BundlesTable', () => {

describe('A bundle row', () => {
it('should navigate to the bundle detail when clicked', async () => {
const bundles = [{_id: '123', title: 'Bundle 1'}] as BundleDocument[]
const bundles = [{_id: '123', title: 'Bundle 1', name: 'bundle-1'}] as BundleDocument[]
await renderBundlesTable(bundles)

const bundleRow = screen.getAllByTestId('bundle-row')[0]
fireEvent.click(within(bundleRow).getByText('Bundle 1'))

expect(useRouter().navigate).toHaveBeenCalledWith({bundleId: '123'})
expect(useRouter().navigate).toHaveBeenCalledWith({bundleName: 'bundle-1'})
})

it('should delete bundle when menu button is clicked', async () => {
const bundles = [{_id: '123', title: 'Bundle 1'}] as BundleDocument[]
const bundles = [{_id: '123', title: 'Bundle 1', name: 'bundle-1'}] as BundleDocument[]
await renderBundlesTable(bundles)

const bundleRow = screen.getAllByTestId('bundle-row')[0]
Expand All @@ -87,7 +87,7 @@ describe('BundlesTable', () => {

await waitFor(() => {
expect(useBundleOperations().deleteBundle).toHaveBeenCalledWith('123')
expect(useRouter().navigate).toHaveBeenCalledWith({bundleId: undefined})
expect(useRouter().navigate).toHaveBeenCalledWith({bundleName: undefined})
})
})
})
Expand Down

0 comments on commit efca9b3

Please sign in to comment.