Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bengotow committed Aug 12, 2024
1 parent 7c28029 commit c31d15e
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const DeleteDynamicPartitionsModalInner = memo(
},
);

const DELETE_DYNAMIC_PARTITIONS_MUTATION = gql`
export const DELETE_DYNAMIC_PARTITIONS_MUTATION = gql`
mutation DeleteDynamicPartitionsMutation(
$partitionKeys: [String!]!
$partitionsDefName: String!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,25 @@ export const TWO_DIMENSIONAL_ASSET_EMPTY: PartitionHealthQuery = {
},
},
};

export const ONE_DIMENSIONAL_DYNAMIC_ASSET: PartitionHealthQuery = {
__typename: 'Query',
assetNodeOrError: {
__typename: 'AssetNode',
id: '1234',
partitionKeysByDimension: [
{
__typename: 'DimensionPartitionKeys',
name: 'default',
partitionKeys: ['apple', 'pear', 'fig'],
type: PartitionDefinitionType.DYNAMIC,
},
],
assetPartitionStatuses: {
__typename: 'DefaultPartitionStatuses',
materializedPartitions: ['apple', 'pear', 'fig'],
materializingPartitions: [],
failedPartitions: [],
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {MockedProvider} from '@apollo/client/testing';
import {waitFor} from '@testing-library/dom';
import {render} from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import {
buildQueryMock,
mockViewportClientRect,
restoreViewportClientRect,
} from '../../testing/mocking';
import {
DELETE_DYNAMIC_PARTITIONS_MUTATION,
DeleteDynamicPartitionsDialog,
} from '../DeleteDynamicPartitionsDialog';
import {ONE_DIMENSIONAL_DYNAMIC_ASSET} from '../__fixtures__/PartitionHealth.fixtures';
import {PARTITION_HEALTH_QUERY} from '../usePartitionHealthData';

describe('DeleteDynamicPartitionsDialog', () => {
beforeAll(() => {
mockViewportClientRect();
});
afterAll(() => {
restoreViewportClientRect();
});

it('should show a partition selector and delete selected partitions', async () => {
const deletePartitionsMock = {
request: {
query: DELETE_DYNAMIC_PARTITIONS_MUTATION,
variables: {
repositorySelector: {repositoryLocationName: 'location', repositoryName: 'repo.py'},
partitionsDefName: 'fruits',
partitionKeys: ['apple', 'fig'],
},
},
result: jest.fn(() => ({
data: {
__typename: 'Mutation',
deleteDynamicPartitions: {},
},
})),
};

const {getByText, getByTestId} = render(
<MockedProvider
mocks={[
buildQueryMock({
query: PARTITION_HEALTH_QUERY,
variables: {assetKey: {path: ['asset']}},
data: ONE_DIMENSIONAL_DYNAMIC_ASSET,
}),
deletePartitionsMock,
]}
>
<DeleteDynamicPartitionsDialog
assetKey={{path: ['asset']}}
repoAddress={{location: 'location', name: 'repo.py'}}
partitionsDefName="fruits"
isOpen
onClose={() => {}}
/>
</MockedProvider>,
);
await waitFor(() => {
expect(getByText('Delete fruits partitions')).toBeVisible();
});
const user = userEvent.setup();
await waitFor(async () => {
await user.click(getByText('Select a partition'));
});
await user.click(getByTestId(`menu-item-apple`));
await user.click(getByTestId(`menu-item-fig`));

await user.click(getByText('Delete 2 partitions'));

expect(deletePartitionsMock.result).toHaveBeenCalled();
});
});

0 comments on commit c31d15e

Please sign in to comment.