Skip to content

Commit

Permalink
fixup! Added end-to-end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felixgirault committed Oct 11, 2024
1 parent 81877e8 commit 7022899
Showing 1 changed file with 77 additions and 49 deletions.
126 changes: 77 additions & 49 deletions e2e/orejime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,166 +18,194 @@ test.describe('Orejime', () => {
});

test('should show a notice', async ({page}) => {
const notice = await page.locator('.orejime-Banner');
const notice = page.locator('.orejime-Banner');
await expect(notice).toBeVisible();
});

test('should navigate to the notice first', async ({page}) => {
await page.keyboard.press('Tab');
const firstButton = await page.locator('.orejime-Banner-saveButton');
const firstButton = page.locator('.orejime-Banner-saveButton');
await expect(firstButton).toBeVisible();
});

test('should accept all purposes from the notice', async ({page, context}) => {
test('should accept all purposes from the notice', async ({
page,
context
}) => {
await page.locator('.orejime-Banner-saveButton').click();
const notice = await page.locator('.orejime-Banner');
const notice = page.locator('.orejime-Banner');
await expect(notice).not.toBeVisible();

const consents = await getConsentsFromCookies(context);

expect(consents).toEqual(expect.objectContaining({
'mandatory': true,
'inline-tracker': true,
'external-tracker': true
}));
expect(consents).toEqual(
expect.objectContaining({
'mandatory': true,
'inline-tracker': true,
'external-tracker': true
})
);
});

test('should decline all purposes from the notice', async ({page, context}) => {
test('should decline all purposes from the notice', async ({
page,
context
}) => {
await page.locator('.orejime-Banner-declineButton').click();
const notice = await page.locator('.orejime-Banner');
const notice = page.locator('.orejime-Banner');
await expect(notice).not.toBeVisible();

const consents = await getConsentsFromCookies(context);

expect(consents).toEqual(expect.objectContaining({
'mandatory': true,
'inline-tracker': false,
'external-tracker': false
}));
expect(consents).toEqual(
expect.objectContaining({
'mandatory': true,
'inline-tracker': false,
'external-tracker': false
})
);
});

test('should open a modal', async ({page}) => {
await page.locator('.orejime-Banner-learnMoreButton').click();
const notice = await page.locator('.orejime-Banner');
const notice = page.locator('.orejime-Banner');
await expect(notice).toBeVisible();

const modal = await page.locator('.orejime-Modal');
const modal = page.locator('.orejime-Modal');
await expect(modal).toBeVisible();
await expect(notice).toBeVisible();
});

test('should close the modal via the close button', async ({page}) => {
await page.locator('.orejime-Banner-learnMoreButton').click();
const modal = await page.locator('.orejime-Modal');
const modal = page.locator('.orejime-Modal');
await expect(modal).toBeVisible();

await page.locator('.orejime-Modal-closeButton').click();
await expect(modal).toHaveCount(0);

const notice = await page.locator('.orejime-Banner');
const notice = page.locator('.orejime-Banner');
await expect(notice).toBeVisible();
});

test('should close the modal via the overlay', async ({page}) => {
await page.locator('.orejime-Banner-learnMoreButton').click();
const modal = await page.locator('.orejime-Modal');
const modal = page.locator('.orejime-Modal');
await expect(modal).toBeVisible();

await page.locator('.orejime-ModalOverlay').click();
// We're clicking in a corner to avoid clicking on the
// modal itself, which has no effect.
await page.locator('.orejime-ModalOverlay').click({
position: {
x: 1,
y: 1
}
});

await expect(modal).toHaveCount(0);

const notice = await page.locator('.orejime-Banner');
const notice = page.locator('.orejime-Banner');
await expect(notice).toBeVisible();
});

test('should close the modal via `Escape` key', async ({page}) => {
await page.locator('.orejime-Banner-learnMoreButton').click();
const modal = await page.locator('.orejime-Modal');
const modal = page.locator('.orejime-Modal');
await expect(modal).toBeVisible();

await page.keyboard.press('Escape');
await expect(modal).toHaveCount(0);

const notice = await page.locator('.orejime-Banner');
const notice = page.locator('.orejime-Banner');
await expect(notice).toBeVisible();
});

test('should move focus after closing the modal', async ({page}) => {
const openModalButton = await page.locator('.orejime-Banner-learnMoreButton');
const openModalButton = page.locator('.orejime-Banner-learnMoreButton');
openModalButton.click();

const modal = await page.locator('.orejime-Modal');
const modal = page.locator('.orejime-Modal');
await expect(modal).toBeVisible();

await page.keyboard.press('Escape');
await expect(openModalButton).toBeFocused();
});

test('should accept all purposes from the modal', async ({page, context}) => {
test('should accept all purposes from the modal', async ({
page,
context
}) => {
await page.locator('.orejime-Banner-learnMoreButton').click();
await page.locator('.orejime-PurposeToggles-enableAll').click();

const checkbox = await page.locator('#orejime-purpose-inline-tracker');
const checkbox = page.locator('#orejime-purpose-inline-tracker');
await expect(checkbox).toBeChecked();

const mandatoryCheckbox = await page.locator('#orejime-purpose-mandatory');
const mandatoryCheckbox = page.locator('#orejime-purpose-mandatory');
await expect(mandatoryCheckbox).toBeChecked();

await page.locator('.orejime-Modal-saveButton').click();
const consents = await getConsentsFromCookies(context);

expect(consents).toEqual(expect.objectContaining({
'mandatory': true,
'inline-tracker': true,
'external-tracker': true
}));
expect(consents).toEqual(
expect.objectContaining({
'mandatory': true,
'inline-tracker': true,
'external-tracker': true
})
);

const notice = await page.locator('.orejime-Banner');
const notice = page.locator('.orejime-Banner');
await expect(notice).not.toBeVisible();
});

test('should decline all purposes from the modal', async ({page, context}) => {
test('should decline all purposes from the modal', async ({
page,
context
}) => {
await page.locator('.orejime-Banner-learnMoreButton').click();
await page.locator('.orejime-PurposeToggles-enableAll').click();
await page.locator('.orejime-PurposeToggles-disableAll').click();

const checkbox = await page.locator('#orejime-purpose-inline-tracker');
const checkbox = page.locator('#orejime-purpose-inline-tracker');
await expect(checkbox).not.toBeChecked();

const mandatoryCheckbox = await page.locator('#orejime-purpose-mandatory');
const mandatoryCheckbox = page.locator('#orejime-purpose-mandatory');
await expect(mandatoryCheckbox).toBeChecked();

await page.locator('.orejime-Modal-saveButton').click();
const consents = await getConsentsFromCookies(context);

expect(consents).toEqual(expect.objectContaining({
'mandatory': true,
'inline-tracker': false,
'external-tracker': false
}));
expect(consents).toEqual(
expect.objectContaining({
'mandatory': true,
'inline-tracker': false,
'external-tracker': false
})
);

const notice = await page.locator('.orejime-Banner');
const notice = page.locator('.orejime-Banner');
await expect(notice).not.toBeVisible();
});

test('should sync grouped purposes', async ({page}) => {
await page.locator('.orejime-Banner-learnMoreButton').click();

const checkbox = await page.locator('#orejime-purpose-inline-tracker');
const checkbox = page.locator('#orejime-purpose-inline-tracker');
await expect(checkbox).not.toBeChecked();

const checkbox2 = await page.locator('#orejime-purpose-external-tracker');
const checkbox2 = page.locator('#orejime-purpose-external-tracker');
await expect(checkbox2).not.toBeChecked();

const groupCheckbox = await page.locator('#orejime-purpose-group');
const groupCheckbox = page.locator('#orejime-purpose-group');
await groupCheckbox.check();
await expect(groupCheckbox).toBeChecked();
await expect(checkbox).toBeChecked();
await expect(checkbox2).toBeChecked();

await checkbox.uncheck();
await expect(groupCheckbox).not.toBeChecked();
await expect(groupCheckbox).toHaveJSProperty("indeterminate", true);
await expect(groupCheckbox).toHaveJSProperty('indeterminate', true);
await expect(checkbox).not.toBeChecked();
await expect(checkbox2).toBeChecked();

Expand Down

0 comments on commit 7022899

Please sign in to comment.