Skip to content

Commit

Permalink
test: fixing existing release date tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanl17 committed Jan 24, 2025
1 parent 3b4cd31 commit 064be01
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,14 @@ export const Calendar = forwardRef(function Calendar(
icon={ChevronLeftIcon}
mode="bleed"
onClick={() => moveFocusedDate(-1)}
data-testid="calendar-prev-month"
tooltipProps={{content: 'Previous month'}}
/>
<Button
icon={ChevronRightIcon}
mode="bleed"
onClick={() => moveFocusedDate(1)}
data-testid="calendar-next-month"
tooltipProps={{content: 'Next month'}}
/>
</TooltipDelayGroupProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ describe('CreateReleaseDialog', () => {

const wrapper = await createTestProvider()
render(<CreateReleaseDialog onCancel={onCancelMock} onSubmit={onSubmitMock} />, {wrapper})

await waitFor(() => {
expect(screen.queryByTestId('loading-block')).not.toBeInTheDocument()

Check failure on line 27 in packages/sanity/src/core/releases/components/dialog/__tests__/CreateReleaseDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest / node 18)

src/core/releases/components/dialog/__tests__/CreateReleaseDialog.test.tsx > CreateReleaseDialog > when creating a new release > should render the dialog

Error: expect(element).not.toBeInTheDocument() expected document not to contain element, found <div class="sc-efgocT gddDFb" data-testid="loading-block" > <div class="StyledText-sc-11ov82j-0 ivlrmW StyledSpinner-sc-124hnd0-0 dlxwXj sc-ffiKcS doCHgh" data-ui="Spinner" > <span> <svg data-sanity-icon="spinner" fill="none" height="1em" viewBox="0 0 25 25" width="1em" xmlns="http://www.w3.org/2000/svg" > <path d="M4.5 12.5C4.5 16.9183 8.08172 20.5 12.5 20.5C16.9183 20.5 20.5 16.9183 20.5 12.5C20.5 8.08172 16.9183 4.5 12.5 4.5" stroke="currentColor" stroke-linejoin="round" stroke-width="1.2" /> </svg> </span> </div> </div> instead Ignored nodes: comments, script, style <html> <head /> <body> <div> <div class="sc-efgocT gddDFb" data-testid="loading-block" > <div class="StyledText-sc-11ov82j-0 ivlrmW StyledSpinner-sc-124hnd0-0 dlxwXj sc-ffiKcS doCHgh" data-ui="Spinner" > <span> <svg data-sanity-icon="spinner" fill="none" height="1em" viewBox="0 0 25 25" width="1em" xmlns="http://www.w3.org/2000/svg" > <path d="M4.5 12.5C4.5 16.9183 8.08172 20.5 12.5 20.5C16.9183 20.5 20.5 16.9183 20.5 12.5C20.5 8.08172 16.9183 4.5 12.5 4.5" stroke="currentColor" stroke-linejoin="round" stroke-width="1.2" /> </svg> </span> </div> </div> </div> <div data-portal="" /> </body> </html>... ❯ src/core/releases/components/dialog/__tests__/CreateReleaseDialog.test.tsx:27:59 ❯ runWithExpensiveErrorDiagnosticsDisabled ../../node_modules/.pnpm/@testing-library[email protected]/node_modules/@testing-library/dom/dist/config.js:47:12 ❯ checkCallback ../../node_modules/.pnpm/@testing-library[email protected]/node_modules/@testing-library/dom/dist/wait-for.js:124:77 ❯ Timeout.checkRealTimersCallback ../../node_modules/.pnpm/@testing-library[email protected]/node_modules/@testing-library/dom/dist/wait-for.js:118:16

Check failure on line 27 in packages/sanity/src/core/releases/components/dialog/__tests__/CreateReleaseDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest / node 18)

src/core/releases/components/dialog/__tests__/CreateReleaseDialog.test.tsx > CreateReleaseDialog > when creating a new release > should call onCancel when dialog is closed

Error: expect(element).not.toBeInTheDocument() expected document not to contain element, found <div class="sc-efgocT gddDFb" data-testid="loading-block" > <div class="StyledText-sc-11ov82j-0 ivlrmW StyledSpinner-sc-124hnd0-0 dlxwXj sc-ffiKcS doCHgh" data-ui="Spinner" > <span> <svg data-sanity-icon="spinner" fill="none" height="1em" viewBox="0 0 25 25" width="1em" xmlns="http://www.w3.org/2000/svg" > <path d="M4.5 12.5C4.5 16.9183 8.08172 20.5 12.5 20.5C16.9183 20.5 20.5 16.9183 20.5 12.5C20.5 8.08172 16.9183 4.5 12.5 4.5" stroke="currentColor" stroke-linejoin="round" stroke-width="1.2" /> </svg> </span> </div> </div> instead Ignored nodes: comments, script, style <html> <head /> <body> <div data-portal="" /> <div> <div class="sc-efgocT gddDFb" data-testid="loading-block" > <div class="StyledText-sc-11ov82j-0 ivlrmW StyledSpinner-sc-124hnd0-0 dlxwXj sc-ffiKcS doCHgh" data-ui="Spinner" > <span> <svg data-sanity-icon="spinner" fill="none" height="1em" viewBox="0 0 25 25" width="1em" xmlns="http://www.w3.org/2000/svg" > <path d="M4.5 12.5C4.5 16.9183 8.08172 20.5 12.5 20.5C16.9183 20.5 20.5 16.9183 20.5 12.5C20.5 8.08172 16.9183 4.5 12.5 4.5" stroke="currentColor" stroke-linejoin="round" stroke-width="1.2" /> </svg> </span> </div> </div> </div> </body> </html>... ❯ src/core/releases/components/dialog/__tests__/CreateReleaseDialog.test.tsx:27:59 ❯ runWithExpensiveErrorDiagnosticsDisabled ../../node_modules/.pnpm/@testing-library[email protected]/node_modules/@testing-library/dom/dist/config.js:47:12 ❯ checkCallback ../../node_modules/.pnpm/@testing-library[email protected]/node_modules/@testing-library/dom/dist/wait-for.js:124:77 ❯ Timeout.checkRealTimersCallback ../../node_modules/.pnpm/@testing-library[email protected]/node_modules/@testing-library/dom/dist/wait-for.js:118:16
})
})

it('should render the dialog', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {LockIcon} from '@sanity/icons'
import {Card, Flex, Spinner, Stack, TabList, Text, useClickOutsideEvent} from '@sanity/ui'
import {format, isAfter, isBefore, isValid, parse, startOfMinute} from 'date-fns'
import {format, isBefore, isValid, parse, startOfMinute} from 'date-fns'
import {isEqual} from 'lodash'
import {useCallback, useEffect, useMemo, useRef, useState} from 'react'

Expand Down Expand Up @@ -62,7 +62,9 @@ export function ReleaseTypePicker(props: {release: ReleaseDocument}): React.JSX.
metadata: {...release.metadata, intendedPublishAt: updatedDate, releaseType},
}

if (!isEqual(newRelease, release) && inputValue && isAfter(inputValue, new Date())) {
if (!isEqual(newRelease, release)) {
if (releaseType === 'scheduled' && inputValue && isBefore(inputValue, new Date())) return

setIsUpdating(true)
updateRelease(newRelease).then(() => {
setIsUpdating(false)
Expand Down Expand Up @@ -128,14 +130,14 @@ export function ReleaseTypePicker(props: {release: ReleaseDocument}): React.JSX.
setInputValue(nextPublishAt)
}, [])

const handleBundlePublishAtChange = useCallback((date: Date | null) => {
const handlePublishAtCalendarChange = useCallback((date: Date | null) => {
if (!date) return

setIsIntendedScheduleDateInPast(isBefore(date, new Date()))
setInputValue(startOfMinute(new Date(date)))
}, [])

const handleInputChange = useCallback((event: React.FocusEvent<HTMLInputElement>) => {
const handlePublishAtInputChange = useCallback((event: React.FocusEvent<HTMLInputElement>) => {
const parsedDate = parse(event.currentTarget.value, dateInputFormat, new Date())

if (isValid(parsedDate)) {
Expand Down Expand Up @@ -185,7 +187,7 @@ export function ReleaseTypePicker(props: {release: ReleaseDocument}): React.JSX.
)}
<LazyTextInput
value={inputValue ? format(inputValue, dateInputFormat) : undefined}
onChange={handleInputChange}
onChange={handlePublishAtInputChange}
/>
<DatePicker
ref={datePickerRef}
Expand All @@ -194,7 +196,7 @@ export function ReleaseTypePicker(props: {release: ReleaseDocument}): React.JSX.
selectTime
padding={0}
value={inputValue}
onChange={handleBundlePublishAtChange}
onChange={handlePublishAtCalendarChange}
isPastDisabled
showTimezone
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ describe('ReleaseTypePicker', () => {
const scheduledTab = screen.getByText('At time')
fireEvent.click(scheduledTab)

const Calendar = getByDataUi(document.body, 'CalendarMonth')
const Calendar = getByDataUi(document.body, 'Calendar')
const CalendarMonth = getByDataUi(document.body, 'CalendarMonth')

// Select the 10th day in the calendar month
fireEvent.click(within(Calendar).getByText('10'))
fireEvent.click(within(Calendar).getByTestId('calendar-next-month'))
fireEvent.click(within(CalendarMonth).getByText('10'))
fireEvent.change(screen.getByLabelText('Select hour'), {target: {value: 10}})
fireEvent.change(screen.getByLabelText('Select minute'), {target: {value: 55}})
expect(mockUpdateRelease).not.toHaveBeenCalled()
Expand Down Expand Up @@ -217,8 +219,10 @@ describe('ReleaseTypePicker', () => {
fireEvent.click(screen.getByText('Undecided'))
fireEvent.click(screen.getByTestId('release-type-picker'))

// Check if the spinner is displayed while updating
screen.getByTestId('updating-release-spinner')
await waitFor(() => {
// Check if the spinner is displayed while updating
screen.queryByTestId('updating-release-spinner')
})
})
})
})

0 comments on commit 064be01

Please sign in to comment.