fix delete template when trash is not in page

This commit is contained in:
mildred 2024-03-08 18:17:47 +01:00
parent 7224b9a0d5
commit d1998547c0
2 changed files with 43 additions and 25 deletions

View File

@ -166,11 +166,14 @@ export class TemplatesPage {
} }
async gotoDeleteAndConfirmInModal(template: String) { async gotoDeleteAndConfirmInModal(template: String): Promise <boolean>{
try { try {
const row = this.page.locator(`tr:has-text('${template}')`); const row = this.page.locator(`tr:has-text('${template}')`);
await row.locator('i.bi.bi-trash').click(); const trashLocator = row.locator('i.bi.bi-trash');
// Check if the trash icon exists
if (await trashLocator.count() > 0) {
await trashLocator.click();
//Find the modal that corresponds to the specific template (see html) //Find the modal that corresponds to the specific template (see html)
const modal = this.page.locator(`div.modal:has-text("${template}")`) const modal = this.page.locator(`div.modal:has-text("${template}")`)
.first(); .first();
@ -180,6 +183,11 @@ export class TemplatesPage {
// Click the delete button within the modal // Click the delete button within the modal
await modal.locator('.btn.btn-danger').click(); await modal.locator('.btn.btn-danger').click();
return true;
} else {
console.log(`The schema ${template} can not be deleted`)
return false;
}
} catch (error) { } catch (error) {
console.error("A problem while trying to delete the template.", error); console.error("A problem while trying to delete the template.", error);
@ -187,11 +195,14 @@ export class TemplatesPage {
} }
} }
async gotoDeleteAndCancelInModal(template: String) { async gotoDeleteAndCancelInModal(template: String): Promise <boolean>{
try { try {
const row = this.page.locator(`tr:has-text('${template}')`); const row = this.page.locator(`tr:has-text('${template}')`);
await row.locator('i.bi.bi-trash').click(); const trashLocator = row.locator('i.bi.bi-trash');
// Check if the trash icon exists
if (await trashLocator.count() > 0) {
await trashLocator.click();
//Find the modal that corresponds to the specific template (see html) //Find the modal that corresponds to the specific template (see html)
const modal = this.page.locator(`div.modal:has-text("${template}")`) const modal = this.page.locator(`div.modal:has-text("${template}")`)
.first(); .first();
@ -201,6 +212,11 @@ export class TemplatesPage {
// Click the delete button within the modal // Click the delete button within the modal
await modal.locator('.btn.btn-secondary').click(); await modal.locator('.btn.btn-secondary').click();
return true;
} else {
console.log(`The schema ${template} can not be deleted`)
return false;
}
} catch (error) { } catch (error) {
console.error("A problem while trying to delete the template.", error); console.error("A problem while trying to delete the template.", error);
throw error; throw error;

View File

@ -1,4 +1,4 @@
import { test, expect} from '@playwright/test' import { test, expect } from '@playwright/test'
import { TemplatesPage } from '../src/page-objects/AD_TemplatesPage' import { TemplatesPage } from '../src/page-objects/AD_TemplatesPage'
import { ViewImportedDataPage } from '../src/page-objects/AD_ViewImportedDataPage' import { ViewImportedDataPage } from '../src/page-objects/AD_ViewImportedDataPage'
import { ImportDataPage } from '../src/page-objects/AD_ImportDataPage' import { ImportDataPage } from '../src/page-objects/AD_ImportDataPage'
@ -66,11 +66,13 @@ test.describe('TEMPLATES Section Tests ', () => {
/*Verify the schema was imported*/ /*Verify the schema was imported*/
expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeTruthy(); expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeTruthy();
/*Try to delete the schema and thenn confirm the operation*/ /*Try to delete the schema and then confirm the operation*/
await templatesPage.gotoDeleteAndConfirmInModal(JSON_SCHEMA_FVC); let wasDeleted = await templatesPage.gotoDeleteAndConfirmInModal(JSON_SCHEMA_FVC);
/*Verify the schema was deleted*/
expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeFalsy();
/*Verify the schema was deleted*/
if (wasDeleted) {
expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeFalsy();
}
}) })
}) })