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 {
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)
const modal = this.page.locator(`div.modal:has-text("${template}")`)
.first();
@ -180,6 +183,11 @@ export class TemplatesPage {
// Click the delete button within the modal
await modal.locator('.btn.btn-danger').click();
return true;
} else {
console.log(`The schema ${template} can not be deleted`)
return false;
}
} catch (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 {
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)
const modal = this.page.locator(`div.modal:has-text("${template}")`)
.first();
@ -201,6 +212,11 @@ export class TemplatesPage {
// Click the delete button within the modal
await modal.locator('.btn.btn-secondary').click();
return true;
} else {
console.log(`The schema ${template} can not be deleted`)
return false;
}
} catch (error) {
console.error("A problem while trying to delete the template.", error);
throw error;

View File

@ -66,11 +66,13 @@ test.describe('TEMPLATES Section Tests ', () => {
/*Verify the schema was imported*/
expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeTruthy();
/*Try to delete the schema and thenn confirm the operation*/
await templatesPage.gotoDeleteAndConfirmInModal(JSON_SCHEMA_FVC);
/*Verify the schema was deleted*/
expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeFalsy();
/*Try to delete the schema and then confirm the operation*/
let wasDeleted = await templatesPage.gotoDeleteAndConfirmInModal(JSON_SCHEMA_FVC);
/*Verify the schema was deleted*/
if (wasDeleted) {
expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeFalsy();
}
})
})