Skip to content

Commit

Permalink
Functional Tests : Fixed campaigns/modules/ps_apiresources/01*/01*
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Feb 8, 2024
1 parent 444c136 commit 6ab9364
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Expand Up @@ -127,11 +127,11 @@ describe('PrestaShop API Resources module - Uninstall and install module', async
expect(pageTitle).to.eq(addNewApiAccessPage.pageTitleCreate);
});

it('should check that scopes from Core are present and enabled', async function () {
it('should check that scopes from Core are no more present', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkScopesCore', baseContext);

const scopes = await addNewApiAccessPage.getApiScopes(page, '__core_scopes');
expect(scopes.length).to.be.gt(0);
const hasScopes = await addNewApiAccessPage.hasScopes(page);
expect(hasScopes).to.equal(false);
});

it('should check that scopes from Module are not present', async function () {
Expand Down Expand Up @@ -206,11 +206,18 @@ describe('PrestaShop API Resources module - Uninstall and install module', async
expect(pageTitle).to.eq(addNewApiAccessPage.pageTitleCreate);
});

it('should check that scopes are present', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkScopePresent', baseContext);

const hasScopes = await addNewApiAccessPage.hasScopes(page);
expect(hasScopes).to.equal(true);
});

it('should check that scopes from Core are present', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkScopesCore', baseContext);

const scopes = await addNewApiAccessPage.getApiScopes(page, '__core_scopes');
expect(scopes.length).to.be.gt(0);
expect(scopes.length).to.be.eq(0);
});

it('should check that scopes from Module are present', async function () {
Expand Down
Expand Up @@ -123,7 +123,7 @@ describe('PrestaShop API Resources module - Disable/Enable module', async () =>
await testContext.addContextItem(this, 'testIdentifier', `checkScopesCore${index}`, baseContext);

const scopes = await addNewApiAccessPage.getApiScopes(page, '__core_scopes');
expect(scopes.length).to.be.gt(0);
expect(scopes.length).to.be.eq(0);

// eslint-disable-next-line no-restricted-syntax
for (const scope of scopes) {
Expand Down
15 changes: 15 additions & 0 deletions tests/UI/pages/BO/advancedParameters/APIAccess/add.ts
Expand Up @@ -36,6 +36,8 @@ class AddNewAPIAccess extends BOBasePage {

private readonly statusInput: string;

private readonly noScopes: string;

private readonly scopeGroup: (group:string) => string;

private readonly scopeStatus: (scope: string) => string;
Expand Down Expand Up @@ -75,6 +77,7 @@ class AddNewAPIAccess extends BOBasePage {
this.tokenLifetimeInput = `${this.formAPIAccess} #api_access_lifetime`;
this.statusSpan = `${this.formAPIAccess} span#api_access_enabled`;
this.statusInput = `${this.statusSpan} input`;
this.noScopes = `${this.formAPIAccess} p.resource-scopes-not-available`;
this.scopeGroup = (group:string) => `#api_access_scopes_${group}_accordion div.switch-scope`;
this.scopeStatus = (scope: string) => `${this.formAPIAccess} div[data-scope="${scope}"] div.switch-widget span.ps-switch`;
this.scopeStatusInput = (scope: string) => `${this.scopeStatus(scope)} input`;
Expand Down Expand Up @@ -156,12 +159,24 @@ class AddNewAPIAccess extends BOBasePage {
return false;
}

/**
* Returns if scopes are visible
* @param page {Page} Browser tab
* @return Promise<boolean>
*/
async hasScopes(page: Page): Promise<boolean> {
return this.elementNotVisible(page, this.noScopes, 1000);
}

/**
* Returns the list of scopes from a group
* @param page {Page} Browser tab
* @param group {string} Scopes Group
*/
async getApiScopes(page: Page, group: string): Promise<string[]> {
if ((await page.locator(this.scopeGroup(group)).count()) === 0) {
return [];
}
return page
.locator(this.scopeGroup(group))
.evaluateAll(
Expand Down

0 comments on commit 6ab9364

Please sign in to comment.