|
1 | 1 | import type { Page } from "@playwright/test";
|
2 | 2 | import { expect } from "@playwright/test";
|
3 | 3 | import * as API from "api/api";
|
| 4 | +import type { SerpentOption } from "api/typesGenerated"; |
4 | 5 | import { coderPort } from "./constants";
|
5 | 6 | import { findSessionToken, randomName } from "./helpers";
|
6 | 7 |
|
@@ -49,67 +50,92 @@ export const createGroup = async (orgId: string) => {
|
49 | 50 | return group;
|
50 | 51 | };
|
51 | 52 |
|
52 |
| -export async function verifyConfigFlag( |
| 53 | +export async function verifyConfigFlagBoolean( |
53 | 54 | page: Page,
|
54 | 55 | config: API.DeploymentConfig,
|
55 | 56 | flag: string,
|
56 | 57 | ) {
|
57 |
| - const opt = config.options.find((option) => option.flag === flag); |
58 |
| - if (opt === undefined) { |
59 |
| - // must be undefined as `false` is expected |
60 |
| - throw new Error(`Option with env ${flag} has undefined value.`); |
61 |
| - } |
| 58 | + const opt = findConfigOption(config, flag); |
| 59 | + const type = opt.value ? "option-enabled" : "option-disabled"; |
| 60 | + const value = opt.value ? "Enabled" : "Disabled"; |
62 | 61 |
|
63 |
| - // Map option type to test class name. |
64 |
| - let type: string; |
65 |
| - let value = opt.value; |
| 62 | + const configOption = page.locator( |
| 63 | + `div.options-table .option-${flag} .${type}`, |
| 64 | + ); |
| 65 | + await expect(configOption).toHaveText(value); |
| 66 | +} |
66 | 67 |
|
67 |
| - if (typeof value === "boolean") { |
68 |
| - // Boolean options map to string (Enabled/Disabled). |
69 |
| - type = value ? "option-enabled" : "option-disabled"; |
70 |
| - value = value ? "Enabled" : "Disabled"; |
71 |
| - } else if (typeof value === "number") { |
72 |
| - type = "option-value-number"; |
73 |
| - value = String(value); |
74 |
| - } else if (!value || value.length === 0) { |
75 |
| - type = "option-value-empty"; |
76 |
| - } else if (typeof value === "string") { |
77 |
| - type = "option-value-string"; |
78 |
| - } else if (typeof value === "object") { |
79 |
| - type = "option-array"; |
80 |
| - } else { |
81 |
| - type = "option-value-json"; |
82 |
| - } |
| 68 | +export async function verifyConfigFlagNumber( |
| 69 | + page: Page, |
| 70 | + config: API.DeploymentConfig, |
| 71 | + flag: string, |
| 72 | +) { |
| 73 | + const opt = findConfigOption(config, flag); |
| 74 | + const configOption = page.locator( |
| 75 | + `div.options-table .option-${flag} .option-value-number`, |
| 76 | + ); |
| 77 | + await expect(configOption).toHaveText(String(opt.value)); |
| 78 | +} |
| 79 | + |
| 80 | +export async function verifyConfigFlagString( |
| 81 | + page: Page, |
| 82 | + config: API.DeploymentConfig, |
| 83 | + flag: string, |
| 84 | +) { |
| 85 | + const opt = findConfigOption(config, flag); |
| 86 | + |
| 87 | + const configOption = page.locator( |
| 88 | + `div.options-table .option-${flag} .option-value-string`, |
| 89 | + ); |
| 90 | + await expect(configOption).toHaveText(opt.value); |
| 91 | +} |
| 92 | + |
| 93 | +export async function verifyConfigFlagArray( |
| 94 | + page: Page, |
| 95 | + config: API.DeploymentConfig, |
| 96 | + flag: string, |
| 97 | +) { |
| 98 | + const opt = findConfigOption(config, flag); |
| 99 | + const configOption = page.locator( |
| 100 | + `div.options-table .option-${flag} .option-array`, |
| 101 | + ); |
83 | 102 |
|
84 |
| - // Special cases |
85 |
| - if (opt.flag === "strict-transport-security" && opt.value === 0) { |
86 |
| - type = "option-value-string"; |
87 |
| - value = "Disabled"; // Display "Disabled" instead of zero seconds. |
| 103 | + // Verify array of options with simple dots |
| 104 | + for (const item of opt.value) { |
| 105 | + await expect(configOption.locator("li", { hasText: item })).toBeVisible(); |
88 | 106 | }
|
| 107 | +} |
89 | 108 |
|
| 109 | +export async function verifyConfigFlagEntries( |
| 110 | + page: Page, |
| 111 | + config: API.DeploymentConfig, |
| 112 | + flag: string, |
| 113 | +) { |
| 114 | + const opt = findConfigOption(config, flag); |
90 | 115 | const configOption = page.locator(
|
91 |
| - `div.options-table .option-${flag} .${type}`, |
| 116 | + `div.options-table .option-${flag} .option-array`, |
92 | 117 | );
|
93 | 118 |
|
94 | 119 | // Verify array of options with green marks.
|
95 |
| - if (typeof value === "object" && !Array.isArray(value)) { |
96 |
| - Object.entries(value) |
97 |
| - .sort((a, b) => a[0].localeCompare(b[0])) |
98 |
| - .map(async ([item]) => { |
99 |
| - await expect( |
100 |
| - configOption.locator(`.option-array-item-${item}.option-enabled`, { |
101 |
| - hasText: item, |
102 |
| - }), |
103 |
| - ).toBeVisible(); |
104 |
| - }); |
105 |
| - return; |
106 |
| - } |
107 |
| - // Verify array of options with simmple dots |
108 |
| - if (Array.isArray(value)) { |
109 |
| - for (const item of value) { |
110 |
| - await expect(configOption.locator("li", { hasText: item })).toBeVisible(); |
111 |
| - } |
112 |
| - return; |
| 120 | + Object.entries(opt.value) |
| 121 | + .sort((a, b) => a[0].localeCompare(b[0])) |
| 122 | + .map(async ([item]) => { |
| 123 | + await expect( |
| 124 | + configOption.locator(`.option-array-item-${item}.option-enabled`, { |
| 125 | + hasText: item, |
| 126 | + }), |
| 127 | + ).toBeVisible(); |
| 128 | + }); |
| 129 | +} |
| 130 | + |
| 131 | +export function findConfigOption( |
| 132 | + config: API.DeploymentConfig, |
| 133 | + flag: string, |
| 134 | +): SerpentOption { |
| 135 | + const opt = config.options.find((option) => option.flag === flag); |
| 136 | + if (opt === undefined) { |
| 137 | + // must be undefined as `false` is expected |
| 138 | + throw new Error(`Option with env ${flag} has undefined value.`); |
113 | 139 | }
|
114 |
| - await expect(configOption).toHaveText(String(value)); |
| 140 | + return opt; |
115 | 141 | }
|
0 commit comments