Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw committed Dec 17, 2024
1 parent 16114a4 commit a014b41
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 63 deletions.
35 changes: 12 additions & 23 deletions packages/plugin-awesome/src/generators.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type {
AttachmentLink,
EnvironmentItem,
Statistic,
TestResult
import {
type AttachmentLink,
type EnvironmentItem,
type Statistic,
type TestResult,
compareBy,
nullsLast,
ordinal,
} from "@allurereport/core-api";
import type { AllureStore, ReportFiles, ResultFile } from "@allurereport/plugin-api";
import { createTreeByLabels } from "@allurereport/plugin-api";
Expand Down Expand Up @@ -104,18 +107,6 @@ const createBreadcrumbs = (convertedTr: AllureAwesomeTestResult) => {
}, [] as string[][]);
};

export const getTestResultStart = (testResult: AllureAwesomeTestResult) => {
if (testResult.start) {
return testResult.start;
}

if (testResult.stop && testResult.duration) {
return testResult.stop - testResult.duration;
}

return undefined;
};

export const generateTestResults = async (writer: AllureAwesomeDataWriter, store: AllureStore) => {
const allTr = await store.allTestResults({ includeHidden: true });
let convertedTrs: AllureAwesomeTestResult[] = [];
Expand All @@ -140,12 +131,10 @@ export const generateTestResults = async (writer: AllureAwesomeDataWriter, store
convertedTrs.push(convertedTr);
}

convertedTrs = convertedTrs
.sort((a, b) => getTestResultStart(a)! > getTestResultStart(b)! ? 1 : -1)
.map((tr, idx) => ({
...tr,
order: idx + 1,
}));
convertedTrs = convertedTrs.sort(nullsLast(compareBy("start", ordinal()))).map((tr, idx) => ({
...tr,
order: idx + 1,
}));

for (const convertedTr of convertedTrs) {
await writer.writeTestCase(convertedTr);
Expand Down
3 changes: 2 additions & 1 deletion packages/web-awesome/src/utils/treeFilters.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { compareBy, nullsLast, ordinal, reverse } from "@allurereport/core-api";
import type { TreeFiltersState } from "@/stores/tree";
import type {
AllureAwesomeOrderedTree,
Expand Down Expand Up @@ -32,7 +33,7 @@ export const filterLeaves = (

return [queryMatched, statusMatched, flakyMatched, retryMatched].every(Boolean);
})
.sort((a, b) => a.start - b.start)
.sort(nullsLast(compareBy("start", ordinal())))
.map(
(leaf, i) =>
({
Expand Down
78 changes: 39 additions & 39 deletions packages/web-awesome/test/utils/treeFilters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ describe("utils > treeFilters", () => {
const result = filterLeaves(leaves, leavesById);

expect(result).toEqual([
expect.objectContaining({ name: "a1", order: 1 }),
expect.objectContaining({ name: "b2", order: 2 }),
expect.objectContaining({ name: "c3", order: 3 }),
expect.objectContaining({ name: "a1", groupOrder: 1 }),
expect.objectContaining({ name: "b2", groupOrder: 2 }),
expect.objectContaining({ name: "c3", groupOrder: 3 }),
]);
});

Expand Down Expand Up @@ -56,8 +56,8 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual([
expect.objectContaining({ name: "a1", order: 1 }),
expect.objectContaining({ name: "c3", order: 2 }),
expect.objectContaining({ name: "a1", groupOrder: 1 }),
expect.objectContaining({ name: "c3", groupOrder: 2 }),
]);
});

Expand Down Expand Up @@ -88,8 +88,8 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual([
expect.objectContaining({ name: "a1", order: 1 }),
expect.objectContaining({ name: "c3", order: 2 }),
expect.objectContaining({ name: "a1", groupOrder: 1 }),
expect.objectContaining({ name: "c3", groupOrder: 2 }),
]);
});

Expand Down Expand Up @@ -118,7 +118,7 @@ describe("utils > treeFilters", () => {
},
});

expect(result).toEqual([expect.objectContaining({ name: "a1", order: 1 })]);
expect(result).toEqual([expect.objectContaining({ name: "a1", groupOrder: 1 })]);
});

it("sorts leave by duration in ascending order", () => {
Expand All @@ -143,9 +143,9 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual([
expect.objectContaining({ name: "a1", order: 1 }),
expect.objectContaining({ name: "b2", order: 2 }),
expect.objectContaining({ name: "c3", order: 3 }),
expect.objectContaining({ name: "a1", groupOrder: 1 }),
expect.objectContaining({ name: "b2", groupOrder: 2 }),
expect.objectContaining({ name: "c3", groupOrder: 3 }),
]);
});

Expand All @@ -171,9 +171,9 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual([
expect.objectContaining({ name: "c3", order: 3 }),
expect.objectContaining({ name: "b2", order: 2 }),
expect.objectContaining({ name: "a1", order: 1 }),
expect.objectContaining({ name: "c3", groupOrder: 3 }),
expect.objectContaining({ name: "b2", groupOrder: 2 }),
expect.objectContaining({ name: "a1", groupOrder: 1 }),
]);
});

Expand All @@ -196,9 +196,9 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual([
expect.objectContaining({ name: "a1", order: 1 }),
expect.objectContaining({ name: "b2", order: 2 }),
expect.objectContaining({ name: "c3", order: 3 }),
expect.objectContaining({ name: "a1", groupOrder: 1 }),
expect.objectContaining({ name: "b2", groupOrder: 2 }),
expect.objectContaining({ name: "c3", groupOrder: 3 }),
]);
});

Expand All @@ -221,9 +221,9 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual([
expect.objectContaining({ name: "c3", order: 3 }),
expect.objectContaining({ name: "b2", order: 2 }),
expect.objectContaining({ name: "a1", order: 1 }),
expect.objectContaining({ name: "c3", groupOrder: 3 }),
expect.objectContaining({ name: "b2", groupOrder: 2 }),
expect.objectContaining({ name: "a1", groupOrder: 1 }),
]);
});

Expand Down Expand Up @@ -257,11 +257,11 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual([
expect.objectContaining({ name: "b2", order: 2 }),
expect.objectContaining({ name: "c3", order: 3 }),
expect.objectContaining({ name: "a1", order: 1 }),
expect.objectContaining({ name: "e5", order: 5 }),
expect.objectContaining({ name: "d4", order: 4 }),
expect.objectContaining({ name: "b2", groupOrder: 2 }),
expect.objectContaining({ name: "c3", groupOrder: 3 }),
expect.objectContaining({ name: "a1", groupOrder: 1 }),
expect.objectContaining({ name: "e5", groupOrder: 5 }),
expect.objectContaining({ name: "d4", groupOrder: 4 }),
]);
});

Expand Down Expand Up @@ -295,11 +295,11 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual([
expect.objectContaining({ name: "d4", order: 4 }),
expect.objectContaining({ name: "e5", order: 5 }),
expect.objectContaining({ name: "a1", order: 1 }),
expect.objectContaining({ name: "c3", order: 3 }),
expect.objectContaining({ name: "b2", order: 2 }),
expect.objectContaining({ name: "d4", groupOrder: 4 }),
expect.objectContaining({ name: "e5", groupOrder: 5 }),
expect.objectContaining({ name: "a1", groupOrder: 1 }),
expect.objectContaining({ name: "c3", groupOrder: 3 }),
expect.objectContaining({ name: "b2", groupOrder: 2 }),
]);
});

Expand All @@ -326,9 +326,9 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual([
expect.objectContaining({ name: "c3", order: 1 }),
expect.objectContaining({ name: "b2", order: 2 }),
expect.objectContaining({ name: "a1", order: 3 }),
expect.objectContaining({ name: "c3", groupOrder: 1 }),
expect.objectContaining({ name: "b2", groupOrder: 2 }),
expect.objectContaining({ name: "a1", groupOrder: 3 }),
]);
});

Expand All @@ -355,9 +355,9 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual([
expect.objectContaining({ name: "a1", order: 3 }),
expect.objectContaining({ name: "b2", order: 2 }),
expect.objectContaining({ name: "c3", order: 1 }),
expect.objectContaining({ name: "a1", groupOrder: 3 }),
expect.objectContaining({ name: "b2", groupOrder: 2 }),
expect.objectContaining({ name: "c3", groupOrder: 1 }),
]);
});
});
Expand Down Expand Up @@ -404,13 +404,13 @@ describe("utils > treeFilters", () => {
});

expect(result).toEqual({
leaves: [expect.objectContaining({ name: "a1", order: 1 })],
leaves: [expect.objectContaining({ name: "a1", groupOrder: 1 })],
groups: [
{
leaves: [expect.objectContaining({ name: "b2", order: 1 })],
leaves: [expect.objectContaining({ name: "b2", groupOrder: 1 })],
groups: [
{
leaves: [expect.objectContaining({ name: "c3", order: 1 })],
leaves: [expect.objectContaining({ name: "c3", groupOrder: 1 })],
groups: [],
},
],
Expand Down

0 comments on commit a014b41

Please sign in to comment.