(e2e) add mailboxe (dis/en)able check

This provides a new test to check the action on the mailbox item.
For now we can only enable or disable a mailbox.

We need to create the mailbox in the test, so it exists on Dimail side.
This commit is contained in:
Quentin BEY
2025-05-12 14:15:19 +02:00
parent 78cb3e693c
commit 8c67d4a004
3 changed files with 104 additions and 3 deletions

View File

@@ -21,7 +21,11 @@ from core import models
from demo import defaults
from mailbox_manager import models as mailbox_models
from mailbox_manager.enums import MailboxStatusChoices, MailDomainStatusChoices
from mailbox_manager.enums import (
MailboxStatusChoices,
MailDomainRoleChoices,
MailDomainStatusChoices,
)
fake = Faker()
@@ -366,6 +370,19 @@ def create_demo(stdout): # pylint: disable=too-many-locals
queue.flush()
# Enabled domain for 2E2 tests
enabled_domain, _created = mailbox_models.MailDomain.objects.get_or_create(
name="enabled-domain.com",
status=MailDomainStatusChoices.ENABLED,
support_email="support@enabled-domain.com",
)
domain_owner = models.User.objects.get(email="e2e.mail-owner@example.com")
mailbox_models.MailDomainAccess.objects.get_or_create(
domain=enabled_domain,
user=domain_owner,
role=MailDomainRoleChoices.OWNER,
)
# OIDC configuration
if settings.OAUTH2_PROVIDER.get("OIDC_ENABLED", False):
stdout.write("Creating OIDC client for People Identity Provider")

View File

@@ -40,13 +40,14 @@ def test_commands_create_demo(settings):
assert models.Team.objects.count() == TEST_NB_OBJECTS["teams"]
assert models.TeamAccess.objects.count() >= TEST_NB_OBJECTS["teams"]
assert mailbox_models.MailDomain.objects.count() == TEST_NB_OBJECTS["domains"] + 1
assert mailbox_models.MailDomain.objects.count() == TEST_NB_OBJECTS["domains"] + 1 + 1
# 3 domain access for each user with domain rights
# 3 x 3 domain access for each user with both rights
# 1 domain for E2E mail owner user
assert (
mailbox_models.MailDomainAccess.objects.count()
== TEST_NB_OBJECTS["domains"] + 3 + 9
== TEST_NB_OBJECTS["domains"] + 3 + 9 + 1
)

View File

@@ -192,6 +192,89 @@ test.describe('Mail domain', () => {
page.getByText('No mail box was created with this mail domain.'),
).toBeVisible();
});
test('can disable and enable mailbox', async ({ page, browserName }) => {
await page.goto('/');
await keyCloakSignIn(page, browserName, 'mail-owner');
await clickOnMailDomainsNavButton(page);
// Go to the enabled-domain.com management page
await expect(page).toHaveURL(/mail-domains\//);
await expect(
page.getByText('enabled-domain.com', { exact: true }),
).toBeVisible();
await page
.getByLabel(`enabled-domain.com listboxDomains button`)
.click();
await expect(page).toHaveURL(/mail-domains\/enabled-domaincom\//);
await expect(
page.getByRole('heading', { name: 'enabled-domain.com' }),
).toBeVisible();
// Click new mailbox button
await page.getByTestId('button-new-mailbox').click();
// Fill in mailbox form with random string
const randomString = Math.random().toString(36).substring(2, 8);
await page.getByLabel('First name').fill('John');
await page.getByLabel('Last name').fill('Doe');
await page.getByLabel('Name of the new address').fill(randomString);
await page
.getByLabel('Personal email address')
.fill(`${randomString}@example.com`);
// Submit form
await page.getByRole('button', { name: 'Create' }).click();
// Verify success toast appears
await expect(page.getByText('Mailbox created!')).toBeVisible();
// Verify mailbox appears in list
await expect(
page.getByText(`${randomString}@enabled-domain.com`),
).toBeVisible();
// Click the options button for the specific mailbox
await page
.getByRole('row', { name: `${randomString}@enabled-domain.com` })
.getByLabel('Open the access options modal')
.click();
// Click disable button
await page.getByText('Disable mailbox').click();
// Verify modal appears
await expect(
page.getByText('Are you sure you want to disable this mailbox?'),
).toBeVisible();
// Click disable in modal
await page.getByRole('button', { name: 'Disable' }).click();
// Verify mailbox status shows as disabled
await expect(
page
.getByRole('row', { name: `${randomString}@enabled-domain.com` })
.getByText('Disabled'),
).toBeVisible();
// Click options button again
await page
.getByRole('row', { name: `${randomString}@enabled-domain.com` })
.getByLabel('Open the access options modal')
.click();
// Click enable button
await page.getByText('Enable mailbox').click();
// Verify mailbox status shows as enabled
await expect(
page
.getByRole('row', { name: `${randomString}@enabled-domain.com` })
.getByText('Enabled'),
).toBeVisible();
});
});
test.describe('mail domain creation is pending', () => {