310 lines
15 KiB
TypeScript
310 lines
15 KiB
TypeScript
|
import { test, expect} from '@playwright/test'
|
||
|
import { TemplatesPage } from '../src/page-objects/AD_TemplatesPage'
|
||
|
import { ViewImportedDataPage } from '../src/page-objects/AD_ViewImportedDataPage'
|
||
|
import { ImportDataPage } from '../src/page-objects/AD_ImportDataPage'
|
||
|
import { checkFileName, clickDataOnLeftMenu, clickTemplatesOnLeftMenu, loadIfJsonSchemaNotAvailable, loginAsAdmin, loginAsUser, gotoViewEnabledCredential, expectedCredentialSubjectForUser } from '../src/steps';
|
||
|
import { ViewCredentialPage } from '../src/page-objects/US_ViewCredentialPage.js'
|
||
|
import { fail } from 'assert'
|
||
|
import { URL_IDHUB, USER1_EMAIL } from '../src/constants/env_constants';
|
||
|
import { ALERT_FILE_TO_IMPORT_IS_EMPTY, ALERT_FILE_TO_IMPORT_WITHOUT_REQUIRED_COLUMS, ALERT_FILE_TO_IMPORT_WITH_ALIEN_COLUMS, FILE_TO_IMPORT_FVC, FILE_TO_IMPORT_FVC_EMPTY, FILE_TO_IMPORT_FVC_WITHOUT_REQUIRED_COLUMNS, FILE_TO_IMPORT_FVC_WITH_ALIEN_COLUMNS, JSON_SCHEMA_FVC, JSON_SCHEMA_ID_FVC, PATH_FILES_TO_IMPORT, SCHEMA_FVC, SCHEMA_TYPE_FVC } from '../src/constants/constants';
|
||
|
import { deleteFile } from '../src/utils';
|
||
|
|
||
|
/**
|
||
|
* 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);
|
||
|
})
|
||
|
|
||
|
/**
|
||
|
* 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);
|
||
|
})
|
||
|
|
||
|
/**
|
||
|
* 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 thenn confirm the operation*/
|
||
|
await templatesPage.gotoDeleteAndConfirmInModal(JSON_SCHEMA_FVC);
|
||
|
/*Verify the schema was deleted*/
|
||
|
expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeFalsy();
|
||
|
|
||
|
})
|
||
|
})
|
||
|
|
||
|
/**
|
||
|
* Checking data section: view the lists of files imported, import data, delete...
|
||
|
*/
|
||
|
|
||
|
test.describe('DATA Section Tests', () => {
|
||
|
|
||
|
test.beforeEach(async ({ page }) => { //este se ejecutará antes de cada test
|
||
|
await loginAsAdmin(page, URL_IDHUB);
|
||
|
})
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Load of an excel file - Happy Path:
|
||
|
* Check if file was loaded before. If yes, copy the original file (financial-vulnerability-credential.xlxs) to a new valid with random name
|
||
|
* If the template schema (associated with the type of credential to be enabled) is not available, import it and verify the operation
|
||
|
* Load the associated data file (xls) and check that appears in the list of imported data files
|
||
|
* Expected behavior: the file is loaded, the message:"The file was imported successfully!" is displayed,
|
||
|
* and the file appears in the imported files view.
|
||
|
*/
|
||
|
|
||
|
test('DATA -> Import data file - Happy path - Financial Vulnerability Credential ', async ({ page }) => {
|
||
|
|
||
|
const viewImportedDataPage = new ViewImportedDataPage(page);
|
||
|
const importDataPage = new ImportDataPage(page);
|
||
|
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
|
||
|
// If a file with a FILE_TO_IMPORT was previouly loaded, rename it
|
||
|
let fileName = FILE_TO_IMPORT_FVC;
|
||
|
fileName = await checkFileName(page, fileName);
|
||
|
|
||
|
// Check if the json schema associated with the file is loaded to be used
|
||
|
// If not, load it in templates
|
||
|
await loadIfJsonSchemaNotAvailable(page, JSON_SCHEMA_FVC);
|
||
|
|
||
|
//Go to the Data option on leftmenu
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
|
||
|
//Select the import button and go to the import data page
|
||
|
await viewImportedDataPage.gotoImportDataPage();
|
||
|
|
||
|
//Import excel file to enable a 'Financial vulnerability credential'for testing users
|
||
|
console.log("File to import: ", fileName, " with schema: ", SCHEMA_FVC);
|
||
|
await importDataPage.importFile(SCHEMA_FVC, PATH_FILES_TO_IMPORT + fileName, "Default");
|
||
|
let actual = await viewImportedDataPage.alertFileImportedSuccessfully();
|
||
|
|
||
|
//Rename the default excel file with the original name FILE_TO_IMPORT in the directoy PATH_FILES_TO_IMPORT
|
||
|
if (fileName != FILE_TO_IMPORT_FVC) {
|
||
|
await deleteFile(fileName);
|
||
|
}
|
||
|
if (actual) {
|
||
|
//Check if the file is in the list of imported files sucessfully
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
await page.getByRole('link', { name: 'Date' }).click();
|
||
|
await page.getByRole('link', { name: 'Date' }).click();
|
||
|
|
||
|
expect(await viewImportedDataPage.fileIsAvailableInView(fileName)).toBeTruthy();
|
||
|
expect(await viewImportedDataPage.isFileSuccessfullyLoaded(fileName)).toBeTruthy();
|
||
|
} else {
|
||
|
console.log("Unexpected result loading the file. Test failed.")
|
||
|
fail();
|
||
|
}
|
||
|
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Load of an excel file - Sad Path:
|
||
|
* Check if file was loaded before. If yes, copy the original to the new one with random name.
|
||
|
* If the template schema (associated with the type of credential to be enabled) is not available, import it and verify the operation
|
||
|
* Try to load a well-formatted excel file but without data.
|
||
|
* Expected behavior: The error message: "The file you try to import is empty"
|
||
|
*/
|
||
|
|
||
|
test('DATA -> Import data file - Sad path (file well formatted but empty) - Financial Vulnerability Credential ', async ({ page }) => {
|
||
|
|
||
|
const viewImportedDataPage = new ViewImportedDataPage(page);
|
||
|
const importDataPage = new ImportDataPage(page);
|
||
|
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
|
||
|
// If a file with a FILE_TO_IMPORT was previously loaded, rename it
|
||
|
let fileName = await checkFileName(page, FILE_TO_IMPORT_FVC_EMPTY);
|
||
|
|
||
|
// Check if the json schema associated with the file is loaded to be used
|
||
|
// If not, load it in templates
|
||
|
await loadIfJsonSchemaNotAvailable(page, JSON_SCHEMA_FVC);
|
||
|
|
||
|
//Go to the Data option on leftmenu
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
|
||
|
//Select the import button and go to the import data page
|
||
|
await viewImportedDataPage.gotoImportDataPage();
|
||
|
|
||
|
//Import excel file to enable a 'Financial vulnerability credential'. The file has no data.
|
||
|
console.log("File to import: ", fileName, " with schema: ", SCHEMA_FVC);
|
||
|
await importDataPage.importFile(SCHEMA_FVC, PATH_FILES_TO_IMPORT + fileName, "Default");
|
||
|
let actual = await importDataPage.alertFileImportedUnsuccessfully(ALERT_FILE_TO_IMPORT_IS_EMPTY);
|
||
|
|
||
|
//Rename the default excel file with the original name FILE_TO_IMPORT in the directoy PATH_FILES_TO_IMPORT
|
||
|
if (fileName != FILE_TO_IMPORT_FVC_EMPTY) {
|
||
|
await deleteFile(fileName);
|
||
|
}
|
||
|
if (actual) {
|
||
|
//Check if the file is in the list of imported files as failed
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
await page.getByRole('link', { name: 'Date' }).click();
|
||
|
await page.getByRole('link', { name: 'Date' }).click();
|
||
|
|
||
|
expect(await viewImportedDataPage.fileIsAvailableInView(fileName)).toBeTruthy();
|
||
|
expect(await viewImportedDataPage.isFileSuccessfullyLoaded(fileName)).toBeFalsy();
|
||
|
} else {
|
||
|
console.log("Unexpected result loading an empty file. Test failed.");
|
||
|
fail();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
test('DATA -> Import data file - Sad path (file bad formatted, without required columns) - Financial Vulnerability Credential ', async ({ page }) => {
|
||
|
|
||
|
const viewImportedDataPage = new ViewImportedDataPage(page);
|
||
|
const importDataPage = new ImportDataPage(page);
|
||
|
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
|
||
|
// If a file with a FILE_TO_IMPORT was previously loaded, rename it
|
||
|
let fileName = await checkFileName(page, FILE_TO_IMPORT_FVC_WITHOUT_REQUIRED_COLUMNS);
|
||
|
|
||
|
// Check if the json schema associated with the file is loaded to be used
|
||
|
// If not, load it in templates
|
||
|
await loadIfJsonSchemaNotAvailable(page, JSON_SCHEMA_FVC);
|
||
|
|
||
|
//Go to the Data option on leftmenu
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
|
||
|
//Select the import button and go to the import data page
|
||
|
await viewImportedDataPage.gotoImportDataPage();
|
||
|
|
||
|
//Import excel file to enable a 'Financial vulnerability credential'. The file has no data.
|
||
|
console.log("File to import: ", fileName, " with schema: ", SCHEMA_FVC);
|
||
|
await importDataPage.importFile(SCHEMA_FVC, PATH_FILES_TO_IMPORT + fileName, "Default");
|
||
|
let actual = await importDataPage.alertFileImportedUnsuccessfully(ALERT_FILE_TO_IMPORT_WITHOUT_REQUIRED_COLUMS);
|
||
|
|
||
|
//Rename the default excel file with the original name FILE_TO_IMPORT in the directoy PATH_FILES_TO_IMPORT
|
||
|
if (fileName != FILE_TO_IMPORT_FVC_WITHOUT_REQUIRED_COLUMNS) {
|
||
|
await deleteFile(fileName);
|
||
|
}
|
||
|
if (actual) {
|
||
|
//Check if the file is in the list of imported files as failed
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
await page.getByRole('link', { name: 'Date' }).click();
|
||
|
await page.getByRole('link', { name: 'Date' }).click();
|
||
|
|
||
|
expect(await viewImportedDataPage.fileIsAvailableInView(fileName)).toBeTruthy();
|
||
|
expect(await viewImportedDataPage.isFileSuccessfullyLoaded(fileName)).toBeFalsy();
|
||
|
} else {
|
||
|
console.log("Unexpected result loading an empty file. Test failed.");
|
||
|
fail();
|
||
|
}
|
||
|
|
||
|
});
|
||
|
|
||
|
test('DATA -> Import data file - Sad path (file bad formatted, with alien columns) - Financial Vulnerability Credential ', async ({ page }) => {
|
||
|
|
||
|
const viewImportedDataPage = new ViewImportedDataPage(page);
|
||
|
const importDataPage = new ImportDataPage(page);
|
||
|
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
|
||
|
// If a file with a FILE_TO_IMPORT was previously loaded, rename it
|
||
|
let fileName = await checkFileName(page, FILE_TO_IMPORT_FVC_WITH_ALIEN_COLUMNS);
|
||
|
|
||
|
// Check if the json schema associated with the file is loaded to be used
|
||
|
// If not, load it in templates
|
||
|
await loadIfJsonSchemaNotAvailable(page, JSON_SCHEMA_FVC);
|
||
|
|
||
|
//Go to the Data option on leftmenu
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
|
||
|
//Select the import button and go to the import data page
|
||
|
await viewImportedDataPage.gotoImportDataPage();
|
||
|
|
||
|
//Import excel file to enable a 'Financial vulnerability credential'. The file has no data.
|
||
|
console.log("File to import: ", fileName, " with schema: ", SCHEMA_FVC);
|
||
|
await importDataPage.importFile(SCHEMA_FVC, PATH_FILES_TO_IMPORT + fileName, "Default");
|
||
|
let actual = await importDataPage.alertFileImportedUnsuccessfully(ALERT_FILE_TO_IMPORT_WITH_ALIEN_COLUMS);
|
||
|
|
||
|
//Rename the default excel file with the original name FILE_TO_IMPORT in the directoy PATH_FILES_TO_IMPORT
|
||
|
if (fileName != FILE_TO_IMPORT_FVC_WITH_ALIEN_COLUMNS) {
|
||
|
await deleteFile(fileName);
|
||
|
}
|
||
|
if (actual) {
|
||
|
//Check if the file is in the list of imported files as failed
|
||
|
await clickDataOnLeftMenu(page);
|
||
|
await page.getByRole('link', { name: 'Date' }).click();
|
||
|
await page.getByRole('link', { name: 'Date' }).click();
|
||
|
|
||
|
expect(await viewImportedDataPage.fileIsAvailableInView(fileName)).toBeTruthy();
|
||
|
expect(await viewImportedDataPage.isFileSuccessfullyLoaded(fileName)).toBeFalsy();
|
||
|
} else {
|
||
|
console.log("Unexpected result loading an empty file. Test failed.");
|
||
|
fail();
|
||
|
}
|
||
|
|
||
|
});
|
||
|
|
||
|
}) //end describe
|
||
|
|
||
|
test.describe('USER Credentials Section Tests', () => {
|
||
|
|
||
|
test.beforeEach(async ({ page }) => { //este se ejecutará antes de cada test
|
||
|
await loginAsUser(page, USER1_EMAIL, URL_IDHUB);
|
||
|
})
|
||
|
|
||
|
/**
|
||
|
* Check if the user1 can visualize the credentials that has been enabled in "My Credentials"
|
||
|
* Check the fields displayed when user click "View" Credential
|
||
|
*/
|
||
|
|
||
|
test('USER Credentials -> My Credentials -> View enabled Financial Vulnerability Credential', async ({ page }) => {
|
||
|
// View the Financial Vulnerabilty Credential in status 'Enabled' for the user
|
||
|
const credentialStatus = "Enabled"
|
||
|
await gotoViewEnabledCredential(page, SCHEMA_TYPE_FVC);
|
||
|
const enabledCredentialView = new ViewCredentialPage(page);
|
||
|
//Check that required fields exist and have a valid value in the current enabled credential
|
||
|
|
||
|
//Get the credential subject values of the credential visualized in the screen and compare to the model
|
||
|
let actualCredential = await enabledCredentialView.buildACredentialFromInputValues(SCHEMA_TYPE_FVC);
|
||
|
let expectedCredential = await expectedCredentialSubjectForUser(USER1_EMAIL, SCHEMA_TYPE_FVC);
|
||
|
expect(actualCredential).toEqual(expectedCredential);
|
||
|
|
||
|
});
|
||
|
|
||
|
}) //end describe
|
||
|
|
||
|
//Añadir test con otros tipos de credenciales
|