Skip to content

Commit

Permalink
DEVPROD-14715: Fix build variant sorting (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad authored Feb 5, 2025
1 parent b1dd441 commit c80d4ef
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
77 changes: 77 additions & 0 deletions apps/spruce/src/pages/waterfall/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,83 @@ describe("groupBuildVariants", () => {
it("correctly groups build variants from versions", () => {
expect(groupBuildVariants(versions)).toStrictEqual(buildVariants);
});

it("sorts display names in an expected order", () => {
const symbolVersions = [
{
activated: true,
id: "version_1",
waterfallBuilds: [
{
id: "id_a",
buildVariant: "bv_a",
displayName: "a",
},
{
id: "id_b",
buildVariant: "bv_b",
displayName: "1",
},
{
id: "id_c",
buildVariant: "bv_c",
displayName: "!",
},
{
id: "id_d",
buildVariant: "bv_d",
displayName: "~",
},
],
},
] as Version[];
expect(groupBuildVariants(symbolVersions)).toStrictEqual([
{
displayName: "!",
id: "bv_c",
builds: [
{
id: "id_c",
tasks: [],
version: "version_1",
},
],
},
{
displayName: "1",
id: "bv_b",
builds: [
{
id: "id_b",
tasks: [],
version: "version_1",
},
],
},
{
displayName: "a",
id: "bv_a",
builds: [
{
id: "id_a",
tasks: [],
version: "version_1",
},
],
},
{
displayName: "~",
id: "bv_d",
builds: [
{
id: "id_d",
tasks: [],
version: "version_1",
},
],
},
]);
});
});

const versions: Version[] = [
Expand Down
12 changes: 9 additions & 3 deletions apps/spruce/src/pages/waterfall/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ export const groupBuildVariants = (
});

// Although each version's build variants are sorted, we need to make sure the whole list is sorted once combined.
const arr: BuildVariant[] = Array.from(bvs.values()).sort((a, b) =>
a.displayName.localeCompare(b.displayName),
);
const arr: BuildVariant[] = Array.from(bvs.values()).sort((a, b) => {
if (a.displayName < b.displayName) {
return -1;
}
if (a.displayName > b.displayName) {
return 1;
}
return 0;
});

return arr;
};

0 comments on commit c80d4ef

Please sign in to comment.