Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional Tests : BO - Advanced Parameter - Authorization Server : Edit API Access #34330

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

// Import commonTests
import loginCommon from '@commonTests/BO/loginBO';
import createAPIAccessTest from '@commonTests/BO/advancedParameters/authServer';
import {setFeatureFlag} from '@commonTests/BO/advancedParameters/newFeatures';

// Import pages
import apiAccessPage from 'pages/BO/advancedParameters/APIAccess';
import addNewApiAccessPage from '@pages/BO/advancedParameters/APIAccess/add';
import featureFlagPage from '@pages/BO/advancedParameters/featureFlag';
import dashboardPage from '@pages/BO/dashboard';

// Import data
import APIAccessData from '@data/faker/APIAccess';

import {expect} from 'chai';
import type {BrowserContext, Page} from 'playwright';

const baseContext: string = 'functional_BO_advancedParameters_authorizationServer_editAPIAccess';

describe('BO - Advanced Parameter - API Access : Edit API Access', async () => {
let browserContext: BrowserContext;
let page: Page;

const createAPIAccess: APIAccessData = new APIAccessData({
clientName: 'API Access XYZ',
clientId: 'api-access-xyz',
description: 'Description ABC',
});
const editAPIAccess: APIAccessData = new APIAccessData({
clientName: 'API Access UVW',
clientId: 'api-access-uvw',
description: 'Description DEF',
});

// Pre-condition: Enable experimental feature : Authorization server
setFeatureFlag(featureFlagPage.featureFlagAuthorizationServer, true, `${baseContext}_enableAuthorizationServer`);

// Pre-condition: Create an API Access
createAPIAccessTest(createAPIAccess, `${baseContext}_preTest_0`);

// before and after functions
before(async function () {
browserContext = await helper.createBrowserContext(this.browser);
page = await helper.newTab(browserContext);
});

after(async () => {
await helper.closeBrowserContext(browserContext);
});

describe('BO - Advanced Parameter - API Access : Edit API Access', async () => {
it('should login in BO', async function () {
await loginCommon.loginBO(this, page);
});

it('should go to \'Advanced Parameters > API Access\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToAuthorizationServerPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.advancedParametersLink,
dashboardPage.authorizationServerLink,
);

const pageTitle = await apiAccessPage.getPageTitle(page);
expect(pageTitle).to.eq(apiAccessPage.pageTitle);
});

it('should go to edit API Access page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToEditAPIAccessPage', baseContext);

await apiAccessPage.goToEditAPIAccessPage(page, 1);

const pageTitle = await addNewApiAccessPage.getPageTitle(page);
expect(pageTitle).to.eq(addNewApiAccessPage.pageTitleEdit(createAPIAccess.clientName));
});

it('should edit API Access', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'editAPIAccess', baseContext);

const textResult = await addNewApiAccessPage.addAPIAccess(page, editAPIAccess);
expect(textResult).to.equal(addNewApiAccessPage.successfulUpdateMessage);
});

it('should return to the list', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'returnToList', baseContext);

// Go back to list to get number of elements because edition form redirects to itself
await dashboardPage.goToSubMenu(
page,
dashboardPage.advancedParametersLink,
dashboardPage.authorizationServerLink,
);
const numElements = await apiAccessPage.getNumberOfElementInGrid(page);
expect(numElements).to.equal(1);
});

it('should delete API Access', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'deleteAPIAccess', baseContext);

const textResult = await apiAccessPage.deleteAPIAccess(page, 1);
expect(textResult).to.equal(addNewApiAccessPage.successfulDeleteMessage);

const numElements = await apiAccessPage.getNumberOfElementInGrid(page);
expect(numElements).to.equal(0);
});
});

// Post-condition: Disable experimental feature : Authorization server
setFeatureFlag(featureFlagPage.featureFlagAuthorizationServer, false, `${baseContext}_disableAuthorizationServer`);
});
90 changes: 90 additions & 0 deletions tests/UI/commonTests/BO/advancedParameters/authServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

import loginCommon from '@commonTests/BO/loginBO';

import dashboardPage from '@pages/BO/dashboard';
import apiAccessPage from '@pages/BO/advancedParameters/APIAccess';
import addNewApiAccessPage from '@pages/BO/advancedParameters/APIAccess/add';

import APIAccessData from '@data/faker/APIAccess';

import {expect} from 'chai';
import type {BrowserContext, Page} from 'playwright';

/**
* Function to create API Access
* @param apiAccess {APIAccessData} Data to set in API Access form
* @param baseContext {string} String to identify the test
*/
function createAPIAccessTest(apiAccess: APIAccessData, baseContext: string = 'commonTests-createAPIAccessTest'): void {
let browserContext: BrowserContext;
let page: Page;
let numberOfAPIAccess: number = 0;

describe('PRE-TEST: Create an API Access', async () => {
// before and after functions
before(async function () {
browserContext = await helper.createBrowserContext(this.browser);
page = await helper.newTab(browserContext);
});

after(async () => {
await helper.closeBrowserContext(browserContext);
});

it('should login in BO', async function () {
await loginCommon.loginBO(this, page);
});

it('should go to \'Advanced Parameters > API Access\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToAuthorizationServerPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.advancedParametersLink,
dashboardPage.authorizationServerLink,
);

const pageTitle = await apiAccessPage.getPageTitle(page);
expect(pageTitle).to.eq(apiAccessPage.pageTitle);

numberOfAPIAccess = await apiAccessPage.getNumberOfElementInGrid(page);
expect(numberOfAPIAccess).to.gte(0);
});

it('should check that no records found', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkThatNoRecordFound', baseContext);

const noRecordsFoundText = await apiAccessPage.getTextForEmptyTable(page);
expect(noRecordsFoundText).to.contains('warning No records found');
});

it('should go to add New API Access page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToNewAPIAccessPage', baseContext);

await apiAccessPage.goToNewAPIAccessPage(page);

const pageTitle = await addNewApiAccessPage.getPageTitle(page);
expect(pageTitle).to.eq(addNewApiAccessPage.pageTitleCreate);
});

it('should create API Access', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'createAPIAccess', baseContext);

const textResult = await addNewApiAccessPage.addAPIAccess(page, apiAccess);
expect(textResult).to.equal(addNewApiAccessPage.successfulCreationMessage);

// Go back to list to get number of elements because creation form redirects to edition form
await dashboardPage.goToSubMenu(
page,
dashboardPage.advancedParametersLink,
dashboardPage.authorizationServerLink,
);
const numElements = await apiAccessPage.getNumberOfElementInGrid(page);
expect(numElements).to.equal(numberOfAPIAccess + 1);
});
});
}

export default createAPIAccessTest;