fix: preview button conditions (#3613)
This commit is contained in:
@@ -17,7 +17,15 @@ import CustomEditView from './components/views/CustomEdit'
|
||||
import CustomMinimalRoute from './components/views/CustomMinimal'
|
||||
import CustomVersionsView from './components/views/CustomVersions'
|
||||
import CustomView from './components/views/CustomView'
|
||||
import { globalSlug, postsSlug, slugPluralLabel, slugSingularLabel } from './shared'
|
||||
import {
|
||||
globalSlug,
|
||||
group1Collection1Slug,
|
||||
group1Collection2Slug,
|
||||
group1GlobalSlug,
|
||||
postsSlug,
|
||||
slugPluralLabel,
|
||||
slugSingularLabel,
|
||||
} from './shared'
|
||||
|
||||
export interface Post {
|
||||
createdAt: Date
|
||||
@@ -211,7 +219,7 @@ export default buildConfigWithDefaults({
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: 'group-one-collection-ones',
|
||||
slug: group1Collection1Slug,
|
||||
admin: {
|
||||
group: 'One',
|
||||
},
|
||||
@@ -223,7 +231,7 @@ export default buildConfigWithDefaults({
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: 'group-one-collection-twos',
|
||||
slug: group1Collection2Slug,
|
||||
admin: {
|
||||
group: 'One',
|
||||
},
|
||||
@@ -288,6 +296,7 @@ export default buildConfigWithDefaults({
|
||||
},
|
||||
admin: {
|
||||
group: 'Group',
|
||||
preview: () => 'https://payloadcms.com',
|
||||
},
|
||||
versions: {
|
||||
drafts: true,
|
||||
@@ -357,7 +366,7 @@ export default buildConfigWithDefaults({
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: 'group-globals-one',
|
||||
slug: group1GlobalSlug,
|
||||
label: 'Group Globals 1',
|
||||
admin: {
|
||||
group: 'Group',
|
||||
|
||||
@@ -17,7 +17,13 @@ import {
|
||||
} from '../helpers'
|
||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil'
|
||||
import { initPayloadE2E } from '../helpers/configHelpers'
|
||||
import { globalSlug, postsSlug, slugPluralLabel } from './shared'
|
||||
import {
|
||||
globalSlug,
|
||||
group1Collection1Slug,
|
||||
group1GlobalSlug,
|
||||
postsSlug,
|
||||
slugPluralLabel,
|
||||
} from './shared'
|
||||
|
||||
const { afterEach, beforeAll, beforeEach, describe } = test
|
||||
|
||||
@@ -149,6 +155,38 @@ describe('admin', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ui', () => {
|
||||
test('collection - should render preview button when `admin.preview` is set', async () => {
|
||||
const collectionWithPreview = new AdminUrlUtil(serverURL, postsSlug)
|
||||
await page.goto(collectionWithPreview.create)
|
||||
await page.locator('#field-title').fill(title)
|
||||
await saveDocAndAssert(page)
|
||||
await expect(page.locator('.btn.preview-btn')).toBeVisible()
|
||||
})
|
||||
|
||||
test('collection - should not render preview button when `admin.preview` is not set', async () => {
|
||||
const collectionWithoutPreview = new AdminUrlUtil(serverURL, group1Collection1Slug)
|
||||
await page.goto(collectionWithoutPreview.create)
|
||||
await page.locator('#field-title').fill(title)
|
||||
await saveDocAndAssert(page)
|
||||
await expect(page.locator('.btn.preview-btn')).toBeHidden()
|
||||
})
|
||||
|
||||
test('global - should render preview button when `admin.preview` is set', async () => {
|
||||
const globalWithPreview = new AdminUrlUtil(serverURL, globalSlug)
|
||||
await page.goto(globalWithPreview.global(globalSlug))
|
||||
await expect(page.locator('.btn.preview-btn')).toBeVisible()
|
||||
})
|
||||
|
||||
test('global - should not render preview button when `admin.preview` is not set', async () => {
|
||||
const globalWithoutPreview = new AdminUrlUtil(serverURL, group1GlobalSlug)
|
||||
await page.goto(globalWithoutPreview.global(group1GlobalSlug))
|
||||
await page.locator('#field-title').fill(title)
|
||||
await saveDocAndAssert(page)
|
||||
await expect(page.locator('.btn.preview-btn')).toBeHidden()
|
||||
})
|
||||
})
|
||||
|
||||
describe('doc titles', () => {
|
||||
test('collection - should render fallback titles when creating new', async () => {
|
||||
await page.goto(url.create)
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
export const postsSlug = 'posts'
|
||||
|
||||
export const group1Collection1Slug = 'group-one-collection-ones'
|
||||
|
||||
export const group1Collection2Slug = 'group-one-collection-twos'
|
||||
|
||||
export const slugSingularLabel = 'Post'
|
||||
|
||||
export const slugPluralLabel = 'Posts'
|
||||
|
||||
export const globalSlug = 'global'
|
||||
|
||||
export const group1GlobalSlug = 'group-globals-one'
|
||||
|
||||
Reference in New Issue
Block a user