-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move createWrapper to test package, update name -> slug (#7177)
* fix: issue with slugs and condition * fix: issue with badge with global bundle + tests * chore: update test imports * test: update createWrapper import * refactor: update dummygetters to reflect corel
- Loading branch information
Showing
12 changed files
with
94 additions
and
16 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
2 changes: 1 addition & 1 deletion
2
packages/sanity/src/core/bundles/components/dialog/__tests__/BundleIconEditorPicker.test.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
83 changes: 83 additions & 0 deletions
83
packages/sanity/src/core/bundles/components/dialog/__tests__/CreateBundleDialog.test.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,83 @@ | ||
import {beforeEach, describe, expect, it, jest} from '@jest/globals' | ||
import {fireEvent, render, screen} from '@testing-library/react' | ||
import {type BundleDocument, useBundles} from 'sanity' | ||
|
||
import {createWrapper} from '../../../../../../test/testUtils/createWrapper' | ||
import {useBundleOperations} from '../../../../store/bundles/useBundleOperations' | ||
import {usePerspective} from '../../../hooks/usePerspective' | ||
import {CreateBundleDialog} from '../CreateBundleDialog' | ||
|
||
/*jest.mock('../../../../../core/hooks/useDateTimeFormat', () => ({ | ||
useDateTimeFormat: jest.fn(), | ||
}))*/ | ||
|
||
jest.mock('../../../../store/bundles', () => ({ | ||
useBundles: jest.fn(), | ||
})) | ||
|
||
jest.mock('../../../../store/bundles/useBundleOperations', () => ({ | ||
useBundleOperations: jest.fn().mockReturnValue({ | ||
createBundle: jest.fn(), | ||
}), | ||
})) | ||
|
||
jest.mock('../../../hooks/usePerspective', () => ({ | ||
usePerspective: jest.fn().mockReturnValue({ | ||
setPerspective: jest.fn(), | ||
}), | ||
})) | ||
|
||
const mockUseBundleStore = useBundles as jest.Mock<typeof useBundles> | ||
//const mockUseDateTimeFormat = useDateTimeFormat as jest.Mock | ||
|
||
describe('CreateBundleDialog', () => { | ||
const onCancelMock = jest.fn() | ||
const onCreateMock = jest.fn() | ||
|
||
beforeEach(async () => { | ||
onCancelMock.mockClear() | ||
onCreateMock.mockClear() | ||
|
||
mockUseBundleStore.mockReturnValue({ | ||
data: [], | ||
loading: true, | ||
dispatch: jest.fn(), | ||
}) | ||
|
||
//mockUseDateTimeFormat.mockReturnValue({format: jest.fn().mockReturnValue('Mocked date')}) | ||
|
||
const wrapper = await createWrapper() | ||
render(<CreateBundleDialog onCancel={onCancelMock} onCreate={onCreateMock} />, {wrapper}) | ||
}) | ||
|
||
it('should render the dialog', () => { | ||
expect(screen.getByRole('dialog')).toBeInTheDocument() | ||
}) | ||
|
||
it('should call onCancel when dialog is closed', () => { | ||
fireEvent.click(screen.getByRole('button', {name: /close/i})) | ||
|
||
expect(onCancelMock).toHaveBeenCalled() | ||
}) | ||
|
||
it('should call createBundle, setPerspective, and onCreate when form is submitted with a valid slug', async () => { | ||
const value: Partial<BundleDocument> = { | ||
slug: 'bundle-1', | ||
title: 'Bundle 1', | ||
hue: 'gray', | ||
icon: 'cube', | ||
//publishAt: undefined, | ||
} | ||
|
||
const titleInput = screen.getByTestId('bundle-form-title') | ||
fireEvent.change(titleInput, {target: {value: value.title}}) | ||
|
||
const submitButton = screen.getByTestId('create-release-button') | ||
fireEvent.click(submitButton) | ||
|
||
await expect(useBundleOperations().createBundle).toHaveBeenCalledWith(value) | ||
|
||
expect(usePerspective().setPerspective).toHaveBeenCalledWith(value.slug) | ||
expect(onCreateMock).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
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
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
7 changes: 2 additions & 5 deletions
7
...core/bundles/util/tests/createWrapper.tsx → ...s/sanity/test/testUtils/createWrapper.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