Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.development.local
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ REACT_APP_PAGOPA_HELP_EMAIL=assistenza@selfcare.it
REACT_APP_OPERATOR_EMAIL_ADDRESSES='stefano.bafaro@pagopa.it;'

REACT_APP_JWT=DUMMY

144 changes: 144 additions & 0 deletions integration-test/tests/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { Page, test, expect } from '@playwright/test';
import { changeToEcIPAUser, ORG } from './utils/e2eUtils';

const INSTITUTION_ID = ORG.EC_IPA.id;
const GET_SERVICES_URL = `**/institutions/${INSTITUTION_ID}/services/consents`;

test.describe('Settings Page - Service Consents', () => {
// eslint-disable-next-line functional/no-let
let page: Page;

test.beforeAll(async ({ browser }) => {
console.log('🚀 STARTING TEST FILE: settings.spec.ts');
page = await browser.newPage({ storageState: undefined });
});

test('should render the list of services correctly', async () => {
await changeToEcIPAUser(page);
await acceptCookieBanner(page);

console.log('🚀 STARTING TEST: Render the list of services');
await page.getByTestId('settings-nav-test').click();
await expect(page.getByRole('heading', { name: /Impostazioni/i })).toBeVisible();
await expect(page.getByRole('alert')).toBeVisible();
await expect(page.getByRole('heading', { name: /SEPA Request to Pay/})).toBeVisible();
});

test('should open dialog, enable service (Opt-In) and disable service (Opt-in) or vice versa', async ({ page }) => {
await changeToEcIPAUser(page);
await acceptCookieBanner(page);

await page.getByTestId('settings-nav-test').click();

const btnEnable = page.getByTestId('settingCard-RTP-enableButton');
const btnDisable = page.getByTestId('settingCard-RTP-disableButton');
const eitherButton = btnEnable.or(btnDisable);
await eitherButton.waitFor({ state: 'visible', timeout: 5000 });

if (await btnEnable.isVisible()) {
console.log('🚀 STATE DETECTED: Service is OFF. Testing ENABLE flow.');
await enableServiceFlow(page, "RTP");

console.log('🚀 Testing DISABLE flow.');
await disableServiceFlow(page, "RTP");
} else {
console.log('🚀 STATE DETECTED: Service is ON. Testing DISABLE flow.');
await disableServiceFlow(page, "RTP");

console.log('🚀 Testing ENABLE flow.');
await enableServiceFlow(page, "RTP");
}
});

test('should close dialog when clicking cancel', async ({ page }) => {
console.log('🚀 STARTING TEST: Should close dialog when clicking cancel.');
await changeToEcIPAUser(page);
await acceptCookieBanner(page);

await page.getByTestId('settings-nav-test').click();

const btnEnable = page.getByTestId('settingCard-RTP-enableButton');
const btnDisable = page.getByTestId('settingCard-RTP-disableButton');
const eitherButton = btnEnable.or(btnDisable);
await eitherButton.waitFor({ state: 'visible', timeout: 5000 });

if (await btnEnable.isVisible()) {
await btnEnable.click();
} else {
await btnDisable.click();
}

const dialog = page.getByTestId('settingCard-RTP-dialog-message');
await expect(dialog).toBeVisible();

// Click Cancel
await page.getByTestId('settingCard-RTP-dialog-cancelButton').click();

await expect(dialog).toBeHidden();
});

test('should show empty state if list is empty', async ({ page }) => {
console.log('🚀 STARTING TEST: Should close dialog when clicking cancel.');
await changeToEcIPAUser(page);
await acceptCookieBanner(page);

await page.route(GET_SERVICES_URL, async (route) => {
await route.fulfill({
status: 200,
body: JSON.stringify({ services: [] }),
});
});

await page.getByTestId('settings-nav-test').click();

await expect(page.getByTestId("settingsPage.emptyListError")).toBeVisible();
});
});

export const acceptCookieBanner = async (page: Page) => {
const cookieButton = page.getByRole('button', { name: /accetta|accept/i });

try {
await cookieButton.waitFor({ state: 'visible', timeout: 5000 });
await cookieButton.click();
console.log('🍪 Cookie banner accepted.');
} catch (error) {
console.log('🍪 Cookie banner not found or already accepted (Continuing test...)');
}
};

/**
* Utility method that performs the "Enable Service" flow.
* It handles the modal confirmation and asserts that the disabling button becomes visible afterwards.
* @param page - The Playwright Page object
* @param serviceId - The service id under test
*/
export const enableServiceFlow = async (page: Page, serviceId: string) => {
const btnEnable = page.getByTestId(`settingCard-${serviceId}-enableButton`);
const btnDisable = page.getByTestId(`settingCard-${serviceId}-disableButton`);
const dialogBtnEnable = page.getByTestId(`settingCard-${serviceId}-dialog-enableButton`);

await btnEnable.click();
await dialogBtnEnable.click();

await expect(page.getByText('In attivazione')).toBeVisible();
await expect(btnDisable).toBeVisible();
};

/**
* Utility method that performs the "Disable Service" flow.
* It handles the modal confirmation and asserts that the enabling button becomes visible afterwards.
* @param page - The Playwright Page object
* @param serviceId - The service id under test
*/
export const disableServiceFlow = async (page: Page, serviceId: string) => {
const btnEnable = page.getByTestId(`settingCard-${serviceId}-enableButton`);
const btnDisable = page.getByTestId(`settingCard-${serviceId}-disableButton`);
const dialogBtnDisable = page.getByTestId(`settingCard-${serviceId}-dialog-disableButton`);

await btnDisable.click();
await dialogBtnDisable.click();

await expect(page.getByText('In disattivazione')).toBeVisible();
await expect(btnEnable).toBeVisible();
};
5 changes: 5 additions & 0 deletions integration-test/tests/utils/e2eUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type ORG_TYPE = {
export const ORG = {
EC_DEMO_DIRECT: { id: '21079fe3-b5eb-4978-bef0-5588d11ab53f', taxCode: '99999000013' },
PSP_DEMO_DIRECT: { id: '5b7130fb-dbe1-4e3b-b02b-2a9cfaf54602', taxCode: '99999000011' },
EC_IPA: { id: '6b920f99-fc0d-4eb4-9f91-719a98ba48db', taxCode: '00067060947' },
};

export async function login(
Expand Down Expand Up @@ -73,6 +74,10 @@ export async function changeToPspUser(page: Page, isOperator?: boolean) {
await login(page, ORG.PSP_DEMO_DIRECT, isOperator);
}

export async function changeToEcIPAUser(page: Page, isOperator?: boolean) {
await login(page, ORG.EC_IPA, isOperator);
}

export function getTodayDate() {
const today = new Date();
const dd = String(today.getDate()).padStart(2, '0');
Expand Down
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ const SecuredRoutes = withLogin(
<ProtectedRoute
permission="settings"
flagValue="settings-section"
orgCheckCondition={(orgInfo) => orgInfo.types.isEcIPA}
>
<SettingsPage />
</ProtectedRoute>
Expand Down
Loading
Loading