|
1 | 1 | importtype{Page}from"@playwright/test";
|
2 | 2 | import{expect}from"@playwright/test";
|
3 | 3 | import*asAPIfrom"api/api";
|
| 4 | +importtype{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 | returngroup;
|
50 | 51 | };
|
51 | 52 |
|
52 |
| -exportasyncfunctionverifyConfigFlag( |
| 53 | +exportasyncfunctionverifyConfigFlagBoolean( |
53 | 54 | page:Page,
|
54 | 55 | config:API.DeploymentConfig,
|
55 | 56 | flag:string,
|
56 | 57 | ){
|
57 |
| -constopt=config.options.find((option)=>option.flag===flag); |
58 |
| -if(opt===undefined){ |
59 |
| -// must be undefined as `false` is expected |
60 |
| -thrownewError(`Option with env${flag} has undefined value.`); |
61 |
| -} |
| 58 | +constopt=findConfigOption(config,flag); |
| 59 | +consttype=opt.value ?"option-enabled" :"option-disabled"; |
| 60 | +constvalue=opt.value ?"Enabled" :"Disabled"; |
62 | 61 |
|
63 |
| -// Map option type to test class name. |
64 |
| -lettype:string; |
65 |
| -letvalue=opt.value; |
| 62 | +constconfigOption=page.locator( |
| 63 | +`div.options-table .option-${flag} .${type}`, |
| 64 | +); |
| 65 | +awaitexpect(configOption).toHaveText(value); |
| 66 | +} |
66 | 67 |
|
67 |
| -if(typeofvalue==="boolean"){ |
68 |
| -// Boolean options map to string (Enabled/Disabled). |
69 |
| -type=value ?"option-enabled" :"option-disabled"; |
70 |
| -value=value ?"Enabled" :"Disabled"; |
71 |
| -}elseif(typeofvalue==="number"){ |
72 |
| -type="option-value-number"; |
73 |
| -value=String(value); |
74 |
| -}elseif(!value||value.length===0){ |
75 |
| -type="option-value-empty"; |
76 |
| -}elseif(typeofvalue==="string"){ |
77 |
| -type="option-value-string"; |
78 |
| -}elseif(typeofvalue==="object"){ |
79 |
| -type="option-array"; |
80 |
| -}else{ |
81 |
| -type="option-value-json"; |
82 |
| -} |
| 68 | +exportasyncfunctionverifyConfigFlagNumber( |
| 69 | +page:Page, |
| 70 | +config:API.DeploymentConfig, |
| 71 | +flag:string, |
| 72 | +){ |
| 73 | +constopt=findConfigOption(config,flag); |
| 74 | +constconfigOption=page.locator( |
| 75 | +`div.options-table .option-${flag} .option-value-number`, |
| 76 | +); |
| 77 | +awaitexpect(configOption).toHaveText(String(opt.value)); |
| 78 | +} |
| 79 | + |
| 80 | +exportasyncfunctionverifyConfigFlagString( |
| 81 | +page:Page, |
| 82 | +config:API.DeploymentConfig, |
| 83 | +flag:string, |
| 84 | +){ |
| 85 | +constopt=findConfigOption(config,flag); |
| 86 | + |
| 87 | +constconfigOption=page.locator( |
| 88 | +`div.options-table .option-${flag} .option-value-string`, |
| 89 | +); |
| 90 | +awaitexpect(configOption).toHaveText(opt.value); |
| 91 | +} |
| 92 | + |
| 93 | +exportasyncfunctionverifyConfigFlagArray( |
| 94 | +page:Page, |
| 95 | +config:API.DeploymentConfig, |
| 96 | +flag:string, |
| 97 | +){ |
| 98 | +constopt=findConfigOption(config,flag); |
| 99 | +constconfigOption=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(constitemofopt.value){ |
| 105 | +awaitexpect(configOption.locator("li",{hasText:item})).toBeVisible(); |
88 | 106 | }
|
| 107 | +} |
89 | 108 |
|
| 109 | +exportasyncfunctionverifyConfigFlagEntries( |
| 110 | +page:Page, |
| 111 | +config:API.DeploymentConfig, |
| 112 | +flag:string, |
| 113 | +){ |
| 114 | +constopt=findConfigOption(config,flag); |
90 | 115 | constconfigOption=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(typeofvalue==="object"&&!Array.isArray(value)){ |
96 |
| -Object.entries(value) |
97 |
| -.sort((a,b)=>a[0].localeCompare(b[0])) |
98 |
| -.map(async([item])=>{ |
99 |
| -awaitexpect( |
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(constitemofvalue){ |
110 |
| -awaitexpect(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 | +awaitexpect( |
| 124 | +configOption.locator(`.option-array-item-${item}.option-enabled`,{ |
| 125 | +hasText:item, |
| 126 | +}), |
| 127 | +).toBeVisible(); |
| 128 | +}); |
| 129 | +} |
| 130 | + |
| 131 | +exportfunctionfindConfigOption( |
| 132 | +config:API.DeploymentConfig, |
| 133 | +flag:string, |
| 134 | +):SerpentOption{ |
| 135 | +constopt=config.options.find((option)=>option.flag===flag); |
| 136 | +if(opt===undefined){ |
| 137 | +// must be undefined as `false` is expected |
| 138 | +thrownewError(`Option with env${flag} has undefined value.`); |
113 | 139 | }
|
114 |
| -awaitexpect(configOption).toHaveText(String(value)); |
| 140 | +returnopt; |
115 | 141 | }
|