Skip to content

Commit

Permalink
added tests for validations
Browse files Browse the repository at this point in the history
  • Loading branch information
matejnesuta committed Jun 5, 2024
1 parent 9b6a496 commit 2d09fc5
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 6 deletions.
4 changes: 2 additions & 2 deletions plugins/kiali/dev/__fixtures__/general/istioValidations.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
},
"travel-control": {
"errors": 0,
"objectCount": 0,
"warnings": 0
"objectCount": 1,
"warnings": 1
},
"travel-portal": {
"errors": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"desiredReplicas": 1,
"currentReplicas": 1,
"availableReplicas": 1,
"syncedProxies": 1
"syncedProxies": 0
}
],
"requests": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "control",
"desiredReplicas": 1,
"currentReplicas": 1,
"currentReplicas": 0,
"availableReplicas": 1,
"syncedProxies": 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const ValidationSummary = (props: Props) => {
return (
<Tooltip
aria-label="Validations list"
data-test={`validation-icon-${severity()}`}
placement="right"
title={tooltipContent()}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const OverviewCard = (props: OverviewCardProps) => {
errors={validations.errors}
warnings={validations.warnings}
objectCount={validations.objectCount}
data-test={'validation-summary'}
/>
);
};
Expand Down
6 changes: 4 additions & 2 deletions plugins/kiali/src/pages/Overview/OverviewStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export class OverviewStatus extends React.Component<Props, {}> {
items.push(`and ${length - items.length} more...`);
}
const tooltipContent = (
<div>
<strong>{this.props.status.name}</strong>
<div data-test={'overview-status'}>
<strong data-test={`${this.props.status.name}-status`}>
{this.props.status.name}
</strong>
{items.map((app, idx) => {
return (
<div
Expand Down
111 changes: 111 additions & 0 deletions plugins/kiali/tests/kialiPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@ import { Common, kialiData } from './kialiHelper';
const CONFIG = kialiData.config;
const NAMESPACES = kialiData.namespaces;
const STATUS = kialiData.status;
const BOOKINFO_APPS = kialiData.apps.bookinfo;
const BOOKINFO_SERVICES = kialiData.services.bookinfo;
const BOOKINFO_WORKLOADS = kialiData.workloads.bookinfo;

async function checkReportedItems(
type: string,
ns: string,
objects: any,
page: any,
): Promise<void> {
const ns_card = await page.locator(`data-test=overview-card-${ns}`);
await page.click('[aria-label="Health for"]');
await page.click(`[data-value=${type}]`);

const icon = await ns_card.locator('data-test=overview-app-health');
await icon.hover();
let list = await page.locator('data-test=overview-status');

// Wait for the list to appear
await page.waitForSelector('data-test=overview-status');

let i = 0;
for (const object of Object.entries(objects)) {
if (i == 5) {
break;
}
await icon.hover({ force: true }).then(async () => {
await expect(list).toContainText(`${object[1].name}`);
});
i++;
}
let expected = type == 'app' ? 'application' : type;
await expect(
ns_card.locator(`data-test=overview-type-${type}`),
).toContainText(`${Object.entries(objects).length} ${expected}s`);
}

function filterByIstioInjectionEnabled(jsonArray: any): any {
return jsonArray.filter(
Expand Down Expand Up @@ -188,5 +224,80 @@ test.describe('Kiali page', () => {
`${Object.entries(ns.labels).length} labels`,
);
});

test('Apps should be reported in the namespace card', async () => {
const ns = BOOKINFO_APPS.namespace.name;
await checkReportedItems('app', ns, BOOKINFO_APPS.applications, page);
});

test('Services should be reported in the namespace card', async () => {
const ns = BOOKINFO_SERVICES.namespace.name;
await checkReportedItems('service', ns, BOOKINFO_SERVICES.services, page);
});

test('Workloads should be reported in the namespace card', async () => {
const ns = BOOKINFO_WORKLOADS.namespace.name;
await checkReportedItems(
'workload',
ns,
BOOKINFO_WORKLOADS.workloads,
page,
);
});

test('Healthy apps should be reported in the namespace card', async () => {
const ns_card = await page.locator(`data-test=overview-card-bookinfo`);
const icon = await ns_card.locator('data-test=overview-app-health');
await icon.hover();
await page.waitForSelector('data-test=overview-status');
await expect(ns_card.locator('data-test=Healthy-status')).toBeDefined();
});

test('Degraded apps should be reported in the namespace card', async () => {
const ns_card = await page.locator(
`data-test=overview-card-travel-agency`,
);
const icon = await ns_card
.locator('[aria-label="Overview status"]')
.first();
await icon.hover();
await page.waitForSelector('data-test=overview-status');
await expect(ns_card.locator('data-test=Degraded-status')).toBeDefined();
});

test('Failed apps should be reported in the namespace card', async () => {
const ns_card = await page.locator(
`data-test=overview-card-travel-control`,
);
const icon = await ns_card.locator('[aria-label="Overview status"]');
await icon.hover();
await page.waitForSelector('data-test=overview-status');
await expect(ns_card.locator('data-test=Failure-status')).toBeDefined();
});

test('Istio config with success should be reported in the namespace card', async () => {
const ns_card = await page.locator(
`data-test=overview-card-travel-agency`,
);
await expect(
ns_card.locator('data-test=validation-icon-correct'),
).toBeVisible();
});

test('Istio config with warning should be reported in the namespace card', async () => {
const ns_card = await page.locator(
`data-test=overview-card-travel-control`,
);
await expect(
ns_card.locator('data-test=validation-icon-warning'),
).toBeVisible();
});

test('Istio config with error should be reported in the namespace card', async () => {
const ns_card = await page.locator(`data-test=overview-card-bookinfo`);
await expect(
ns_card.locator('data-test=validation-icon-error'),
).toBeVisible();
});
});
});

0 comments on commit 2d09fc5

Please sign in to comment.