246 lines
12 KiB
TypeScript
246 lines
12 KiB
TypeScript
import { test, expect } from '@playwright/test'
|
|
import { ViewImportedDataPage } from '../src/page-objects/AD_ViewImportedDataPage'
|
|
import { ImportDataPage } from '../src/page-objects/AD_ImportDataPage'
|
|
import { checkFileName, clickDataOnLeftMenu, 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, USER2_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, PATH_FILES_TO_IMPORT, SCHEMA_FVC, SCHEMA_TYPE_FVC } from '../src/constants/constants';
|
|
import { deleteFile } from '../src/utils';
|
|
|
|
/**
|
|
* Checking data section: view the lists of files imported, import data, delete...
|
|
*/
|
|
|
|
test.describe('ADMIN-> DATA Section Tests - Testing with Financial Vulnerability Credential', () => {
|
|
|
|
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 - testing with USER1_EMAIL AND FINANCIAL VULNERABILITY CRED', () => {
|
|
|
|
test.beforeEach(async ({ page }) => { //este se ejecutará antes de cada test
|
|
await loginAsUser(page, USER1_EMAIL, URL_IDHUB);
|
|
})
|
|
|
|
/**
|
|
* PRE-CONDITIONS: the admin has enabled a credential of type 'Financial Vulnerabitity' for USER1_EMAIL
|
|
* This is true, if the before test (DATA -> Import data- HAPPY PATH has been passed sucessfully)
|
|
* SUMMARY:
|
|
* - 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
|
|
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
|
|
|