-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes 4743: add delete and bulk delete of snapshots (#373)
* Fixes 4743: add delete and bulk delete of snapshots * fix: optimization with promise all, add new tests * fix: improve templates for snapshots query * fix+style: small fixes
- Loading branch information
1 parent
642890a
commit 186335f
Showing
18 changed files
with
951 additions
and
189 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
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
115 changes: 115 additions & 0 deletions
115
...ListTable/components/SnapshotListModal/DeleteSnapshotsModal/DeleteSnapshotsModal.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,115 @@ | ||
import { render } from '@testing-library/react'; | ||
import { | ||
ReactQueryTestWrapper, | ||
defaultContentItemWithSnapshot, | ||
defaultSnapshotItem, | ||
defaultTemplateItem, | ||
defaultTemplateItem2, | ||
} from 'testingHelpers'; | ||
import DeleteSnapshotsModal from './DeleteSnapshotsModal'; | ||
import { DELETE_ROUTE } from 'Routes/constants'; | ||
import { useGetSnapshotList } from 'services/Content/ContentQueries'; | ||
import { useFetchTemplatesForSnapshots } from 'services/Templates/TemplateQueries'; | ||
import { formatDateDDMMMYYYY } from 'helpers'; | ||
|
||
jest.mock('react-query', () => ({ | ||
...jest.requireActual('react-query'), | ||
useQueryClient: jest.fn(), | ||
})); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
useNavigate: jest.fn(), | ||
useParams: () => ({ repoUUID: defaultContentItemWithSnapshot.uuid }), | ||
useLocation: () => ({ | ||
search: `${DELETE_ROUTE}?snapshotUUID=${defaultSnapshotItem.uuid}`, | ||
}), | ||
useHref: () => 'insights/content/repositories', | ||
})); | ||
|
||
jest.mock('../SnapshotListModal', () => ({ | ||
useSnapshotListOutletContext: () => ({ | ||
clearCheckedRepositories: () => undefined, | ||
deletionContext: { | ||
checkedSnapshots: new Set<string>([defaultSnapshotItem.uuid]), | ||
}, | ||
}), | ||
})); | ||
|
||
jest.mock('Hooks/useRootPath', () => () => 'someUrl'); | ||
|
||
jest.mock('services/Content/ContentQueries', () => ({ | ||
useBulkDeleteSnapshotsMutate: () => ({ isLoading: false }), | ||
useGetSnapshotList: jest.fn(), | ||
})); | ||
|
||
jest.mock('services/Templates/TemplateQueries', () => ({ | ||
useFetchTemplatesForSnapshots: jest.fn(), | ||
})); | ||
|
||
jest.mock('middleware/AppContext', () => ({ | ||
useAppContext: () => ({ | ||
features: { snapshots: { accessible: true } }, | ||
rbac: { repoWrite: true, repoRead: true }, | ||
}), | ||
})); | ||
|
||
it('Render delete modal where snapshot is not included in any templates', () => { | ||
(useGetSnapshotList as jest.Mock).mockImplementation(() => ({ | ||
data: { | ||
isLoading: false, | ||
data: [defaultSnapshotItem], | ||
}, | ||
})); | ||
(useFetchTemplatesForSnapshots as jest.Mock).mockImplementation(() => ({ | ||
isError: false, | ||
data: { | ||
data: [], | ||
meta: { limit: 10, offset: 0, count: 0 }, | ||
isLoading: false, | ||
}, | ||
})); | ||
|
||
const { queryByText } = render( | ||
<ReactQueryTestWrapper> | ||
<DeleteSnapshotsModal /> | ||
</ReactQueryTestWrapper>, | ||
); | ||
|
||
expect( | ||
queryByText(formatDateDDMMMYYYY(defaultSnapshotItem.created_at, true)), | ||
).toBeInTheDocument(); | ||
expect(queryByText(defaultTemplateItem.name)).not.toBeInTheDocument(); | ||
expect(queryByText(defaultTemplateItem2.name)).not.toBeInTheDocument(); | ||
expect(queryByText('None')).toBeInTheDocument(); | ||
}); | ||
|
||
it('Render delete modal where snapshot is included in templates', () => { | ||
(useGetSnapshotList as jest.Mock).mockImplementation(() => ({ | ||
data: { | ||
isLoading: false, | ||
data: [defaultSnapshotItem], | ||
}, | ||
})); | ||
(useFetchTemplatesForSnapshots as jest.Mock).mockImplementation(() => ({ | ||
isError: false, | ||
data: { | ||
data: [defaultTemplateItem, defaultTemplateItem2], | ||
meta: { limit: 10, offset: 0, count: 2 }, | ||
isLoading: false, | ||
}, | ||
})); | ||
|
||
const { queryByText } = render( | ||
<ReactQueryTestWrapper> | ||
<DeleteSnapshotsModal /> | ||
</ReactQueryTestWrapper>, | ||
); | ||
|
||
expect( | ||
queryByText(formatDateDDMMMYYYY(defaultSnapshotItem.created_at, true)), | ||
).toBeInTheDocument(); | ||
expect(queryByText(defaultTemplateItem.name)).toBeInTheDocument(); | ||
expect(queryByText(defaultTemplateItem2.name)).toBeInTheDocument(); | ||
expect(queryByText('Some snapshots have associated templates.')).toBeInTheDocument(); | ||
expect(queryByText('None')).not.toBeInTheDocument(); | ||
}); |
Oops, something went wrong.