Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad committed Dec 8, 2023
1 parent 038cc13 commit dd3e954
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
5 changes: 4 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { execSync } from "child_process";

export default defineConfig({
e2e: {
retries: 3,
retries: {
runMode: 3,
openMode: 0,
},
baseUrl: "http://localhost:3000",
projectId: "yshv48",
reporterOptions: {
Expand Down
12 changes: 7 additions & 5 deletions cypress/integration/version/task_duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("Task Duration Tab", () => {
cy.dataCy("leafygreen-table-row").should("have.length", 3);
cy.location("search").should(
"include",
"duration=DESC&page=0&statuses=running-umbrella,started,dispatched"
"duration=DESC&page=0&statuses=running-umbrella%2Cstarted%2Cdispatched"
);
// Clear status filter.
cy.dataCy("status-filter-popover").click();
Expand Down Expand Up @@ -61,24 +61,26 @@ describe("Task Duration Tab", () => {
});

it("updates URL appropriately when sort is changing", () => {
const durationSortControl = "button[aria-label='Sort by Task Duration']";
// The default sort (DURATION DESC) should be applied
cy.location("search").should("include", "duration=DESC");
const longestTask = "test-thirdparty";
cy.contains(longestTask).should("be.visible");
cy.dataCy("leafygreen-table-row").first().should("contain", longestTask);
cy.dataCy("duration-sort-icon").click();
cy.get(durationSortControl).click();
cy.location("search").should("not.include", "duration");
cy.dataCy("duration-sort-icon").click();
cy.get(durationSortControl).click();
cy.location("search").should("include", "duration=ASC");
const shortestTask = "test-auth";
cy.contains(shortestTask).should("be.visible");
cy.dataCy("leafygreen-table-row").first().should("contain", shortestTask);
});

it("clearing all filters resets to the default sort", () => {
cy.dataCy("duration-sort-icon").click();
const durationSortControl = "button[aria-label='Sort by Task Duration']";
cy.get(durationSortControl).click();
cy.location("search").should("not.include", "duration");
cy.dataCy("duration-sort-icon").click();
cy.get(durationSortControl).click();
cy.location("search").should("include", "duration=ASC");
cy.contains("Clear all filters").click();
cy.location("search").should("include", "duration=DESC");
Expand Down
55 changes: 37 additions & 18 deletions src/pages/version/taskDuration/TaskDurationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,20 @@ export const TaskDurationTable: React.FC<Props> = ({
updatedParams[id] = value;
});

sorting.forEach(({ desc, id }) => {
updatedParams[id] = desc ? SortDirection.Desc : SortDirection.Asc;
});

setQueryParams(updatedParams);
sendEvent({ name: "Filter Tasks", filterBy: Object.keys(filterState) });
};

const updateSort = (sortState: SortingState) => {
const updatedParams = { page: "0" };

if (!sortState.length) {
setQueryParams(updatedParams);
}
filters.forEach(({ id, value }) => {
updatedParams[id] = value;
});

sortState.forEach(({ desc, id }) => {
updatedParams[id] = desc ? SortDirection.Desc : SortDirection.Asc;
Expand All @@ -84,7 +88,7 @@ export const TaskDurationTable: React.FC<Props> = ({
}) => <TaskLink taskId={id} taskName={getValue()} />,
meta: {
search: {
"data-cy": "task-name-filter",
"data-cy": "task-name-filter-popover",
},
},
},
Expand All @@ -97,7 +101,7 @@ export const TaskDurationTable: React.FC<Props> = ({
cell: ({ getValue }) => <TaskStatusBadge status={getValue()} />,
meta: {
treeSelect: {
"data-cy": "status-filter",
"data-cy": "status-filter-popover",
options: statusOptions,
},
},
Expand All @@ -110,7 +114,7 @@ export const TaskDurationTable: React.FC<Props> = ({
enableColumnFilter: true,
meta: {
search: {
"data-cy": "build-variant-filter",
"data-cy": "build-variant-filter-popover",
},
},
},
Expand Down Expand Up @@ -146,6 +150,11 @@ export const TaskDurationTable: React.FC<Props> = ({
columns,
containerRef: tableContainerRef,
data: tasks ?? [],
defaultColumn: {
// Handle bug in sorting order
// https://github.com/TanStack/table/issues/4289
sortDescFirst: false,
},
state: {
columnFilters: filters,
sorting,
Expand Down Expand Up @@ -190,21 +199,31 @@ const getInitialParams = (queryParams: {
initialSort: SortingState;
} => {
const {
[PatchTasksQueryParams.TaskName]: taskName = "",
[PatchTasksQueryParams.Statuses]: statuses = [],
[PatchTasksQueryParams.Variant]: variant = "",
[PatchTasksQueryParams.Duration]: duration = "",
[PatchTasksQueryParams.TaskName]: taskName,
[PatchTasksQueryParams.Statuses]: statuses,
[PatchTasksQueryParams.Variant]: variant,
[PatchTasksQueryParams.Duration]: duration,
} = queryParams;

const initialFilters = [];
if (taskName) {
initialFilters.push({
id: PatchTasksQueryParams.TaskName,
value: taskName,
});
}
if (statuses) {
initialFilters.push({
id: PatchTasksQueryParams.Statuses,
value: Array.isArray(statuses) ? statuses : [statuses],
});
}
if (variant) {
initialFilters.push({ id: PatchTasksQueryParams.Variant, value: variant });
}

return {
initialFilters: [
{ id: PatchTasksQueryParams.TaskName, value: taskName },
{
id: PatchTasksQueryParams.Statuses,
value: Array.isArray(statuses) ? statuses : [statuses],
},
{ id: PatchTasksQueryParams.Variant, value: variant },
],
initialFilters,
initialSort: duration
? [
{
Expand Down

0 comments on commit dd3e954

Please sign in to comment.