Skip to content

Commit 07c1452

Browse files
authored
test(argocd): add playwright dev mode tests (janus-idp#1616)
1 parent 2892709 commit 07c1452

File tree

6 files changed

+280
-16
lines changed

6 files changed

+280
-16
lines changed

plugins/argocd/dev/__data__/applications.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export const preProdApplication = {
146146
},
147147
{
148148
name: 'environment',
149-
value: 'dev',
149+
value: 'preprod',
150150
},
151151
{
152152
name: 'image.tag',
@@ -156,7 +156,7 @@ export const preProdApplication = {
156156
},
157157
path: './helm/app',
158158
repoURL:
159-
'https://gitlab-gitlab.apps.cluster.test.com/development/quarkus-app-gitops.git',
159+
'https://gitlab-gitlab.apps.cluster.test.com/preprod/quarkus-app-gitops.git',
160160
targetRevision: 'HEAD',
161161
},
162162
},
@@ -168,7 +168,7 @@ export const preProdApplication = {
168168
id: 0,
169169
source: {
170170
repoURL:
171-
'https://gitlab-gitlab.apps.cluster.test.com/development/quarkus-app-gitops.git',
171+
'https://gitlab-gitlab.apps.cluster.test.com/preprod/quarkus-app-gitops.git',
172172
path: './helm/app',
173173
targetRevision: 'HEAD',
174174
helm: {
@@ -179,7 +179,7 @@ export const preProdApplication = {
179179
},
180180
{
181181
name: 'environment',
182-
value: 'dev',
182+
value: 'preprod',
183183
},
184184
{
185185
name: 'image.tag',
@@ -196,7 +196,7 @@ export const preProdApplication = {
196196
id: 1,
197197
source: {
198198
repoURL:
199-
'https://gitlab-gitlab.apps.cluster.test.com/development/quarkus-app-gitops.git',
199+
'https://gitlab-gitlab.apps.cluster.test.com/preprod/quarkus-app-gitops.git',
200200
path: './helm/app',
201201
targetRevision: 'HEAD',
202202
helm: {
@@ -207,7 +207,7 @@ export const preProdApplication = {
207207
},
208208
{
209209
name: 'environment',
210-
value: 'dev',
210+
value: 'preprod',
211211
},
212212
{
213213
name: 'image.tag',
@@ -268,7 +268,7 @@ export const prodApplication = {
268268
},
269269
{
270270
name: 'environment',
271-
value: 'dev',
271+
value: 'prod',
272272
},
273273
{
274274
name: 'image.tag',
@@ -278,7 +278,7 @@ export const prodApplication = {
278278
},
279279
path: './helm/app',
280280
repoURL:
281-
'https://gitlab-gitlab.apps.cluster.test.com/development/quarkus-app-gitops.git',
281+
'https://gitlab-gitlab.apps.cluster.test.com/prod/quarkus-app-gitops.git',
282282
targetRevision: 'HEAD',
283283
},
284284
},
@@ -290,7 +290,7 @@ export const prodApplication = {
290290
id: 0,
291291
source: {
292292
repoURL:
293-
'https://gitlab-gitlab.apps.cluster.test.com/development/quarkus-app-gitops.git',
293+
'https://gitlab-gitlab.apps.cluster.test.com/prod/quarkus-app-gitops.git',
294294
path: './helm/app',
295295
targetRevision: 'HEAD',
296296
helm: {
@@ -301,7 +301,7 @@ export const prodApplication = {
301301
},
302302
{
303303
name: 'environment',
304-
value: 'dev',
304+
value: 'prod',
305305
},
306306
{
307307
name: 'image.tag',
@@ -318,7 +318,7 @@ export const prodApplication = {
318318
id: 1,
319319
source: {
320320
repoURL:
321-
'https://gitlab-gitlab.apps.cluster.test.com/development/quarkus-app-gitops.git',
321+
'https://gitlab-gitlab.apps.cluster.test.com/prod/quarkus-app-gitops.git',
322322
path: './helm/app',
323323
targetRevision: 'HEAD',
324324
helm: {
@@ -329,7 +329,7 @@ export const prodApplication = {
329329
},
330330
{
331331
name: 'environment',
332-
value: 'dev',
332+
value: 'prod',
333333
},
334334
{
335335
name: 'image.tag',

plugins/argocd/dev/__data__/config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { Config } from '@kubernetes/client-node';
2-
3-
export const mockArgocdConfig: Config = {
1+
export const mockArgocdConfig = {
42
argocd: {
53
baseUrl: 'https://localhost:8080',
64
appLocatorMethods: [

plugins/argocd/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"prepack": "backstage-cli package prepack",
2424
"start": "backstage-cli package start",
2525
"test": "backstage-cli package test --passWithNoTests --coverage",
26-
"tsc": "tsc"
26+
"tsc": "tsc",
27+
"ui-test": "yarn playwright test"
2728
},
2829
"dependencies": {
2930
"@backstage/catalog-model": "^1.4.4",
@@ -54,6 +55,7 @@
5455
"@backstage/dev-utils": "1.0.30",
5556
"@backstage/test-utils": "1.5.3",
5657
"@janus-idp/cli": "1.8.5",
58+
"@playwright/test": "1.41.2",
5759
"@testing-library/jest-dom": "6.0.0",
5860
"@testing-library/react": "14.0.0",
5961
"@testing-library/user-event": "14.0.0",

plugins/argocd/playwright.config.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* See https://playwright.dev/docs/test-configuration.
5+
*/
6+
export default defineConfig({
7+
testDir: './tests',
8+
/* Run tests in files in parallel */
9+
fullyParallel: true,
10+
/* Fail the build on CI if you accidentally left test.only in the source code. */
11+
forbidOnly: !!process.env.CI,
12+
/* Retry on CI only */
13+
retries: process.env.CI ? 2 : 0,
14+
/* Run tests in sequence. */
15+
workers: 1,
16+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
17+
reporter: 'html',
18+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
19+
use: {
20+
baseURL: process.env.PLUGIN_BASE_URL || 'http://localhost:3000',
21+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
22+
trace: 'on-first-retry',
23+
screenshot: 'only-on-failure',
24+
video: 'retain-on-failure',
25+
},
26+
27+
/* Configure projects for major browsers */
28+
projects: [
29+
{
30+
name: 'chromium',
31+
use: { ...devices['Desktop Chrome'] },
32+
},
33+
],
34+
});

plugins/argocd/tests/argocd.spec.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { expect, Page, test } from '@playwright/test';
2+
3+
import {
4+
mockApplication,
5+
preProdApplication,
6+
prodApplication,
7+
} from '../dev/__data__';
8+
import { verifyAppCard, verifyAppSidebar } from './utils';
9+
10+
test.describe('ArgoCD plugin', () => {
11+
let page: Page;
12+
13+
test.beforeAll(async ({ browser }) => {
14+
const context = await browser.newContext();
15+
page = await context.newPage();
16+
await page.goto('/');
17+
await expect(
18+
page.getByRole('heading', { name: 'Deployment lifecycle' }),
19+
).toBeVisible({ timeout: 20000 });
20+
});
21+
22+
test.afterAll(async ({ browser }) => {
23+
await browser.close();
24+
});
25+
26+
const apps = [mockApplication, preProdApplication, prodApplication];
27+
28+
test.describe('Deployment lifecycle', () => {
29+
for (const [index, app] of apps.entries()) {
30+
/* eslint-disable-next-line no-loop-func */
31+
test(`Verify ${app.metadata.name} card`, async () => {
32+
const card = page.getByTestId(`${app.metadata.name}-card`);
33+
await expect(card).toBeVisible();
34+
await verifyAppCard(app, card, index);
35+
});
36+
37+
/* eslint-disable-next-line no-loop-func */
38+
test(`Verify ${app.metadata.name} side bar`, async () => {
39+
await page.getByTestId(`${app.metadata.name}-card`).click();
40+
const sideBar = page.locator(`.MuiDrawer-paper`);
41+
await expect(sideBar).toBeVisible();
42+
await verifyAppSidebar(app, sideBar, index);
43+
await sideBar.getByRole('button', { name: 'Close the drawer' }).click();
44+
await expect(sideBar).toBeVisible({ visible: false });
45+
});
46+
}
47+
});
48+
49+
test.describe('Summary', () => {
50+
const columns = [
51+
'ArgoCD App',
52+
'Namespace',
53+
'Instance',
54+
'Server',
55+
'Revision',
56+
'Last Deployed',
57+
'Sync Status',
58+
'Health Status',
59+
];
60+
61+
test.beforeAll(async () => {
62+
await page.getByRole('link', { name: 'Summary' }).click();
63+
await expect(page.getByRole('heading')).toHaveText('Deployment summary');
64+
});
65+
66+
test('Verify column names', async () => {
67+
for (const col of columns) {
68+
await expect(
69+
page.getByRole('columnheader', { name: col }),
70+
).toBeVisible();
71+
}
72+
});
73+
74+
for (const app of apps) {
75+
const appName = app.metadata.name;
76+
77+
/* eslint-disable-next-line no-loop-func */
78+
test(`Verify ${appName} row`, async () => {
79+
const row = page.locator('.MuiTableRow-root', { hasText: appName });
80+
const revision = app.status.history
81+
?.slice(-1)[0]
82+
.revision.substring(0, 7);
83+
84+
await expect(
85+
row.locator('td', { hasText: app.metadata.instance.name }),
86+
).toBeVisible();
87+
await expect(
88+
row.locator('td', { hasText: app.spec.destination.server }),
89+
).toBeVisible();
90+
await expect(row.locator('td', { hasText: revision })).toBeVisible();
91+
await expect(
92+
row.locator('td', { hasText: app.status.health.status }),
93+
).toBeVisible();
94+
await expect(
95+
row.locator('td', { hasText: app.status.sync.status }),
96+
).toBeVisible();
97+
});
98+
}
99+
});
100+
});

0 commit comments

Comments
 (0)