Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions frontend/e2e/clients/kubernetes-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,97 @@ export default class KubernetesClient {
} as any);
}

async createConfigMap(
name: string,
namespace: string,
data: Record<string, string> = {},
): Promise<void> {
await this.k8sApi.createNamespacedConfigMap({
namespace,
body: { apiVersion: 'v1', kind: 'ConfigMap', metadata: { name, namespace }, data },
});
}

async createSecret(
name: string,
namespace: string,
data: Record<string, string> = {},
): Promise<void> {
await this.k8sApi.createNamespacedSecret({
namespace,
body: { apiVersion: 'v1', kind: 'Secret', metadata: { name, namespace }, data },
});
}

async mergePatchResource(apiPath: string, patch: object): Promise<void> {
const opts: https.RequestOptions = {};
this.kubeConfig.applyToHTTPSOptions(opts);
const cluster = this.kubeConfig.getCurrentCluster();
const url = new URL(apiPath, cluster?.server);
const body = JSON.stringify(patch);
const proxyUrl = KubernetesClient.getProxyUrl();
const agent = proxyUrl ? KubernetesClient.createProxyAgent(proxyUrl) : undefined;
await new Promise<void>((resolve, reject) => {
const req = https.request(
{
hostname: url.hostname,
port: url.port || 443,
path: url.pathname,
method: 'PATCH',
headers: {
'Content-Type': 'application/merge-patch+json',
'Content-Length': Buffer.byteLength(body),
...opts.headers,
},
rejectUnauthorized: false,
ca: opts.ca,
cert: opts.cert,
key: opts.key,
agent,
},
(res) => {
let data = '';
res.on('data', (chunk) => (data += chunk));
res.on('end', () => {
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
resolve();
} else {
reject(new Error(`Patch failed: ${res.statusCode} ${data}`));
}
});
},
);
req.setTimeout(30_000, () => {
req.destroy(new Error('mergePatchResource request timed out after 30s'));
});
req.on('error', reject);
req.write(body);
req.end();
});
}

async annotateConfigMap(
name: string,
namespace: string,
annotations: Record<string, string | null>,
): Promise<void> {
await this.mergePatchResource(
`/api/v1/namespaces/${namespace}/configmaps/${name}`,
{ metadata: { annotations } },
);
}

async labelConfigMap(
name: string,
namespace: string,
labels: Record<string, string | null>,
): Promise<void> {
await this.mergePatchResource(
`/api/v1/namespaces/${namespace}/configmaps/${name}`,
{ metadata: { labels } },
);
}

async deleteConfigMap(name: string, namespace: string): Promise<void> {
try {
await this.k8sApi.deleteNamespacedConfigMap({ name, namespace });
Expand Down Expand Up @@ -435,6 +526,36 @@ export default class KubernetesClient {
}
}

async createClusterCustomResource(
group: string,
version: string,
plural: string,
body: Record<string, unknown>,
): Promise<unknown> {
const response = await this.coApi.createClusterCustomObject({
body,
group,
plural,
version,
});
return response;
}

async deleteClusterCustomResource(
group: string,
version: string,
plural: string,
name: string,
): Promise<void> {
try {
await this.coApi.deleteClusterCustomObject({ group, name, plural, version });
} catch (err) {
if (!isNotFound(err)) {
throw err;
}
}
}

async getCustomResource(
group: string,
version: string,
Expand Down
30 changes: 30 additions & 0 deletions frontend/e2e/fixtures/cleanup-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export interface CleanupFixture {
plural: string,
type?: string,
): void;
trackClusterCustomResource(
name: string,
apiGroup: string,
apiVersion: string,
plural: string,
type?: string,
): void;
readonly count: number;
executeCleanup(): Promise<void>;
shouldSkipCleanup(): boolean;
Expand Down Expand Up @@ -95,6 +102,22 @@ export function createCleanupFixture(testName: string): CleanupFixture {
});
},

trackClusterCustomResource(
name: string,
apiGroup: string,
apiVersion: string,
plural: string,
type?: string,
) {
resources.push({
name,
apiGroup,
apiVersion,
plural,
type: type || plural,
});
},

get count() {
return resources.length;
},
Expand Down Expand Up @@ -142,6 +165,13 @@ export function createCleanupFixture(testName: string): CleanupFixture {
resource.plural,
resource.name,
);
} else if (resource.apiGroup) {
await client.deleteClusterCustomResource(
resource.apiGroup,
resource.apiVersion,
resource.plural,
resource.name,
);
}
} catch (error) {
const msg = error instanceof Error ? error.message : String(error);
Expand Down
13 changes: 2 additions & 11 deletions frontend/e2e/pages/alertmanager-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,11 @@ export class AlertmanagerPage extends BasePage {
}

async getYAMLContent(): Promise<string> {
// Get content from Monaco editor
const content = await this.page.evaluate(() => {
const monacoEditor = (window as any).monaco?.editor?.getModels()?.[0];
return monacoEditor?.getValue() || '';
});

return content;
return this.getEditorContent();
}

async setYAMLContent(content: string): Promise<void> {
await this.page.evaluate((text) => {
const monacoEditor = (window as any).monaco?.editor?.getModels()?.[0];
monacoEditor?.setValue(text);
}, content);
await this.setEditorContent(content);
}

async validateReceiverInList(receiverName: string): Promise<void> {
Expand Down
26 changes: 26 additions & 0 deletions frontend/e2e/pages/base-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import type { Locator, Page } from '@playwright/test';

export async function getEditorContent(page: Page): Promise<string> {
await page.waitForFunction(() => (window as any).monaco?.editor?.getModels()?.[0], {
timeout: 10_000,
});
return page.evaluate(() => {
return (window as any).monaco.editor.getModels()[0].getValue();
});
}

export async function setEditorContent(page: Page, content: string): Promise<void> {
await page.waitForFunction(() => (window as any).monaco?.editor?.getModels()?.[0], {
timeout: 10_000,
});
await page.evaluate((text) => {
(window as any).monaco.editor.getModels()[0].setValue(text);
}, content);
}

export default abstract class BasePage {
constructor(public readonly page: Page) {}

Expand Down Expand Up @@ -97,6 +115,14 @@ export default abstract class BasePage {
await this.robustClick(button);
}

async getEditorContent(): Promise<string> {
return getEditorContent(this.page);
}

async setEditorContent(content: string): Promise<void> {
await setEditorContent(this.page, content);
}

async switchPerspective(target: 'Developer' | 'Administrator'): Promise<void> {
const labelMap: Record<string, string[]> = {
Administrator: ['Administrator', 'Core platform'],
Expand Down
11 changes: 10 additions & 1 deletion frontend/e2e/pages/details-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export class DetailsPage extends BasePage {
return this.pageHeading;
}

async clickPageAction(actionName: string): Promise<void> {
await this.robustClick(this.page.getByTestId('actions-menu-button'));
await this.robustClick(this.page.getByTestId(actionName));
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

getBreadcrumb(index: number): Locator {
return this.page.getByTestId(`breadcrumb-link-${index}`);
}

/**
* Select a specific tab by name
*/
Expand All @@ -41,7 +50,7 @@ export class DetailsPage extends BasePage {
* Click a kebab menu action (assumes menu is already open)
*/
async clickKebabAction(actionId: string): Promise<void> {
const action = this.page.locator(`[data-test-action="${actionId}"]`);
const action = this.page.getByTestId(actionId);
await action.waitFor({ state: 'visible', timeout: 10_000 });
await this.robustClick(action);
}
Expand Down
Loading