-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(releases): archive and unarchive releases (#7072)
* refactor(sanity): update types to bundle * feat(sanity): add ability to create releases from dialog + update types * feat(sanity): update list on global and document to use store * feat(sanity): update types, add icon and hue picker to bundles, update uis * feat(sanity): add date picker to bundleform * refactor(sanity): update publishAt fields in menus * refactor(sanity): update type in dummyGetter * chore(sanity): remove BUNDLES const * chore(sanity): update LATEST type to Partial * chore(sanity): update validation for bundle date creation * chore(sanity): clean up code * refactor(sanity): add archived filter * refactor(sanity): make single bundle menu + clean up * chore(sanity): add missing properties * feat(sanity): add loading & remove unused code * feat(sanity): add loading to document version, update filter * chore(sanity): rename VersionBadge to BundleBadge * chore(sanity): clean up methods and style * chore(sanity): remove unused import * refactor(sanity): use Bundle provider instead of store * chore(sanity): update bundleRow to use the new name for badge * chore(sanity): clean up code * refactor(sanity): re-add oncancel and oncreate props in dialog * refactor(sanity): add scroll to bundle menu * refactor(sanity): move from archived to archivedAt * refactor(sanity): move version provider to its own file + organise + add useVersion * refactor(sanity): remove provider + context, move logic to hook * chore(sanity): remove comments + change name from setCurrentVersion to setGlobalBundle * chore(sanity): rename useVersion to useBundle * chore(sanity): update comments * chore(sanity): Rename currentVersion * refactor(sanity): rename currentBudnle and setGlobalBundle * chore(sanity): rename versions to bundles in core directory * chore(sanity): rename to GlobalPerspectiveMenu and move to navbar directory * chore(sanity): rename to DocumentPerspectiveMenu and move to navbar directory * feat(releases): support for (un)archive * chore(releases): updating testing for BundlesOverview * chore(releases): new tests for BundleMenuButton and (un)archive * fix(releases): disabling bundle menu btn when action is performed --------- Co-authored-by: RitaDias <[email protected]> Co-authored-by: RitaDias <[email protected]>
- Loading branch information
Showing
9 changed files
with
172 additions
and
23 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
108 changes: 108 additions & 0 deletions
108
.../sanity/src/core/releases/components/BundleMenuButton/__tests__/BundleMenuButton.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,108 @@ | ||
import {describe, expect, jest, test} from '@jest/globals' | ||
import {fireEvent, render, screen} from '@testing-library/react' | ||
import {act} from 'react' | ||
import {useRouter} from 'sanity/router' | ||
|
||
import {createTestProvider} from '../../../../../../test/testUtils/TestProvider' | ||
import {type BundleDocument} from '../../../../store/bundles/types' | ||
import {useBundleOperations} from '../../../../store/bundles/useBundleOperations' | ||
import {releasesUsEnglishLocaleBundle} from '../../../i18n' | ||
import {BundleMenuButton} from '../BundleMenuButton' | ||
|
||
jest.mock('../../../../store/bundles/useBundleOperations', () => ({ | ||
useBundleOperations: jest.fn().mockReturnValue({ | ||
deleteBundle: jest.fn(), | ||
updateBundle: jest.fn(), | ||
}), | ||
})) | ||
|
||
jest.mock('sanity/router', () => ({ | ||
...(jest.requireActual('sanity/router') || {}), | ||
useRouter: jest.fn().mockReturnValue({state: {}, navigate: jest.fn()}), | ||
})) | ||
|
||
const renderTest = async (bundle: BundleDocument) => { | ||
const wrapper = await createTestProvider({ | ||
resources: [releasesUsEnglishLocaleBundle], | ||
}) | ||
return render(<BundleMenuButton bundle={bundle} />, {wrapper}) | ||
} | ||
|
||
describe('BundleMenuButton', () => { | ||
test('will archive an unarchived bundle', async () => { | ||
const activeBundle: BundleDocument = { | ||
_id: 'activeBundle', | ||
_type: 'bundle', | ||
archivedAt: undefined, | ||
title: 'activeBundle', | ||
name: 'activeBundle', | ||
authorId: 'author', | ||
_createdAt: new Date().toISOString(), | ||
_updatedAt: new Date().toISOString(), | ||
_rev: '', | ||
} | ||
|
||
await renderTest(activeBundle) | ||
|
||
fireEvent.click(screen.getByLabelText('Release menu')) | ||
|
||
await act(() => { | ||
fireEvent.click(screen.getByText('Archive')) | ||
}) | ||
|
||
expect(useBundleOperations().updateBundle).toHaveBeenCalledWith({ | ||
...activeBundle, | ||
archivedAt: expect.any(String), | ||
}) | ||
}) | ||
|
||
test('will unarchive an archived bundle', async () => { | ||
const archivedBundle: BundleDocument = { | ||
_id: 'activeBundle', | ||
_type: 'bundle', | ||
archivedAt: new Date().toISOString(), | ||
title: 'activeBundle', | ||
name: 'activeBundle', | ||
authorId: 'author', | ||
_createdAt: new Date().toISOString(), | ||
_updatedAt: new Date().toISOString(), | ||
_rev: '', | ||
} | ||
await renderTest(archivedBundle) | ||
|
||
fireEvent.click(screen.getByLabelText('Release menu')) | ||
|
||
await act(() => { | ||
fireEvent.click(screen.getByText('Unarchive')) | ||
}) | ||
|
||
expect(useBundleOperations().updateBundle).toHaveBeenCalledWith({ | ||
...archivedBundle, | ||
archivedAt: undefined, | ||
}) | ||
}) | ||
|
||
test('will delete a bundle', async () => { | ||
const activeBundle: BundleDocument = { | ||
_id: 'activeBundle', | ||
_type: 'bundle', | ||
archivedAt: new Date().toISOString(), | ||
title: 'activeBundle', | ||
name: 'activeBundle', | ||
authorId: 'author', | ||
_createdAt: new Date().toISOString(), | ||
_updatedAt: new Date().toISOString(), | ||
_rev: '', | ||
} | ||
await renderTest(activeBundle) | ||
|
||
fireEvent.click(screen.getByLabelText('Release menu')) | ||
|
||
await act(() => { | ||
fireEvent.click(screen.getByText('Delete')) | ||
}) | ||
|
||
expect(useBundleOperations().deleteBundle).toHaveBeenCalledWith(activeBundle._id) | ||
expect(useRouter().navigate).not.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
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