import { test, expect } from '@playwright/test' import { TemplatesPage } from '../src/page-objects/AD_TemplatesPage' import { clickTemplatesOnLeftMenu, loadIfJsonSchemaNotAvailable, loginAsAdmin } from '../src/steps'; import { URL_IDHUB, URL_SCHEMAS } from '../src/constants/env_constants'; import { JSON_SCHEMA_FVC, JSON_SCHEMA_ID_FVC } from '../src/constants/constants'; /** * Checking template section: view the lists of templates, import schema, delete schema, view json */ test.describe('TEMPLATES Section Tests ', () => { test.beforeEach(async ({ page }) => { //este se ejecutará antes de cada test await loginAsAdmin(page, URL_IDHUB); }) test.afterEach(async ({ page }) => { //este se ejecutará despues de cada test await page.click('.logout'); await page.close(); }) /** * For every row in the templates view, * extract the name of the template schema (second cell) and compare it against the * las element of the $id in the corresponding json file. */ test('TEMPLATES -> View credential templates -> compare each template name against last element of $id in JSON', async ({ page }) => { // Navigate to the page with the table const templatesPage = new TemplatesPage(page); await clickTemplatesOnLeftMenu(page); expect(await templatesPage.checkSchemaNamesAgainstCorrespondingJSON(page)).toBeTruthy(); }) /** * Check a specific template in the list of templates * If the template schema is not available, the schema is imported * Once the template schema is in the list, verify the element id in the json file */ test('TEMPLATES -> View schema/import for Financial Vulnerability Credential', async ({ page }) => { const templatesPage = new TemplatesPage(page); //Load the schema if it is not loaded await loadIfJsonSchemaNotAvailable(page, JSON_SCHEMA_FVC); //validate $id in the json template await templatesPage.gotoViewSchemaPage(JSON_SCHEMA_FVC); const jsonContent = await page.evaluate(() => JSON.parse(document.body.innerText)); // Check if the JSON elements exist expect(jsonContent["$id"]).toBe(JSON_SCHEMA_ID_FVC); await page.goto(URL_SCHEMAS); }) /** * Check a specific template in the list of templates * If the template schema is not available, the schema is imported and verify the operation * Try to delete the schema, but cancel the operation * Try to delete the schema, confirm the operation and verify the operation */ test('TEMPLATES -> Delete schema', async ({ page }) => { //Access the specific template schema const templatesPage = new TemplatesPage(page); //check if the schema is imported await loadIfJsonSchemaNotAvailable(page, JSON_SCHEMA_FVC); /*Try to delete the schema and then cancel in the modal*/ await templatesPage.gotoDeleteAndCancelInModal(JSON_SCHEMA_FVC); /*Verify the schema was imported*/ expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeTruthy(); /*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(); } }) })