astro/packages/astro/e2e/namespaced-component.test.js

95 lines
3.4 KiB
JavaScript
Raw Normal View History

import { expect } from '@playwright/test';
2023-05-16 08:36:15 +00:00
import { testFactory, waitForHydrate } from './test-utils.js';
const test = testFactory({
root: './fixtures/namespaced-component/',
});
let devServer;
test.beforeAll(async ({ astro }) => {
devServer = await astro.startDevServer();
});
test.afterAll(async () => {
await devServer.stop();
});
test.describe('Hydrating namespaced components', () => {
test('Preact Component', async ({ page }) => {
await page.goto('/');
// Counter declared with: <ns.components.PreactCounter id="preact-counter-namespace" client:load>
2023-05-16 08:36:15 +00:00
const namespacedCounter = page.locator('#preact-counter-namespace');
await expect(namespacedCounter, 'component is visible').toBeVisible();
2023-05-16 08:36:15 +00:00
const namespacedCount = namespacedCounter.locator('pre');
await expect(namespacedCount, 'initial count is 0').toHaveText('0');
2023-05-16 08:36:15 +00:00
const namespacedChildren = namespacedCounter.locator('.children');
await expect(namespacedChildren, 'children exist').toHaveText('preact (namespace import)');
2023-05-16 08:36:15 +00:00
await waitForHydrate(page, namespacedCounter);
const namespacedIncrement = namespacedCounter.locator('.increment');
await namespacedIncrement.click();
await expect(namespacedCount, 'count incremented by 1').toHaveText('1');
// Counter declared with: <components.PreactCounterTwo id="preact-counter-named" client:load>
2023-05-16 08:36:15 +00:00
const namedCounter = page.locator('#preact-counter-named');
await expect(namedCounter, 'component is visible').toBeVisible();
2023-05-16 08:36:15 +00:00
const namedCount = namedCounter.locator('pre');
await expect(namedCount, 'initial count is 0').toHaveText('0');
2023-05-16 08:36:15 +00:00
const namedChildren = namedCounter.locator('.children');
await expect(namedChildren, 'children exist').toHaveText('preact (named import)');
2023-05-16 08:36:15 +00:00
await waitForHydrate(page, namedCounter);
const namedIncrement = namedCounter.locator('.increment');
await namedIncrement.click();
await expect(namedCount, 'count incremented by 1').toHaveText('1');
});
test('MDX', async ({ page }) => {
await page.goto('/mdx');
// Counter declared with: <ns.components.PreactCounter id="preact-counter-namespace" client:load>
2023-05-16 08:36:15 +00:00
const namespacedCounter = page.locator('#preact-counter-namespace');
await expect(namespacedCounter, 'component is visible').toBeVisible();
2023-05-16 08:36:15 +00:00
const namespacedCount = namespacedCounter.locator('pre');
await expect(namespacedCount, 'initial count is 0').toHaveText('0');
2023-05-16 08:36:15 +00:00
const namespacedChildren = namespacedCounter.locator('.children');
await expect(namespacedChildren, 'children exist').toHaveText('preact (namespace import)');
2023-05-16 08:36:15 +00:00
await waitForHydrate(page, namespacedCounter);
const namespacedIncrement = namespacedCounter.locator('.increment');
await namespacedIncrement.click();
await expect(namespacedCount, 'count incremented by 1').toHaveText('1');
// Counter declared with: <components.PreactCounterTwo id="preact-counter-named" client:load>
2023-05-16 08:36:15 +00:00
const namedCounter = page.locator('#preact-counter-named');
await expect(namedCounter, 'component is visible').toBeVisible();
2023-05-16 08:36:15 +00:00
const namedCount = namedCounter.locator('pre');
await expect(namedCount, 'initial count is 0').toHaveText('0');
2023-05-16 08:36:15 +00:00
const namedChildren = namedCounter.locator('.children');
await expect(namedChildren, 'children exist').toHaveText('preact (named import)');
2023-05-16 08:36:15 +00:00
await waitForHydrate(page, namedCounter);
const namedIncrement = namedCounter.locator('.increment');
await namedIncrement.click();
await expect(namedCount, 'count incremented by 1').toHaveText('1');
});
});