Skip to content

Commit

Permalink
test: add unfinished ctb edit test
Browse files Browse the repository at this point in the history
  • Loading branch information
innerdvations committed May 21, 2024
1 parent 6cd8875 commit 5da07f8
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { test, expect } from '@playwright/test';
import { login } from '../../../utils/login';
import { resetDatabaseAndImportDataFromPath } from '../../../utils/dts-import';
import { waitForRestart } from '../../../utils/restart';
import { resetFiles } from '../../../utils/file-reset';
import { kebabCase, snakeCase } from 'lodash/fp';
import pluralize from 'pluralize';
import { navToHeader, skipCtbTour } from '../../../utils/shared';

type ContentTypeData = {
name: string;
pluralId?: string;
singularId?: string;
};
const createCollectionType = async (page, data) => {
const { name, singularId, pluralId } = data;

await page.getByRole('button', { name: 'Create new collection type' }).click();

await expect(page.getByRole('heading', { name: 'Create a collection type' })).toBeVisible();

const displayName = page.getByLabel('Display name');
await displayName.fill(name);

const singularIdField = page.getByLabel('API ID (Singular)');
await expect(singularIdField).toHaveValue(singularId || kebabCase(name));
if (singularId) {
singularIdField.fill(singularId);
}

const pluralIdField = page.getByLabel('API ID (Plural)');
await expect(pluralIdField).toHaveValue(pluralId || pluralize(kebabCase(name)));
if (pluralId) {
pluralIdField.fill(pluralId);
}

await page.getByRole('button', { name: 'Continue' }).click();

// Create an initial text field for it
await expect(page.getByText('Select a field for your collection type')).toBeVisible();
await page.getByText('Small or long text').click();
await page.getByLabel('Name', { exact: true }).fill('myattribute');
await page.getByRole('button', { name: 'Finish' }).click();
await page.getByRole('button', { name: 'Save' }).click();

await waitForRestart(page);

await expect(page.getByRole('heading', { name })).toBeVisible();
};

test.describe('Edit collection type', () => {
const ctName = 'Secret Document';

test.beforeEach(async ({ page }) => {
await resetFiles();
await resetDatabaseAndImportDataFromPath('with-admin.tar');
await page.goto('/admin');

await login({ page });

await page.getByRole('link', { name: 'Content-Type Builder' }).click();

await skipCtbTour(page);

// TODO: create a "saveFileState" mechanism to be used so we don't have to do a full server restart before each test
// create a collection type to be used
await createCollectionType(page, {
name: ctName,
});
});

// TODO: each test should have a beforeAll that does this, maybe combine all the setup into one util to simplify it
// to keep other suites that don't modify files from needing to reset files, clean up after ourselves at the end
test.afterAll(async () => {
await resetFiles();
});

test('Can edit a collection type', async ({ page }) => {
await navToHeader(page, ['Content-Type Builder', ctName], ctName);
// await page.getByRole('button', { name: 'Create new collection type' }).click();

// await expect(page.getByRole('heading', { name: 'Create a collection type' })).toBeVisible();

// const displayName = page.getByLabel('Display name');
// await displayName.fill('Secret Document');

// const singularId = page.getByLabel('API ID (Singular)');
// await expect(singularId).toHaveValue('secret-document');

// const pluralId = page.getByLabel('API ID (Plural)');
// await expect(pluralId).toHaveValue('secret-documents');

// await page.getByRole('button', { name: 'Continue' }).click();

// await expect(page.getByText('Select a field for your collection type')).toBeVisible();
// await page.getByText('Small or long text').click();
// await page.getByLabel('Name', { exact: true }).fill('myattribute');
// await page.getByRole('button', { name: 'Finish' }).click();
// await page.getByRole('button', { name: 'Save' }).click();

// await waitForRestart(page);

// await expect(page.getByRole('heading', { name: 'Secret Document' })).toBeVisible();
});
});
18 changes: 18 additions & 0 deletions tests/e2e/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ export const navToHeader = async (page: Page, navItems: string[], headerText: st
return header;
};

/**
* Skip the tour if the modal is visible
*/
export const skipCtbTour = async (page: Page) => {
const modalSelector = 'role=button[name="Skip the tour"]';

try {
await page.waitForSelector(modalSelector, { timeout: 1000 });
const modal = page.locator(modalSelector);
if (await modal.isVisible()) {
await modal.click();
await expect(modal).not.toBeVisible();
}
} catch (e) {
// The modal did not appear, continue with the test
}
};

/**
* Look for an element containing text, and then click a sibling close button
*/
Expand Down

0 comments on commit 5da07f8

Please sign in to comment.