-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cd8875
commit 5da07f8
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
tests/e2e/tests/content-type-builder/collection-type/edit-collection-type.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters