Skip to content

Commit 9fd07aa

Browse files
authored
RHIDP-2065: [QE] Automate Scenario - Telemetry (#1268)
* RHIDP-2065: [QE] Automate Scenario - Telemetry * Add skip to RBAC test, TODO * Revert "Add skip to RBAC test, TODO" This reverts commit 1c1d07c. * Add guest login for RBAC * Fix beforeEach * GithubUser * Update analytics-disabled-rbac.spec.ts * Update analytics-disabled-rbac.spec.ts * Verify plugin disabled RBAC in UI * Fix before each * Move to APIHelper
1 parent b827983 commit 9fd07aa

File tree

6 files changed

+95
-3
lines changed

6 files changed

+95
-3
lines changed

.ibm/pipelines/value_files/values_showcase-rbac.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ global:
9898
disabled: false
9999
- package: ./dynamic-plugins/dist/janus-idp-backstage-plugin-rbac
100100
disabled: false
101+
- package: './dynamic-plugins/dist/janus-idp-backstage-plugin-analytics-provider-segment'
102+
disabled: true
101103

102104

103105
# this value will be overriden by 'helm install .... --set global.clusterRouterBase=value'

e2e-tests/playwright.config.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ export default defineConfig({
4141
{
4242
name: 'showcase',
4343
use: { ...devices['Desktop Chrome'] },
44-
testIgnore: '**/playwright/e2e/plugins/rbac/**/*.spec.ts',
44+
testIgnore: [
45+
'**/playwright/e2e/plugins/rbac/**/*.spec.ts',
46+
'**/playwright/e2e/plugins/analytics/analytics-disabled-rbac.spec.ts',
47+
],
4548
},
4649
{
4750
name: 'showcase-rbac',
4851
use: { ...devices['Desktop Chrome'] },
49-
testMatch: '**/playwright/e2e/plugins/rbac/**/*.spec.ts',
52+
testMatch: [
53+
'**/playwright/e2e/plugins/rbac/**/*.spec.ts',
54+
'**/playwright/e2e/plugins/analytics/analytics-disabled-rbac.spec.ts',
55+
],
5056
},
5157

5258
// {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { test, expect } from '@playwright/test';
2+
import { Common } from '../../../utils/Common';
3+
import { UIhelper } from '../../../utils/UIhelper';
4+
import { UIhelperPO } from '../../../support/pageObjects/global-obj';
5+
6+
test.describe('Check RBAC "analytics-provider-segment" plugin', () => {
7+
let common: Common;
8+
let uiHelper: UIhelper;
9+
10+
test.beforeEach(async ({ page }) => {
11+
uiHelper = new UIhelper(page);
12+
common = new Common(page);
13+
await common.loginAsGithubUser();
14+
await uiHelper.openSidebar('Administration');
15+
await uiHelper.verifyHeading('Administration');
16+
await uiHelper.verifyLink('Plugins');
17+
await uiHelper.clickTab('Plugins');
18+
});
19+
20+
test('is disabled', async ({ page }) => {
21+
await page
22+
.getByPlaceholder('Filter')
23+
.pressSequentially('backstage-plugin-analytics-provider-segment\n', {
24+
delay: 300,
25+
});
26+
const row = await page.locator(
27+
UIhelperPO.rowByText(
28+
'@janus-idp/backstage-plugin-analytics-provider-segment',
29+
),
30+
);
31+
expect(await row.locator('td').nth(2).innerText()).toBe('No'); // not enabled
32+
});
33+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { test, expect } from '@playwright/test';
2+
import { Analytics } from '../../../utils/analytics/analytics';
3+
import { APIHelper } from '../../../utils/APIHelper';
4+
5+
test('Check "analytics-provider-segment" plugin is enabled', async () => {
6+
const analytics = new Analytics();
7+
const apihelper = new APIHelper();
8+
9+
const authHeader = await apihelper.getGuestAuthHeader();
10+
const pluginsList = await analytics.getDynamicPluginsList(authHeader);
11+
const isPluginListed = analytics.checkPluginListed(
12+
pluginsList,
13+
'@janus-idp/backstage-plugin-analytics-provider-segment',
14+
);
15+
16+
expect(isPluginListed).toBe(true);
17+
});

e2e-tests/playwright/utils/APIHelper.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { request, APIResponse } from '@playwright/test';
1+
import { request, APIResponse, expect } from '@playwright/test';
22

33
export class APIHelper {
44
private static githubAPIVersion = '2022-11-28';
@@ -38,4 +38,20 @@ export class APIHelper {
3838
response = [...response, ...body];
3939
return await this.getGithubPaginatedRequest(url, pageNo + 1, response);
4040
}
41+
42+
async getGuestToken(): Promise<string> {
43+
const context = await request.newContext();
44+
const response = await context.post('/api/auth/guest/refresh');
45+
expect(response.status()).toBe(200);
46+
const data = await response.json();
47+
return data.backstageIdentity.token;
48+
}
49+
50+
async getGuestAuthHeader(): Promise<{ [key: string]: string }> {
51+
const token = await this.getGuestToken();
52+
const headers = {
53+
Authorization: `Bearer ${token}`,
54+
};
55+
return headers;
56+
}
4157
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect, request } from '@playwright/test';
2+
3+
export class Analytics {
4+
async getDynamicPluginsList(authHeader: { [key: string]: string }) {
5+
const context = await request.newContext();
6+
const loadedPluginsEndpoint = '/api/dynamic-plugins-info/loaded-plugins';
7+
const response = await context.get(loadedPluginsEndpoint, {
8+
headers: authHeader,
9+
});
10+
expect(response.status()).toBe(200);
11+
const plugins = await response.json();
12+
return plugins;
13+
}
14+
15+
checkPluginListed(plugins: any, expected: string) {
16+
return plugins.some((plugin: { name: string }) => plugin.name === expected);
17+
}
18+
}

0 commit comments

Comments
 (0)