Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

164 lines
5.0 KiB
TypeScript
Raw Normal View History

/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Browser, expect, Page, request } from '@playwright/test';
import { randomUUID } from 'crypto';
import { AdminClass } from '../support/user/AdminClass';
import { UserClass } from '../support/user/UserClass';
export const uuid = () => randomUUID().split('-')[0];
export const descriptionBox =
'.toastui-editor-md-container > .toastui-editor > .ProseMirror';
export const INVALID_NAMES = {
MAX_LENGTH:
'a87439625b1c2d3e4f5061728394a5b6c7d8e90a1b2c3d4e5f67890aba87439625b1c2d3e4f5061728394a5b6c7d8e90a1b2c3d4e5f67890abName can be a maximum of 128 characters',
WITH_SPECIAL_CHARS: '::normalName::',
};
export const NAME_VALIDATION_ERROR =
'Name must contain only letters, numbers, underscores, hyphens, periods, parenthesis, and ampersands.';
export const NAME_MIN_MAX_LENGTH_VALIDATION_ERROR =
'Name size must be between 2 and 64';
export const NAME_MAX_LENGTH_VALIDATION_ERROR =
'Name can be a maximum of 128 characters';
export const getToken = async (page: Page) => {
return page.evaluate(
() =>
JSON.parse(localStorage.getItem('om-session') ?? '{}')?.state
?.oidcIdToken ?? ''
);
};
export const getAuthContext = async (token: string) => {
return await request.newContext({
extraHTTPHeaders: {
Authorization: `Bearer ${token}`,
},
});
};
export const redirectToHomePage = async (page: Page) => {
await page.goto('/');
await page.waitForURL('**/my-data');
};
export const createNewPage = async (browser: Browser) => {
// create a new page
const page = await browser.newPage();
await redirectToHomePage(page);
// get the token from localStorage
const token = await getToken(page);
// create a new context with the token
const apiContext = await getAuthContext(token);
const afterAction = async () => {
await apiContext.dispose();
await page.close();
};
return { page, apiContext, afterAction };
};
/**
* Retrieves the API context for the given page.
* @param page The Playwright page object.
* @returns An object containing the API context and a cleanup function.
*/
export const getApiContext = async (page: Page) => {
const token = await getToken(page);
const apiContext = await getAuthContext(token);
const afterAction = async () => await apiContext.dispose();
return { apiContext, afterAction };
};
export const getEntityTypeSearchIndexMapping = (entityType: string) => {
const entityMapping = {
Table: 'table_search_index',
Topic: 'topic_search_index',
Dashboard: 'dashboard_search_index',
Pipeline: 'pipeline_search_index',
MlModel: 'mlmodel_search_index',
Container: 'container_search_index',
SearchIndex: 'search_entity_search_index',
feat(#10933): API service UI (#17003) * feat(#10933): API service UI * feat: Add support for API collections in multiple languages * feat: add collection page * feat: Add support for multiple languages in endpoint-plural translation * chore: Add 'Beta' tag to API Services card, mark 'REST' service as beta, hide Pipelines tab, and update API Schemas card in settings. * fix: api service version page to show list of collections * feat: add api collect version page * feat: add custom property support for api collections and endpoints * feat: Add API Collection and API Endpoint translations in multiple languages * Refactor proxy configuration to use '/api/' context instead of '/api/v1' * feat: add apiEndpoint page * feat: add APIEndpoint summary component * feat: add APIEndpoint schema component * chore: remove the schema type from APIEndpointSchema component * feat: add version page component for API endpoint * chore: add task support for api collection and api endpoint * chore: remove schema from request and response label * chore: don't show add ingestion button for api services * feat: add search support for api entity * feat: add request and response schema field translations for multiple languages * chore: update icons * refactor: Add null checks in EntityUtils.tsx * feat: show deleted child entities if service is deleted * chore: Update addApiEndpointFollower function in apiEndpointsAPI.ts * feat: Add API collection and endpoint retrieval in EntityPopOverCard.tsx * chore: add api endpoint in data assets widget * feat: Add extra info link in data assets header * chore: Add API endpoint index to DataAssetsWidget test * feat: add api endpoint to explore tree * test: add cypress for apiendpoint and apicollection custom property * test: add playwright test for api service entity * test: add playwright test for api collection entity * test: Add ApiEndpoint playwright test * test: fix api endpoint and api collection test * fix: minor issues * test: add playwright test for creating service from ui and explore page tree * test: add playwright test for api endpoint lineage * feat: Update API collection page to use specific fields for owner, tags, and votes * test: remove api endpoint class from linage spec
2024-07-26 14:31:17 +05:30
ApiEndpoint: 'api_endpoint_search_index',
};
return entityMapping[entityType];
};
export const performAdminLogin = async (browser) => {
const admin = new AdminClass();
const page = await browser.newPage();
await admin.login(page);
await redirectToHomePage(page);
const token = await getToken(page);
const apiContext = await getAuthContext(token);
const afterAction = async () => {
await apiContext.dispose();
await page.close();
};
return { page, apiContext, afterAction };
};
export const performUserLogin = async (browser, user: UserClass) => {
const page = await browser.newPage();
await user.login(page);
const token = await getToken(page);
const apiContext = await getAuthContext(token);
const afterAction = async () => {
await apiContext.dispose();
await page.close();
};
return { page, apiContext, afterAction };
};
export const toastNotification = async (
page: Page,
message: string | RegExp
) => {
await expect(page.getByRole('alert').first()).toHaveText(message);
await page.getByLabel('close').first().click();
};
export const clickOutside = async (page: Page) => {
await page.locator('body').click({
position: {
x: 0,
y: 0,
},
}); // with this action left menu bar is getting opened
await page.mouse.move(1280, 0); // moving out side left menu bar to avoid random failure due to left menu bar
};
export const visitUserProfilePage = async (page: Page) => {
await page.getByTestId('dropdown-profile').click();
await page.waitForSelector('[role="menu"].profile-dropdown', {
state: 'visible',
});
const userResponse = page.waitForResponse(
'/api/v1/users/name/*?fields=*&include=all'
);
await page.getByTestId('user-name').click({ force: true });
await userResponse;
await clickOutside(page);
};