(frontend) user can add mail domain

- user can add an externally created mail domain
from UI and see the mail domain status on mail
domain page and left panel links.
- user can not create mailboxes to domain if mail
domain status is not equal to `enabled`
- update related tests and translations
This commit is contained in:
daproclaima
2024-08-14 17:43:10 +02:00
committed by Sebastien Nobour
parent b79725acbe
commit 49c238155c
25 changed files with 1326 additions and 316 deletions

View File

@@ -15,6 +15,7 @@ const mailDomainsFixtures: MailDomain[] = [
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
status: 'enabled',
abilities: {
get: true,
patch: true,
@@ -30,6 +31,7 @@ const mailDomainsFixtures: MailDomain[] = [
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'mailsfr',
status: 'enabled',
abilities: {
get: true,
patch: true,
@@ -45,6 +47,7 @@ const mailDomainsFixtures: MailDomain[] = [
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'versaillesnet',
status: 'enabled',
abilities: {
get: true,
patch: true,
@@ -60,6 +63,7 @@ const mailDomainsFixtures: MailDomain[] = [
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'parisfr',
status: 'enabled',
abilities: {
get: true,
patch: true,
@@ -95,7 +99,7 @@ const interceptCommonApiRequests = (page: Page) => {
});
});
void page.route('**/api/v1.0/mail-domains/domainfr', (route) => {
void page.route('**/api/v1.0/mail-domains/domainfr/', (route) => {
void route.fulfill({
json: mailDomainDomainFrFixture,
});
@@ -275,7 +279,7 @@ test.describe('Mail domain create mailbox', () => {
});
});
void page.route('**/api/v1.0/mail-domains/domainfr', (route) => {
void page.route('**/api/v1.0/mail-domains/domainfr/', (route) => {
void route.fulfill({
json: localMailDomainDomainFr,
});

View File

@@ -5,74 +5,113 @@ import { keyCloakSignIn } from './common';
const currentDateIso = new Date().toISOString();
const mailDomainsFixtures: MailDomain[] = [
{
name: 'domain.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43f',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
},
{
name: 'mails.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43e',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'mailsfr',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
},
{
name: 'versailles.net',
id: '456ac6ca-0402-4615-8005-69bc1efde43g',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'versaillesnet',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
},
{
name: 'paris.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43h',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'parisfr',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
},
];
const interceptCommonApiCalls = async (
page: Page,
arrayMailDomains: MailDomain[],
) => {
const singleMailDomain = arrayMailDomains[0];
await page.route('**/api/v1.0/mail-domains/?page=*', async (route) => {
await route.fulfill({
json: {
count: arrayMailDomains.length,
next: null,
previous: null,
results: arrayMailDomains,
},
});
});
const mailDomainDomainFrFixture = mailDomainsFixtures[0];
await page.route('**/api/v1.0/mail-domains/domainfr/', async (route) => {
await route.fulfill({
json: singleMailDomain,
});
});
await page.route(
'**/api/v1.0/mail-domains/domainfr/mailboxes/?page=1',
async (route) => {
await route.fulfill({
json: {
count: 0,
next: null,
previous: null,
results: [],
},
});
},
);
};
const clickOnMailDomainsNavButton = async (page: Page): Promise<void> =>
await page.locator('menu').first().getByLabel(`Mail Domains button`).click();
const assertMailDomainUpperElementsAreVisible = async (page: Page) => {
await expect(page).toHaveURL(/mail-domains\//);
await page.getByRole('listbox').first().getByText('domain.fr').click();
await expect(page).toHaveURL(/mail-domains\/domainfr\//);
await expect(page.getByRole('heading', { name: 'domain.fr' })).toBeVisible();
};
const assertFilledMailboxesTableElementsAreVisible = async (
page: Page,
domainFr: object & { name: string },
multiLevelArrayMailboxes: object & Array<{ local_part: string }[]>,
) => {
await expect(page).toHaveURL(/mail-domains\//);
await expect(
page.getByRole('button', { name: /Names/ }).first(),
).toBeVisible();
await expect(
page.getByRole('button', { name: /Emails/ }).first(),
).toBeVisible();
await Promise.all(
multiLevelArrayMailboxes[0].map((mailbox) =>
expect(
page.getByText(`${mailbox.local_part}@${domainFr.name}`),
).toBeVisible(),
),
);
const table = page.locator('table');
await expect(table).toBeVisible();
const tdNames = await table.getByText('John Doe').all();
expect(tdNames.length).toEqual(20);
await expect(
page.locator('.c__pagination__list').getByRole('button', { name: '1' }),
).toBeVisible();
await expect(
page.locator('.c__pagination__list').getByText('navigate_next'),
).toBeVisible();
await page
.locator('.c__pagination__list')
.getByRole('button', { name: '2' })
.click();
await expect(
page.locator('.c__pagination__list').getByText('navigate_next'),
).toBeHidden();
await expect(
page.locator('.c__pagination__list').getByText('navigate_before'),
).toBeVisible();
await Promise.all(
multiLevelArrayMailboxes[1].map((mailbox) =>
expect(
page.getByText(`${mailbox.local_part}@${domainFr.name}`),
).toBeVisible(),
),
);
};
test.describe('Mail domain', () => {
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
@@ -103,195 +142,645 @@ test.describe('Mail domain', () => {
});
});
test('checks all the elements are visible when domain exist but contains no mailboxes', async ({
page,
}) => {
const interceptApiCalls = async () => {
await page.route(
'**/api/v1.0/mail-domains/domainfr/mailboxes/?page=1',
async (route) => {
await route.fulfill({
json: {
count: 0,
next: null,
previous: null,
results: [],
},
});
},
);
await page.route('**/api/v1.0/mail-domains/domainfr**', async (route) => {
await route.fulfill({
json: mailDomainDomainFrFixture,
});
});
await page.route('**/api/v1.0/mail-domains/?page=*', async (route) => {
await route.fulfill({
json: {
count: mailDomainsFixtures.length,
next: null,
previous: null,
results: mailDomainsFixtures,
test.describe('user is administrator or owner', () => {
test.describe('mail domain is enabled', () => {
const mailDomainsFixtures: MailDomain[] = [
{
name: 'domain.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43f',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
status: 'enabled',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
});
},
{
name: 'mails.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43e',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'mailsfr',
status: 'enabled',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
},
{
name: 'versailles.net',
id: '456ac6ca-0402-4615-8005-69bc1efde43g',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'versaillesnet',
status: 'enabled',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
},
{
name: 'paris.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43h',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'parisfr',
status: 'enabled',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
},
];
test('checks all the elements are visible when domain exist but contains no mailboxes', async ({
page,
}) => {
await interceptCommonApiCalls(page, mailDomainsFixtures);
await clickOnMailDomainsNavButton(page);
await assertMailDomainUpperElementsAreVisible(page);
await expect(
page.getByRole('button', { name: 'Create a mailbox' }),
).toBeEnabled();
await expect(
page.getByText('No mail box was created with this mail domain.'),
).toBeVisible();
});
};
await interceptApiCalls();
test('checks all the elements are visible when domain exists and contains 2 pages of mailboxes', async ({
page,
}) => {
const mailboxesFixtures = {
domainFr: {
page1: Array.from({ length: 20 }, (_, i) => ({
id: `456ac6ca-0402-4615-8005-69bc1efde${i}f`,
first_name: 'john',
last_name: 'doe',
local_part: `local_part-${i}`,
secondary_email: `secondary_email-${i}`,
})),
page2: Array.from({ length: 2 }, (_, i) => ({
id: `456ac6ca-0402-4615-8005-69bc1efde${i}d`,
first_name: 'john',
last_name: 'doe',
local_part: `local_part-${i}`,
secondary_email: `secondary_email-${i}`,
})),
},
};
const interceptApiCalls = async () => {
await page.route(
'**/api/v1.0/mail-domains/?page=*',
async (route) => {
await route.fulfill({
json: {
count: mailDomainsFixtures.length,
next: null,
previous: null,
results: mailDomainsFixtures,
},
});
},
);
await page.route(
'**/api/v1.0/mail-domains/domainfr/',
async (route) => {
await route.fulfill({
json: mailDomainsFixtures[0],
});
},
);
await page.route(
'**/api/v1.0/mail-domains/domainfr/mailboxes/?page=1**',
async (route) => {
await route.fulfill({
json: {
count:
mailboxesFixtures.domainFr.page1.length +
mailboxesFixtures.domainFr.page2.length,
next: 'http://localhost:8071/api/v1.0/mail-domains/domainfr/mailboxes/?page=2',
previous: null,
results: mailboxesFixtures.domainFr.page1,
},
});
},
);
await page.route(
'**/api/v1.0/mail-domains/domainfr/mailboxes/?page=2**',
async (route) => {
await route.fulfill({
json: {
count:
mailboxesFixtures.domainFr.page1.length +
mailboxesFixtures.domainFr.page2.length,
next: null,
previous:
'http://localhost:8071/api/v1.0/mail-domains/domainfr/mailboxes/?page=1',
results: mailboxesFixtures.domainFr.page2,
},
});
},
);
};
await clickOnMailDomainsNavButton(page);
await interceptApiCalls();
await expect(page).toHaveURL(/mail-domains\//);
await clickOnMailDomainsNavButton(page);
await page.getByRole('listbox').first().getByText('domain.fr').click();
await expect(page).toHaveURL(/mail-domains\/domainfr\//);
await assertMailDomainUpperElementsAreVisible(page);
await expect(
page.getByRole('heading', { name: /domain\.fr/ }).first(),
).toBeVisible();
await expect(
page.getByRole('button', { name: 'Create a mailbox' }),
).toBeEnabled();
await expect(
page.getByText('No mail box was created with this mail domain.'),
).toBeVisible();
await assertFilledMailboxesTableElementsAreVisible(
page,
mailDomainsFixtures[0],
[mailboxesFixtures.domainFr.page1, mailboxesFixtures.domainFr.page2],
);
});
});
test.describe('mail domain creation is pending', () => {
const mailDomainsFixtures: MailDomain[] = [
{
name: 'domain.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43f',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
status: 'pending',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
},
];
test('checks expected elements are visible', async ({ page }) => {
await interceptCommonApiCalls(page, mailDomainsFixtures);
await clickOnMailDomainsNavButton(page);
await expect(page).toHaveURL(/mail-domains\//);
await page.getByRole('listbox').first().getByText('domain.fr').click();
await expect(page).toHaveURL(/mail-domains\/domainfr\//);
await expect(
page.getByRole('heading', { name: 'domain.fr' }),
).toBeVisible();
await expect(
page.getByText(
'Your domain name is being validated. ' +
'You will not be able to create mailboxes until your domain name has been validated by our team.',
),
).toBeVisible();
await expect(
page.getByRole('button', { name: 'Create a mailbox' }),
).toBeDisabled();
await expect(
page.getByText('No mail box was created with this mail domain.'),
).toBeVisible();
});
});
test.describe('mail domain is disabled', () => {
const mailDomainsFixtures: MailDomain[] = [
{
name: 'domain.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43f',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
status: 'disabled',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
},
];
test('checks expected elements are visible', async ({ page }) => {
await interceptCommonApiCalls(page, mailDomainsFixtures);
await clickOnMailDomainsNavButton(page);
await assertMailDomainUpperElementsAreVisible(page);
await expect(
page.getByText(
'This domain name is deactivated. No new mailboxes can be created.',
),
).toBeVisible();
await expect(
page.getByRole('button', { name: 'Create a mailbox' }),
).toBeDisabled();
await expect(
page.getByText('No mail box was created with this mail domain.'),
).toBeVisible();
});
});
test.describe('mail domain creation has failed', () => {
const mailDomainsFixtures: MailDomain[] = [
{
name: 'domain.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43f',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
status: 'failed',
abilities: {
get: true,
patch: true,
put: true,
post: true,
delete: true,
manage_accesses: true,
},
},
];
test('checks expected elements are visible', async ({ page }) => {
await interceptCommonApiCalls(page, mailDomainsFixtures);
await clickOnMailDomainsNavButton(page);
await assertMailDomainUpperElementsAreVisible(page);
await expect(
page.getByText(
'The domain name encounters an error. Please contact our support team to solve the problem:',
),
).toBeVisible();
await expect(
page.getByRole('link', { name: 'suiteterritoriale@anct.gouv.fr' }),
).toBeVisible();
await expect(
page.getByRole('button', { name: 'Create a mailbox' }),
).toBeDisabled();
await expect(
page.getByText('No mail box was created with this mail domain.'),
).toBeVisible();
});
});
});
test('checks all the elements are visible when domain exists and contains 2 pages of mailboxes', async ({
page,
}) => {
const mailboxesFixtures = {
domainFr: {
page1: Array.from({ length: 20 }, (_, i) => ({
id: `456ac6ca-0402-4615-8005-69bc1efde${i}f`,
first_name: 'john',
last_name: 'doe',
local_part: `local_part-${i}`,
secondary_email: `secondary_email-${i}`,
})),
page2: Array.from({ length: 2 }, (_, i) => ({
id: `456ac6ca-0402-4615-8005-69bc1efde${i}d`,
first_name: 'john',
last_name: 'doe',
local_part: `local_part-${i}`,
secondary_email: `secondary_email-${i}`,
})),
},
};
const interceptApiCalls = async () => {
await page.route('**/api/v1.0/mail-domains/?page=*', async (route) => {
await route.fulfill({
json: {
count: mailDomainsFixtures.length,
next: null,
previous: null,
results: mailDomainsFixtures,
test.describe('user is member', () => {
test.describe('mail domain is enabled', () => {
const mailDomainsFixtures: MailDomain[] = [
{
name: 'domain.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43f',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
status: 'enabled',
abilities: {
get: true,
patch: false,
put: false,
post: false,
delete: false,
manage_accesses: false,
},
});
});
await page.route('**/api/v1.0/mail-domains/domainfr', async (route) => {
await route.fulfill({
json: mailDomainDomainFrFixture,
});
});
await page.route(
'**/api/v1.0/mail-domains/domainfr/mailboxes/?page=1**',
async (route) => {
await route.fulfill({
json: {
count:
mailboxesFixtures.domainFr.page1.length +
mailboxesFixtures.domainFr.page2.length,
next: 'http://localhost:8071/api/v1.0/mail-domains/domainfr/mailboxes/?page=2',
previous: null,
results: mailboxesFixtures.domainFr.page1,
},
});
},
);
await page.route(
'**/api/v1.0/mail-domains/domainfr/mailboxes/?page=2**',
async (route) => {
await route.fulfill({
json: {
count:
mailboxesFixtures.domainFr.page1.length +
mailboxesFixtures.domainFr.page2.length,
next: null,
previous:
'http://localhost:8071/api/v1.0/mail-domains/domainfr/mailboxes/?page=1',
results: mailboxesFixtures.domainFr.page2,
},
});
{
name: 'mails.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43e',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'mailsfr',
status: 'enabled',
abilities: {
get: true,
patch: false,
put: false,
post: false,
delete: false,
manage_accesses: false,
},
},
);
};
{
name: 'versailles.net',
id: '456ac6ca-0402-4615-8005-69bc1efde43g',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'versaillesnet',
status: 'enabled',
abilities: {
get: true,
patch: false,
put: false,
post: false,
delete: false,
manage_accesses: false,
},
},
{
name: 'paris.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43h',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'parisfr',
status: 'enabled',
abilities: {
get: true,
patch: false,
put: false,
post: false,
delete: false,
manage_accesses: false,
},
},
];
await interceptApiCalls();
test('checks all the elements are visible when domain exist but contains no mailboxes', async ({
page,
}) => {
await interceptCommonApiCalls(page, mailDomainsFixtures);
await clickOnMailDomainsNavButton(page);
await clickOnMailDomainsNavButton(page);
await expect(page).toHaveURL(/mail-domains\//);
await assertMailDomainUpperElementsAreVisible(page);
await page.getByRole('listbox').first().getByText('domain.fr').click();
await expect(page).toHaveURL(/mail-domains\/domainfr\//);
await expect(
page.getByRole('button', { name: 'Create a mailbox' }),
).not.toBeInViewport();
await expect(
page.getByRole('heading', { name: 'domain.fr' }),
).toBeVisible();
await expect(
page.getByText('No mail box was created with this mail domain.'),
).toBeVisible();
});
await expect(
page.getByRole('button', { name: /Names/ }).first(),
).toBeVisible();
test('checks all the elements are visible when domain exists and contains 2 pages of mailboxes', async ({
page,
}) => {
const mailboxesFixtures = {
domainFr: {
page1: Array.from({ length: 20 }, (_, i) => ({
id: `456ac6ca-0402-4615-8005-69bc1efde${i}f`,
first_name: 'john',
last_name: 'doe',
local_part: `local_part-${i}`,
secondary_email: `secondary_email-${i}`,
})),
page2: Array.from({ length: 2 }, (_, i) => ({
id: `456ac6ca-0402-4615-8005-69bc1efde${i}d`,
first_name: 'john',
last_name: 'doe',
local_part: `local_part-${i}`,
secondary_email: `secondary_email-${i}`,
})),
},
};
const interceptApiCalls = async () => {
await page.route(
'**/api/v1.0/mail-domains/?page=*',
async (route) => {
await route.fulfill({
json: {
count: mailDomainsFixtures.length,
next: null,
previous: null,
results: mailDomainsFixtures,
},
});
},
);
await page.route(
'**/api/v1.0/mail-domains/domainfr/',
async (route) => {
await route.fulfill({
json: mailDomainsFixtures[0],
});
},
);
await page.route(
'**/api/v1.0/mail-domains/domainfr/mailboxes/?page=1**',
async (route) => {
await route.fulfill({
json: {
count:
mailboxesFixtures.domainFr.page1.length +
mailboxesFixtures.domainFr.page2.length,
next: 'http://localhost:8071/api/v1.0/mail-domains/domainfr/mailboxes/?page=2',
previous: null,
results: mailboxesFixtures.domainFr.page1,
},
});
},
);
await page.route(
'**/api/v1.0/mail-domains/domainfr/mailboxes/?page=2**',
async (route) => {
await route.fulfill({
json: {
count:
mailboxesFixtures.domainFr.page1.length +
mailboxesFixtures.domainFr.page2.length,
next: null,
previous:
'http://localhost:8071/api/v1.0/mail-domains/domainfr/mailboxes/?page=1',
results: mailboxesFixtures.domainFr.page2,
},
});
},
);
};
await expect(
page.getByRole('button', { name: /Emails/ }).first(),
).toBeVisible();
await interceptApiCalls();
await Promise.all(
mailboxesFixtures.domainFr.page1.map((mailbox) =>
expect(
await clickOnMailDomainsNavButton(page);
await assertMailDomainUpperElementsAreVisible(page);
await expect(
page.getByRole('button', { name: 'Create a mailbox' }),
).not.toBeInViewport();
await assertFilledMailboxesTableElementsAreVisible(
page,
mailDomainsFixtures[0],
[mailboxesFixtures.domainFr.page1, mailboxesFixtures.domainFr.page2],
);
});
});
test.describe('mail domain creation is pending', () => {
const mailDomainsFixtures: MailDomain[] = [
{
name: 'domain.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43f',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
status: 'pending',
abilities: {
get: true,
patch: false,
put: false,
post: false,
delete: false,
manage_accesses: false,
},
},
];
test('checks expected elements are visible', async ({ page }) => {
await interceptCommonApiCalls(page, mailDomainsFixtures);
await clickOnMailDomainsNavButton(page);
await expect(page).toHaveURL(/mail-domains\//);
await page.getByRole('listbox').first().getByText('domain.fr').click();
await expect(page).toHaveURL(/mail-domains\/domainfr\//);
await expect(
page.getByRole('heading', { name: 'domain.fr' }),
).toBeVisible();
await expect(
page.getByText(
`${mailbox.local_part}@${mailDomainDomainFrFixture.name}`,
'Your domain name is being validated. ' +
'You will not be able to create mailboxes until your domain name has been validated by our team.',
),
).toBeVisible(),
),
);
).toBeVisible();
const table = page.locator('table');
await expect(table).toBeVisible();
await expect(
page.getByRole('button', { name: 'Create a mailbox' }),
).not.toBeInViewport();
const tdNames = await table.getByText('John Doe').all();
expect(tdNames.length).toEqual(20);
await expect(
page.getByText('No mail box was created with this mail domain.'),
).toBeVisible();
});
});
await expect(
page.locator('.c__pagination__list').getByRole('button', { name: '1' }),
).toBeVisible();
test.describe('mail domain is disabled', () => {
const mailDomainsFixtures: MailDomain[] = [
{
name: 'domain.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43f',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
status: 'disabled',
abilities: {
get: true,
patch: false,
put: false,
post: false,
delete: false,
manage_accesses: false,
},
},
];
await expect(
page.locator('.c__pagination__list').getByText('navigate_next'),
).toBeVisible();
test('checks expected elements are visible', async ({ page }) => {
await interceptCommonApiCalls(page, mailDomainsFixtures);
await page
.locator('.c__pagination__list')
.getByRole('button', { name: '2' })
.click();
await clickOnMailDomainsNavButton(page);
await expect(
page.locator('.c__pagination__list').getByText('navigate_next'),
).toBeHidden();
await assertMailDomainUpperElementsAreVisible(page);
await expect(
page.locator('.c__pagination__list').getByText('navigate_before'),
).toBeVisible();
await Promise.all(
mailboxesFixtures.domainFr.page2.map((mailbox) =>
expect(
await expect(
page.getByText(
`${mailbox.local_part}@${mailDomainDomainFrFixture.name}`,
'This domain name is deactivated. No new mailboxes can be created.',
),
).toBeVisible(),
),
);
).toBeVisible();
await expect(
page.getByRole('button', { name: 'Create a mailbox' }),
).not.toBeInViewport();
await expect(
page.getByText('No mail box was created with this mail domain.'),
).toBeVisible();
});
});
test.describe('mail domain creation has failed', () => {
const mailDomainsFixtures: MailDomain[] = [
{
name: 'domain.fr',
id: '456ac6ca-0402-4615-8005-69bc1efde43f',
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
status: 'failed',
abilities: {
get: true,
patch: false,
put: false,
post: false,
delete: false,
manage_accesses: false,
},
},
];
test('checks expected elements are visible', async ({ page }) => {
await interceptCommonApiCalls(page, mailDomainsFixtures);
await clickOnMailDomainsNavButton(page);
await assertMailDomainUpperElementsAreVisible(page);
await expect(
page.getByText(
'The domain name encounters an error. Please contact our support team to solve the problem:',
),
).toBeVisible();
await expect(
page.getByRole('button', { name: 'Create a mailbox' }),
).not.toBeInViewport();
await expect(
page.getByText('No mail box was created with this mail domain.'),
).toBeVisible();
});
});
});
});

View File

@@ -0,0 +1,176 @@
import { expect, test } from '@playwright/test';
import { keyCloakSignIn, randomName } from './common';
test.beforeEach(async ({ page, browserName }) => {
await page.goto('/');
await keyCloakSignIn(page, browserName);
});
test.describe('Add Mail Domains', () => {
test('checks all the elements are visible', async ({ page }) => {
await page.goto('/mail-domains');
const buttonFromHomePage = page.getByRole('button', {
name: 'Add your mail domain',
});
await expect(buttonFromHomePage).toBeVisible();
await buttonFromHomePage.click();
await expect(buttonFromHomePage).toBeHidden();
await expect(
page.getByRole('heading', {
name: 'Add your mail domain',
level: 3,
}),
).toBeVisible();
const form = page.locator('form');
await expect(form.getByLabel('Domain name')).toBeVisible();
await expect(page.getByText('Example: saint-laurent.fr')).toBeVisible();
await expect(
page.getByRole('button', {
name: 'Add the domain',
}),
).toBeVisible();
await expect(
page.getByRole('button', {
name: 'Cancel',
}),
).toBeVisible();
});
test('checks the cancel button interaction', async ({ page }) => {
await page.goto('/mail-domains');
const buttonFromHomePage = page.getByRole('button', {
name: 'Add your mail domain',
});
await buttonFromHomePage.click();
await expect(buttonFromHomePage).toBeHidden();
await page
.getByRole('button', {
name: 'Cancel',
})
.click();
await expect(buttonFromHomePage).toBeVisible();
});
test('checks form invalid status', async ({ page }) => {
await page.goto('/mail-domains');
const buttonFromHomePage = page.getByRole('button', {
name: 'Add your mail domain',
});
await buttonFromHomePage.click();
const form = page.locator('form');
const inputName = form.getByLabel('Domain name');
const buttonSubmit = page.getByRole('button', {
name: 'Add the domain',
});
await expect(inputName).toBeVisible();
await expect(page.getByText('Example: saint-laurent.fr')).toBeVisible();
await expect(
page.getByRole('button', {
name: 'Cancel',
}),
).toBeEnabled();
await expect(buttonSubmit).toBeDisabled();
await inputName.fill('s');
await expect(page.getByText('Example: saint-laurent.fr')).toBeVisible();
await inputName.clear();
await expect(page.getByText('Example: saint-laurent.fr')).toBeVisible();
});
test('checks the routing on new mail domain added', async ({
page,
browserName,
}) => {
const mailDomainName = randomName('versailles.fr', browserName, 1)[0];
const mailDomainSlug = mailDomainName.replace('.', '');
await page.goto('/mail-domains');
const panel = page.getByLabel('Mail domains panel').first();
await panel.getByRole('link', { name: 'Add your mail domain' }).click();
const form = page.locator('form');
await form.getByLabel('Domain name').fill(mailDomainName);
await page.getByRole('button', { name: 'Add the domain' }).click();
await expect(page).toHaveURL(`/mail-domains\/${mailDomainSlug}/`);
await expect(
page.getByRole('heading', {
name: mailDomainName,
}),
).toBeVisible();
});
test('checks error when duplicate mail domain', async ({
page,
browserName,
}) => {
await page.goto('/mail-domains');
const panel = page.getByLabel('Mail domains panel').first();
const additionLink = panel.getByRole('link', {
name: 'Add your mail domain',
});
const form = page.locator('form');
const inputName = form.getByLabel('Domain name');
const submitButton = page.getByRole('button', {
name: 'Add the domain',
});
const mailDomainName = randomName('duplicate.fr', browserName, 1)[0];
const mailDomainSlug = mailDomainName.replace('.', '');
await additionLink.click();
await inputName.fill(mailDomainName);
await submitButton.click();
await expect(page).toHaveURL(`/mail-domains\/${mailDomainSlug}\/`);
await additionLink.click();
await inputName.fill(mailDomainName);
await submitButton.click();
await expect(
page.getByText(
'This mail domain is already used. Please, choose another one.',
),
).toBeVisible();
});
test('checks 404 on mail-domains/[slug] page', async ({ page }) => {
await page.goto('/mail-domains/unknown-domain');
await expect(
page.getByText(
'It seems that the page you are looking for does not exist or cannot be displayed correctly.',
),
).toBeVisible({
timeout: 15000,
});
});
});

View File

@@ -11,6 +11,7 @@ const mailDomainsFixtures: MailDomain[] = [
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'domainfr',
status: 'pending',
abilities: {
get: true,
patch: true,
@@ -26,6 +27,7 @@ const mailDomainsFixtures: MailDomain[] = [
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'mailsfr',
status: 'enabled',
abilities: {
get: true,
patch: true,
@@ -41,6 +43,7 @@ const mailDomainsFixtures: MailDomain[] = [
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'versaillesnet',
status: 'disabled',
abilities: {
get: true,
patch: true,
@@ -56,6 +59,7 @@ const mailDomainsFixtures: MailDomain[] = [
created_at: currentDateIso,
updated_at: currentDateIso,
slug: 'parisfr',
status: 'failed',
abilities: {
get: true,
patch: true,
@@ -99,7 +103,7 @@ test.describe('Mail domains', () => {
response.status() === 200,
);
const panel = page.getByLabel('mail domains panel').first();
const panel = page.getByLabel('Mail domains panel').first();
await panel
.getByRole('button', {
@@ -139,7 +143,7 @@ test.describe('Mail domains', () => {
.click();
await expect(page).toHaveURL(/mail-domains\//);
await expect(
page.getByLabel('mail domains panel', { exact: true }),
page.getByLabel('Mail domains panel', { exact: true }),
).toBeVisible();
await expect(page.getByText('No domains exist.')).toBeVisible();
});
@@ -163,13 +167,17 @@ test.describe('Mail domains', () => {
.click();
await expect(page).toHaveURL(/mail-domains\//);
await expect(
page.getByLabel('mail domains panel', { exact: true }),
page.getByLabel('Mail domains panel', { exact: true }),
).toBeVisible();
await expect(page.getByText('No domains exist.')).toHaveCount(0);
await expect(page.getByText('domain.fr')).toBeVisible();
await expect(page.getByText('mails.fr')).toBeVisible();
await expect(page.getByText('versailles.net')).toBeVisible();
await expect(page.getByText('paris.fr')).toBeVisible();
await Promise.all(
mailDomainsFixtures.map(async ({ name, status }) => {
const linkName = page.getByRole('link', { name });
await expect(linkName).toBeVisible();
await expect(linkName.getByText(`[${status}]`)).toBeVisible();
}),
);
});
});
});