2022-08-12 22:01:05 +00:00
|
|
|
import { expect } from '@playwright/test';
|
2023-05-16 08:36:15 +00:00
|
|
|
import { testFactory, waitForHydrate } from './test-utils.js';
|
2022-08-12 22:01:05 +00:00
|
|
|
|
|
|
|
const test = testFactory({
|
|
|
|
root: './fixtures/namespaced-component/',
|
|
|
|
});
|
|
|
|
|
|
|
|
let devServer;
|
|
|
|
|
2022-08-17 19:37:10 +00:00
|
|
|
test.beforeAll(async ({ astro }) => {
|
2022-08-12 22:01:05 +00:00
|
|
|
devServer = await astro.startDevServer();
|
|
|
|
});
|
|
|
|
|
2022-08-17 19:37:10 +00:00
|
|
|
test.afterAll(async () => {
|
2022-08-12 22:01:05 +00:00
|
|
|
await devServer.stop();
|
|
|
|
});
|
|
|
|
|
|
|
|
test.describe('Hydrating namespaced components', () => {
|
|
|
|
test('Preact Component', async ({ page }) => {
|
|
|
|
await page.goto('/');
|
|
|
|
|
2022-09-07 18:51:09 +00:00
|
|
|
// 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');
|
2022-09-07 18:51:09 +00:00
|
|
|
await expect(namespacedCounter, 'component is visible').toBeVisible();
|
2022-08-12 22:01:05 +00:00
|
|
|
|
2023-05-16 08:36:15 +00:00
|
|
|
const namespacedCount = namespacedCounter.locator('pre');
|
2022-09-07 18:51:09 +00:00
|
|
|
await expect(namespacedCount, 'initial count is 0').toHaveText('0');
|
2022-08-12 22:01:05 +00:00
|
|
|
|
2023-05-16 08:36:15 +00:00
|
|
|
const namespacedChildren = namespacedCounter.locator('.children');
|
2022-09-07 18:51:09 +00:00
|
|
|
await expect(namespacedChildren, 'children exist').toHaveText('preact (namespace import)');
|
2022-08-12 22:01:05 +00:00
|
|
|
|
2023-05-16 08:36:15 +00:00
|
|
|
await waitForHydrate(page, namespacedCounter);
|
|
|
|
|
|
|
|
const namespacedIncrement = namespacedCounter.locator('.increment');
|
2022-09-07 18:51:09 +00:00
|
|
|
await namespacedIncrement.click();
|
2022-08-12 22:01:05 +00:00
|
|
|
|
2022-09-07 18:51:09 +00:00
|
|
|
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');
|
2022-09-07 18:51:09 +00:00
|
|
|
await expect(namedCounter, 'component is visible').toBeVisible();
|
|
|
|
|
2023-05-16 08:36:15 +00:00
|
|
|
const namedCount = namedCounter.locator('pre');
|
2022-09-07 18:51:09 +00:00
|
|
|
await expect(namedCount, 'initial count is 0').toHaveText('0');
|
|
|
|
|
2023-05-16 08:36:15 +00:00
|
|
|
const namedChildren = namedCounter.locator('.children');
|
2022-09-07 18:51:09 +00:00
|
|
|
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');
|
2022-09-07 18:51:09 +00:00
|
|
|
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');
|
2022-09-07 18:51:09 +00:00
|
|
|
await expect(namespacedCounter, 'component is visible').toBeVisible();
|
|
|
|
|
2023-05-16 08:36:15 +00:00
|
|
|
const namespacedCount = namespacedCounter.locator('pre');
|
2022-09-07 18:51:09 +00:00
|
|
|
await expect(namespacedCount, 'initial count is 0').toHaveText('0');
|
|
|
|
|
2023-05-16 08:36:15 +00:00
|
|
|
const namespacedChildren = namespacedCounter.locator('.children');
|
2022-09-07 18:51:09 +00:00
|
|
|
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');
|
2022-09-07 18:51:09 +00:00
|
|
|
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');
|
2022-09-07 18:51:09 +00:00
|
|
|
await expect(namedCounter, 'component is visible').toBeVisible();
|
|
|
|
|
2023-05-16 08:36:15 +00:00
|
|
|
const namedCount = namedCounter.locator('pre');
|
2022-09-07 18:51:09 +00:00
|
|
|
await expect(namedCount, 'initial count is 0').toHaveText('0');
|
|
|
|
|
2023-05-16 08:36:15 +00:00
|
|
|
const namedChildren = namedCounter.locator('.children');
|
2022-09-07 18:51:09 +00:00
|
|
|
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');
|
2022-09-07 18:51:09 +00:00
|
|
|
await namedIncrement.click();
|
|
|
|
|
|
|
|
await expect(namedCount, 'count incremented by 1').toHaveText('1');
|
2022-08-12 22:01:05 +00:00
|
|
|
});
|
|
|
|
});
|