Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(releases): comprehensive testing on release nav #7840

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading