import { expect } from '@genesislcap/foundation-testing/e2e'; import { test } from '../fixture'; // TODO: use UUID service const generateShortUuid = (length: number = 16): string => { const chars: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; let result: string = ''; let count: number = 0; while (count < length) { const randomIndex: number = Math.floor(Math.random() * chars.length); result += chars[randomIndex]; count += 1; } return result; }; test('entity management page audit', async ({ entityManagementPage }) => { await entityManagementPage.audit(); }); test.beforeEach(async ({ loginPage, config }) => { await loginPage.connect(); await loginPage.autofill(config.DEFAULT_USER, config.DEFAULT_PASSWORD); await loginPage.attemptLogin(); }); test('user navigates to entity management', async ({ page }) => { await expect(page).toHaveURL('/entity-management-demo'); await expect(page).toHaveTitle(/Entity Management Micro Frontend - Entity Management Demo/); }); test.describe.serial('Add, Edit and Delete flow', () => { test('user adds new entity', async ({ page }) => { const addButtonLocator = page.getByRole('button', { name: 'Add' }); await addButtonLocator.click(); const inputLocator = page .locator('[data-test-id="COUNTERPARTY_ID"]') .getByPlaceholder('COUNTERPARTY ID', { timeout: 4000 }); await inputLocator.click(); await inputLocator.fill(generateShortUuid()); const inputLocatorLei = page .locator('[data-test-id="COUNTERPARTY_LEI"]') .getByPlaceholder('COUNTERPARTY LEI'); await inputLocatorLei.click(); await inputLocatorLei.fill(generateShortUuid()); const inputLocatorName = page.locator('[data-test-id="NAME"]').getByPlaceholder('NAME'); await inputLocatorName.click(); await inputLocatorName.fill('Temporary Test Record - Inserted'); const submitButtonLocator = page.getByRole('button', { name: 'Submit' }); const isEnabled = await submitButtonLocator.isEnabled(); if (isEnabled) { await submitButtonLocator.click({ timeout: 2000 }); // TODO: FUI-1320 - Address dialog closing in E2E // const closeDialog = page.getByRole('dialog').locator('path'); // await closeDialog.click(); } else { console.log('The submit button is disabled'); } }); test('user edits an entity', async ({ page }) => { const editButtonLocator = page.getByRole('button', { name: 'Edit' }).first(); await editButtonLocator.click(); const inputLocatorLei = page .locator('[data-test-id="COUNTERPARTY_LEI"]') .getByPlaceholder('COUNTERPARTY LEI'); await inputLocatorLei.click(); await inputLocatorLei.fill(generateShortUuid() + '- Updated'); const inputLocatorName = page.locator('[data-test-id="NAME"]').getByPlaceholder('NAME'); await inputLocatorName.click(); await inputLocatorName.fill('Temporary Test Record'); const submitButtonLocator = page.getByRole('button', { name: 'Submit' }); const isEnabled = await submitButtonLocator.isEnabled(); if (isEnabled) { await submitButtonLocator.click(); // TODO: FUI-1320 - Address dialog closing in E2E // const closeDialog = page.getByRole('dialog').locator('path'); // await closeDialog.click(); } else { console.log('The submit button is disabled'); } }); // TODO: FUI-1239 // test('user deletes an entity', async ({ page }) => { // const deleteButtonLocator = page.getByRole('button', { name: 'Delete' }).first(); // await deleteButtonLocator.click(); // const confirmDeleteLocator = page.getByRole('button', { name: 'Confirm' }); // await confirmDeleteLocator.click(); // }); });