-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ctb): validate pluralName and collectionName correctly (#20347)
- Loading branch information
1 parent
0c9f2e7
commit 5277eaf
Showing
5 changed files
with
308 additions
and
2 deletions.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
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 { createCollectionType, navToHeader, skipCtbTour } from '../../../utils/shared'; | ||
|
||
test.describe('Edit collection type', () => { | ||
// use a name with a capital and a space to ensure we also test the kebab-casing conversion for api ids | ||
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, | ||
}); | ||
|
||
await navToHeader(page, ['Content-Type Builder', ctName], 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 toggle internationalization', async ({ page }) => { | ||
await page.getByRole('button', { name: 'Edit' }).click(); | ||
await page.getByRole('tab', { name: 'Advanced settings' }).click(); | ||
await page.getByText('Internationalization').click(); | ||
await page.getByRole('button', { name: 'Finish' }).click(); | ||
|
||
await waitForRestart(page); | ||
|
||
await expect(page.getByRole('heading', { name: 'Secret Document' })).toBeVisible(); | ||
}); | ||
|
||
test('Can toggle draft&publish', async ({ page }) => { | ||
await page.getByRole('button', { name: 'Edit' }).click(); | ||
await page.getByRole('tab', { name: 'Advanced settings' }).click(); | ||
await page.getByText('Draft & publish').click(); | ||
await page.getByRole('button', { name: 'Yes, disable' }).click(); | ||
await page.getByRole('button', { name: 'Finish' }).click(); | ||
|
||
await waitForRestart(page); | ||
|
||
await expect(page.getByRole('heading', { name: 'Secret Document' })).toBeVisible(); | ||
}); | ||
|
||
test('Can add a field with default value', async ({ page }) => { | ||
await page.getByRole('button', { name: 'Add another field', exact: true }).click(); | ||
await page | ||
.getByRole('button', { name: 'Text Small or long text like title or description' }) | ||
.click(); | ||
await page.getByLabel('Name', { exact: true }).fill('testfield'); | ||
await page.getByRole('tab', { name: 'Advanced settings' }).click(); | ||
await page.getByRole('textbox', { name: 'Default value' }).fill('mydefault'); | ||
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(); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
tests/e2e/tests/content-type-builder/single-type/create-single-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,56 @@ | ||
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'; | ||
|
||
test.describe('Create collection type', () => { | ||
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(); | ||
|
||
// close the tutorial modal if it's visible | ||
const modal = page.getByRole('button', { name: 'Close' }); | ||
if (modal.isVisible()) { | ||
await modal.click(); | ||
await expect(modal).not.toBeVisible(); | ||
} | ||
}); | ||
|
||
// 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 create a single type', async ({ page }) => { | ||
await page.getByRole('button', { name: 'Create new single type' }).click(); | ||
|
||
await expect(page.getByRole('heading', { name: 'Create a single 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 single 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(); | ||
}); | ||
}); |
76 changes: 76 additions & 0 deletions
76
tests/e2e/tests/content-type-builder/single-type/edit-single-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,76 @@ | ||
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 { createSingleType, navToHeader, skipCtbTour } from '../../../utils/shared'; | ||
|
||
test.describe('Edit single type', () => { | ||
// use a name with a capital and a space to ensure we also test the kebab-casing conversion for api ids | ||
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 createSingleType(page, { | ||
name: ctName, | ||
}); | ||
|
||
await navToHeader(page, ['Content-Type Builder', ctName], 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 toggle internationalization', async ({ page }) => { | ||
await page.getByRole('button', { name: 'Edit' }).click(); | ||
await page.getByRole('tab', { name: 'Advanced settings' }).click(); | ||
await page.getByText('Internationalization').click(); | ||
await page.getByRole('button', { name: 'Finish' }).click(); | ||
|
||
await waitForRestart(page); | ||
|
||
await expect(page.getByRole('heading', { name: 'Secret Document' })).toBeVisible(); | ||
}); | ||
|
||
test('Can toggle draft&publish', async ({ page }) => { | ||
await page.getByRole('button', { name: 'Edit' }).click(); | ||
await page.getByRole('tab', { name: 'Advanced settings' }).click(); | ||
await page.getByText('Draft & publish').click(); | ||
await page.getByRole('button', { name: 'Yes, disable' }).click(); | ||
await page.getByRole('button', { name: 'Finish' }).click(); | ||
|
||
await waitForRestart(page); | ||
|
||
await expect(page.getByRole('heading', { name: 'Secret Document' })).toBeVisible(); | ||
}); | ||
|
||
test('Can add a field with default value', async ({ page }) => { | ||
await page.getByRole('button', { name: 'Add another field', exact: true }).click(); | ||
await page | ||
.getByRole('button', { name: 'Text Small or long text like title or description' }) | ||
.click(); | ||
await page.getByLabel('Name', { exact: true }).fill('testfield'); | ||
await page.getByRole('tab', { name: 'Advanced settings' }).click(); | ||
await page.getByRole('textbox', { name: 'Default value' }).fill('mydefault'); | ||
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