Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/workspaces/workspace-classes-query.test.ts
2501 views
1
/**
2
* Copyright (c) 2024 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { AllowedWorkspaceClass, getNextDefaultClass } from "./workspace-classes-query";
8
9
test("getNextDefaultClass", async () => {
10
const allClasses: AllowedWorkspaceClass[] = [
11
{ id: "cls-1" },
12
{ id: "cls-2", isDisabledInScope: true },
13
{ id: "cls-3" },
14
{ id: "cls-4", isDisabledInScope: true },
15
{ id: "cls-5" },
16
{ id: "cls-6" },
17
{ id: "cls-7" },
18
] as any;
19
type ArgsType = Parameters<typeof getNextDefaultClass>;
20
const testCases: {
21
args: ArgsType;
22
expected: ReturnType<typeof getNextDefaultClass>;
23
}[] = [
24
{ args: [allClasses, undefined], expected: undefined },
25
{ args: [allClasses, "cls-2"], expected: "cls-1" },
26
{ args: [allClasses, "cls-4"], expected: "cls-3" },
27
{ args: [allClasses, "cls-5"], expected: "cls-5" },
28
{ args: [[], "cls-3"], expected: undefined },
29
{ args: [allClasses.map((e) => ({ ...e, isDisabledInScope: true })), "cls-3"], expected: undefined },
30
];
31
32
for (const t of testCases) {
33
const actual = getNextDefaultClass(...t.args);
34
expect(actual).toBe(t.expected);
35
}
36
});
37
38