-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[e2e][RHIDP-754] Github discovery UI test (#1625)
* + Github discovery UI test * minor fixes * + setup on rbac job * - axios + PW api requests * + playwright fixtures * fix security error * fix config file * fixing configmap * fixing configmap * minor fix * ensure repo is a component * fix fileExistsOnRepo call * deleting github link validation, * fixes and githubApi fixture * replace env variable to playwrightConfig
- Loading branch information
Showing
7 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { test as base } from '@playwright/test'; | ||
import { Catalog } from '../support/pages/Catalog'; | ||
import GithubApi from '../support/api/github'; | ||
import { CATALOG_FILE, JANUS_QE_ORG } from '../utils/constants'; | ||
import { Common } from '../utils/Common'; | ||
import { assert } from 'console'; | ||
|
||
type GithubDiscoveryFixture = { | ||
catalogPage: Catalog; | ||
githubApi: GithubApi; | ||
testOrganization: string; | ||
}; | ||
|
||
const test = base.extend<GithubDiscoveryFixture>({ | ||
catalogPage: async ({ page }, use) => { | ||
await new Common(page).loginAsGithubUser(); | ||
const catalog = new Catalog(page); | ||
await catalog.go(); | ||
use(catalog); | ||
}, | ||
githubApi: new GithubApi(), | ||
testOrganization: JANUS_QE_ORG, | ||
}); | ||
|
||
test.describe('Github Discovery Catalog', () => { | ||
test(`Discover Organization's Catalog`, async ({ | ||
catalogPage, | ||
githubApi, | ||
testOrganization, | ||
}) => { | ||
const organizationRepos = await githubApi.getReposFromOrg(testOrganization); | ||
const reposNames: string[] = organizationRepos.map(repo => repo['name']); | ||
const realComponents: string[] = reposNames.filter( | ||
async repo => | ||
await githubApi.fileExistsOnRepo( | ||
`${testOrganization}/${repo}`, | ||
CATALOG_FILE, | ||
), | ||
); | ||
|
||
for (let i = 0; i != realComponents.length; i++) { | ||
const repo = realComponents[i]; | ||
await catalogPage.search(repo); | ||
const row = await catalogPage.tableRow(repo); | ||
assert(await row.isVisible()); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export class getOrganizationResponse { | ||
reposUrl: string; | ||
constructor(response: any) { | ||
enum OrganizationResponseAttributes { | ||
ReposUrl = 'repos_url', | ||
} | ||
this.reposUrl = response[OrganizationResponseAttributes.ReposUrl]; | ||
} | ||
} | ||
|
||
export enum ItemStatus { | ||
open = 'open', | ||
closed = 'closed', | ||
all = 'all', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { getOrganizationResponse } from './github-structures'; | ||
import { JANUS_ORG } from '../../utils/constants'; | ||
import { APIResponse, request } from '@playwright/test'; | ||
|
||
// https://docs.github.com/en/rest?apiVersion=2022-11-28 | ||
export default class GithubApi { | ||
private static API_URL = 'https://api.github.com'; | ||
private static API_VERSION = '2022-11-28'; | ||
private static AUTH_HEADER = { | ||
Accept: 'application/vnd.github+json', | ||
Authorization: `Bearer ${process.env.GH_RHDH_QE_USER_TOKEN}`, | ||
'X-GitHub-Api-Version': GithubApi.API_VERSION, | ||
}; | ||
|
||
public async getOrganization( | ||
org = JANUS_ORG, | ||
): Promise<getOrganizationResponse> { | ||
const req = await this._organization(org).get(); | ||
return new getOrganizationResponse(req.json()); | ||
} | ||
|
||
public async getReposFromOrg(org = JANUS_ORG) { | ||
const req = await this._organization(org).repos(); | ||
return req.json(); | ||
} | ||
|
||
public async fileExistsOnRepo(repo: string, file: string): Promise<boolean> { | ||
const req = await this._repo(repo).getContent(file); | ||
const status = req.status(); | ||
if (status == 403) { | ||
throw Error('You don-t have permissions to see this path'); | ||
} | ||
return [200, 302, 304].includes(status); | ||
} | ||
|
||
private _myContext = request.newContext({ | ||
baseURL: GithubApi.API_URL, | ||
extraHTTPHeaders: GithubApi.AUTH_HEADER, | ||
}); | ||
|
||
private _repo(repo: string) { | ||
const url = `/repos/${repo}/`; | ||
return { | ||
getContent: async (path: string) => { | ||
path = url + path; | ||
const context = await this._myContext; | ||
return context.get(path); | ||
}, | ||
}; | ||
} | ||
|
||
private _organization(organization: string) { | ||
const url = '/orgs/'; | ||
|
||
return { | ||
get: async (): Promise<APIResponse> => { | ||
const path: string = url + organization; | ||
const context = await this._myContext; | ||
return context.get(path); | ||
}, | ||
|
||
repos: async (): Promise<APIResponse> => { | ||
const context = await this._myContext; | ||
const organizationResponse = await new GithubApi() | ||
._organization(organization) | ||
.get(); | ||
return context.get((await organizationResponse.json()).repos_url); | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect, Page } from '@playwright/test'; | ||
import { GITHUB_URL } from '../../utils/constants'; | ||
|
||
export class CatalogItem { | ||
private page: Page; | ||
|
||
githubLink = (path: string): string => { | ||
return `a[href*="${GITHUB_URL}${path}"]`; | ||
}; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
async validateGithubLink(s: string) { | ||
const url = this.githubLink(s); | ||
const link = this.page.locator(url).first(); | ||
await expect(link).toBeVisible(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const GITHUB_URL = 'https://github.com/'; | ||
export const JANUS_ORG = 'janus-idp'; | ||
export const JANUS_QE_ORG = 'janus-qe'; | ||
export const SHOWCASE_REPO = `${JANUS_ORG}/backstage-showcase`; | ||
export const CATALOG_FILE = 'catalog-info.yaml'; |