-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(sanity): update releaseForm tests
- Loading branch information
Showing
2 changed files
with
17 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import {fireEvent, render, screen} from '@testing-library/react' | ||
import {act} from 'react' | ||
import {beforeEach, describe, expect, it, type Mock, vi} from 'vitest' | ||
|
||
import {createTestProvider} from '../../../../../../test/testUtils/TestProvider' | ||
import {useDateTimeFormat} from '../../../../hooks' | ||
import {studioDefaultLocaleResources} from '../../../../i18n/bundles/studio' | ||
import {releasesUsEnglishLocaleBundle} from '../../../i18n' | ||
import {type EditableReleaseDocument, type ReleaseDocument, useReleases} from '../../../store' | ||
import {RELEASE_DOCUMENT_TYPE} from '../../../store/constants' | ||
import {ReleaseForm} from '../ReleaseForm' | ||
|
@@ -14,12 +17,6 @@ vi.mock('../../../store/useReleases', () => ({ | |
useReleases: vi.fn(), | ||
})) | ||
|
||
vi.mock('../../../i18n/hooks/useTranslation', () => ({ | ||
useTranslate: vi.fn().mockReturnValue({ | ||
t: vi.fn(), | ||
}), | ||
})) | ||
|
||
const mockUseReleases = useReleases as Mock<typeof useReleases> | ||
const mockUseDateTimeFormat = useDateTimeFormat as Mock | ||
|
||
|
@@ -68,7 +65,9 @@ describe('ReleaseForm', () => { | |
|
||
mockUseDateTimeFormat.mockReturnValue({format: vi.fn().mockReturnValue('Mocked date')}) | ||
|
||
const wrapper = await createTestProvider() | ||
const wrapper = await createTestProvider({ | ||
resources: [releasesUsEnglishLocaleBundle, studioDefaultLocaleResources], | ||
}) | ||
render(<ReleaseForm onChange={onChangeMock} value={valueMock} />, { | ||
wrapper, | ||
}) | ||
|
@@ -77,12 +76,14 @@ describe('ReleaseForm', () => { | |
it('should render the form fields', () => { | ||
expect(screen.getByTestId('release-form-title')).toBeInTheDocument() | ||
Check failure on line 77 in packages/sanity/src/core/releases/components/dialog/__tests__/ReleaseForm.test.tsx GitHub Actions / Test (ubuntu-latest / node 20)src/core/releases/components/dialog/__tests__/ReleaseForm.test.tsx > ReleaseForm > when creating a new release > should render the form fields
Check failure on line 77 in packages/sanity/src/core/releases/components/dialog/__tests__/ReleaseForm.test.tsx GitHub Actions / Test (ubuntu-latest / node 18)src/core/releases/components/dialog/__tests__/ReleaseForm.test.tsx > ReleaseForm > when creating a new release > should render the form fields
|
||
expect(screen.getByTestId('release-form-description')).toBeInTheDocument() | ||
//expect(screen.getByTestId('release-form-publish-at')).toBeInTheDocument() | ||
}) | ||
|
||
it('should call onChange when title input value changes', () => { | ||
const titleInput = screen.getByTestId('release-form-title') | ||
fireEvent.change(titleInput, {target: {value: 'Bundle 1'}}) | ||
|
||
act(() => { | ||
fireEvent.change(titleInput, {target: {value: 'Bundle 1'}}) | ||
}) | ||
|
||
expect(onChangeMock).toHaveBeenCalledWith({ | ||
...valueMock, | ||
|
@@ -121,78 +122,4 @@ describe('ReleaseForm', () => { | |
expect(screen.getByTestId('input-validation-icon-error')).toBeInTheDocument() | ||
})*/ | ||
}) | ||
|
||
describe('when updating an existing release', () => { | ||
const existingBundleValue: ReleaseDocument = { | ||
_id: 'db76c50e-358b-445c-a57c-8344c588a5d5', | ||
_type: RELEASE_DOCUMENT_TYPE, | ||
_createdAt: '2024-07-02T11:37:51Z', | ||
_updatedAt: '2024-07-12T10:39:32Z', | ||
name: 'spring-drop', | ||
createdBy: 'unknown', | ||
state: 'active', | ||
metadata: { | ||
title: 'Summer Drop', | ||
description: 'Summer time', | ||
releaseType: 'asap', | ||
}, | ||
} | ||
beforeEach(async () => { | ||
onChangeMock.mockClear() | ||
onErrorMock.mockClear() | ||
|
||
// Mock the data returned by useBundles hook | ||
const mockData: ReleaseDocument[] = [ | ||
{ | ||
_id: 'db76c50e-358b-445c-a57c-8344c588a5d5', | ||
_type: RELEASE_DOCUMENT_TYPE, | ||
_createdAt: '2024-07-02T11:37:51Z', | ||
_updatedAt: '2024-07-12T10:39:32Z', | ||
name: 'spring-drop', | ||
createdBy: 'unknown', | ||
state: 'active', | ||
metadata: { | ||
releaseType: 'asap', | ||
title: 'Spring Drop', | ||
description: 'What a spring drop, allergies galore 🌸', | ||
}, | ||
}, | ||
// Add more mock data if needed | ||
] | ||
mockUseReleases.mockReturnValue({ | ||
data: mockData, | ||
loading: false, | ||
dispatch: vi.fn(), | ||
error: undefined, | ||
archivedReleases: [], | ||
releasesIds: [], | ||
}) | ||
|
||
mockUseDateTimeFormat.mockReturnValue({format: vi.fn().mockReturnValue('Mocked date')}) | ||
|
||
const wrapper = await createTestProvider() | ||
render(<ReleaseForm onChange={onChangeMock} value={existingBundleValue} />, { | ||
wrapper, | ||
}) | ||
}) | ||
|
||
it('should allow for any title to be used', async () => { | ||
const titleInput = screen.getByTestId('release-form-title') | ||
expect(titleInput).toHaveValue(existingBundleValue.metadata.title) | ||
// the slug of this title already exists, | ||
// but the slug for the existing edited release will not be changed | ||
fireEvent.change(titleInput, {target: {value: 'Spring Drop'}}) | ||
|
||
expect(screen.queryByTestId('input-validation-icon-error')).not.toBeInTheDocument() | ||
}) | ||
|
||
it('should populate the form with the existing release values', () => { | ||
expect(screen.getByTestId('release-form-title')).toHaveValue( | ||
existingBundleValue.metadata.title, | ||
) | ||
expect(screen.getByTestId('release-form-description')).toHaveValue( | ||
existingBundleValue.metadata.description, | ||
) | ||
}) | ||
}) | ||
}) |