Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtonG committed Aug 2, 2024
1 parent 7d5c70a commit 548c77f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,23 @@ describe('RunFilterInterstitialModalComponent', () => {
expect(filterFormSetString).toBeDefined();
const filterFormSet = JSON.parse(filterFormSetString || '');

// TODO: is there a better way to test this expectation?
// TODO: is there a better way to test these expectations?
expect(filterFormSet.showArchived).toBeTruthy();
const [filterGroup, idFilterGroup] = filterFormSet.filterGroup.children?.[0].children || [];
expect(filterGroup).toEqual(expectedFilterGroup);

const idFilters = idFilterGroup.children;
expect(idFilters.every((f: FormField) => f.operator === '!=')).toBeTruthy();
expect(idFilters.map((f: FormField) => f.value)).toEqual(expectedExclusions);
const [, , idFilter] = filterFormSet.filterGroup.children;
for (const child of expectedFilterGroup.children) {
expect(filterFormSet.filterGroup.children).toContainEqual(child);
}

for (const exclusion of expectedExclusions) {
expect(idFilter?.children[0].children).toContainEqual({
columnName: 'id',
kind: 'field',
location: 'LOCATION_TYPE_RUN',
operator: '!=',
type: 'COLUMN_TYPE_NUMBER',
value: exclusion,
});
}
});

it('calls server with filter describing visual selection', () => {
Expand All @@ -139,7 +148,7 @@ describe('RunFilterInterstitialModalComponent', () => {
const filterFormSet = JSON.parse(filterFormSetString || '');

expect(filterFormSet.showArchived).toBe(false);
const idFilters = filterFormSet.filterGroup.children?.[0].children || [];
const idFilters = filterFormSet.filterGroup.children || [];
expect(idFilters.every((f: FormField) => f.operator === '=')).toBe(true);
expect(idFilters.map((f: FormField) => f.value)).toEqual(expectedSelection);
});
Expand Down
26 changes: 15 additions & 11 deletions webui/react/src/components/RunFilterInterstitialModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ export const RunFilterInterstitialModalComponent = forwardRef<ControlledModalRef
async (canceler) => {
if (!isOpen) return NotLoaded;
const mergedCanceler = mergeAbortControllers(canceler, closeController.current);
const filter: FilterFormSetWithoutId = {
...filterFormSet,
filterGroup: combine(getIdsFilter(filterFormSet, selection).filterGroup, 'and', {
columnName: 'searcherType',
kind: 'field',
location: 'LOCATION_TYPE_RUN',
operator: '!=',
type: 'COLUMN_TYPE_TEXT',
value: 'single',
}),
};
const filterWithSingleFilter = combine(filterFormSet.filterGroup, 'and', {
columnName: 'searcherType',
kind: 'field',
location: 'LOCATION_TYPE_RUN',
operator: '!=',
type: 'COLUMN_TYPE_TEXT',
value: 'single',
});
const filter: FilterFormSetWithoutId = getIdsFilter(
{
...filterFormSet,
filterGroup: filterWithSingleFilter,
},
selection,
);

try {
const results = await searchRuns(
Expand Down

0 comments on commit 548c77f

Please sign in to comment.