Skip to content

Commit

Permalink
test(releases): comprehensive testing on release nav (#7840)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanl17 authored Nov 19, 2024
1 parent 89137be commit ca2bf71
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 80 deletions.
38 changes: 35 additions & 3 deletions packages/sanity/src/core/releases/__fixtures__/release.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,46 @@ export const activeScheduledRelease: ReleaseDocument = {
_id: '_.releases.activeRelease',
_type: 'system.release',
createdBy: '',
_createdAt: '2023-10-01T08:00:00Z',
_updatedAt: '2023-10-01T09:00:00Z',
_createdAt: '2023-10-10T08:00:00Z',
_updatedAt: '2023-10-10T09:00:00Z',
state: 'active',
name: 'activeRelease',
metadata: {
title: 'active Release',
releaseType: 'scheduled',
intendedPublishAt: '2023-10-01T10:00:00Z',
intendedPublishAt: '2023-10-10T10:00:00Z',
description: 'active Release description',
},
}

export const scheduledRelease: ReleaseDocument = {
_id: '_.releases.scheduledRelease',
_type: 'system.release',
createdBy: '',
_createdAt: '2023-10-10T08:00:00Z',
_updatedAt: '2023-10-10T09:00:00Z',
state: 'scheduled',
name: 'scheduledRelease',
publishAt: '2023-10-10T10:00:00Z',
metadata: {
title: 'scheduled Release',
releaseType: 'scheduled',
intendedPublishAt: '2023-10-10T10:00:00Z',
description: 'scheduled Release description',
},
}

export const activeASAPRelease: ReleaseDocument = {
_id: '_.releases.activeRelease',
_type: 'system.release',
createdBy: '',
_createdAt: '2023-10-01T08:00:00Z',
_updatedAt: '2023-10-01T09:00:00Z',
state: 'active',
name: 'activeRelease',
metadata: {
title: 'active asap Release',
releaseType: 'asap',
description: 'active Release description',
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {type Mocked, vi} from 'vitest'

import {LATEST} from '../../../util/const'
import {type PerspectiveValue} from '../../usePerspective'

export const usePerspectiveMock: Mocked<PerspectiveValue> = {
perspective: undefined,
excludedPerspectives: [],
setPerspective: vi.fn(),
currentGlobalBundle: LATEST,
setPerspectiveFromReleaseId: vi.fn(),
setPerspectiveFromReleaseDocumentId: vi.fn(),
toggleExcludedPerspective: vi.fn(),
isPerspectiveExcluded: vi.fn(),
currentGlobalBundleId: 'drafts',
bundlesPerspective: [],
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {css, styled} from 'styled-components'
import {MenuButton} from '../../../ui-components'
import {useTranslation} from '../../i18n'
import {CreateReleaseDialog} from '../components/dialog/CreateReleaseDialog'
import {usePerspective} from '../hooks'
import {usePerspective} from '../hooks/usePerspective'
import {type ReleaseDocument, type ReleaseType} from '../store/types'
import {useReleases} from '../store/useReleases'
import {
Expand Down Expand Up @@ -75,17 +75,8 @@ export function GlobalPerspectiveMenu(): JSX.Element {
)

const range: LayerRange = useMemo(() => {
let firstIndex = -1
let lastIndex = 0

// if (!releases.published.hidden) {
firstIndex = 0
// }

if (currentGlobalBundleId === 'published') {
lastIndex = 0
}

const {asap, scheduled} = sortedReleaseTypeReleases
const countAsapReleases = asap.length
const countScheduledReleases = scheduled.length
Expand All @@ -103,12 +94,6 @@ export function GlobalPerspectiveMenu(): JSX.Element {
groupSubsetReleases.forEach(({_id}, groupReleaseIndex) => {
const index = offset + groupReleaseIndex

if (firstIndex === -1) {
// if (!item.hidden) {
firstIndex = index
// }
}

if (_id === currentGlobalBundleId) {
lastIndex = index
}
Expand All @@ -118,7 +103,6 @@ export function GlobalPerspectiveMenu(): JSX.Element {
orderedReleaseTypes.forEach(adjustIndexForReleaseType)

return {
firstIndex,
lastIndex,
offsets,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import {GlobalPerspectiveMenuItemIndicator} from './PerspectiveLayerIndicator'

export interface LayerRange {
firstIndex: number
lastIndex: number
offsets: {
asap: number
Expand Down Expand Up @@ -67,12 +66,12 @@ const ExcludedLayerDot = () => (
type rangePosition = 'first' | 'within' | 'last' | undefined

export function getRangePosition(range: LayerRange, index: number): rangePosition {
const {firstIndex, lastIndex} = range
const {lastIndex} = range

if (firstIndex === lastIndex) return undefined
if (index === firstIndex) return 'first'
if (lastIndex === 0) return undefined
if (index === 0) return 'first'
if (index === lastIndex) return 'last'
if (index > firstIndex && index < lastIndex) return 'within'
if (index > 0 && index < lastIndex) return 'within'

return undefined
}
Expand Down Expand Up @@ -191,12 +190,13 @@ export const GlobalPerspectiveMenuItem = forwardRef<
mode="bleed"
onClick={handleToggleReleaseVisibility}
padding={2}
data-testid="release-toggle-visibility"
/>
</Tooltip>
)}
{!isPublishedPerspective(release) && isReleaseScheduledOrScheduling(release) && (
<Box padding={2}>
<Text size={1}>
<Text size={1} data-testid="release-lock-icon">
<LockIcon />
</Text>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ export function ReleaseTypeMenuSection({

if (releases.length === 0) return null

const {firstIndex, lastIndex, offsets} = range
const {lastIndex, offsets} = range
const releaseTypeOffset = offsets[releaseType]

return (
<>
<GlobalPerspectiveMenuLabelIndicator
$withinRange={firstIndex < releaseTypeOffset && lastIndex >= releaseTypeOffset}
$withinRange={releaseTypeOffset > 0 && lastIndex >= releaseTypeOffset}
paddingRight={2}
paddingTop={releaseType === 'asap' ? 1 : 4}
paddingBottom={2}
Expand Down
Loading

0 comments on commit ca2bf71

Please sign in to comment.