feat(ui): add timezone support to scheduled publish (#11090)
This PR extends timezone support to scheduled publish UI and collection, the timezone will be stored on the `input` JSON instead of the `waitUntil` date field so that we avoid needing a schema migration for SQL databases.  If a timezone is selected then the displayed date in the table will be formatted for that timezone. Timezones remain optional here as they can be deselected in which case the date will behave as normal, rendering and formatting to the user's local timezone. For the backend logic that can be left untouched since the underlying date values are stored in UTC the job runners will always handle this relative time by default. Todo: - [x] add e2e to this drawer too to ensure that dates are rendered as expected
This commit is contained in:
@@ -72,6 +72,8 @@ const { beforeAll, beforeEach, describe } = test
|
||||
let payload: PayloadTestSDK<Config>
|
||||
let context: BrowserContext
|
||||
|
||||
const londonTimezone = 'Europe/London'
|
||||
|
||||
describe('Versions', () => {
|
||||
let page: Page
|
||||
let url: AdminUrlUtil
|
||||
@@ -283,7 +285,9 @@ describe('Versions', () => {
|
||||
await page.locator('tbody tr .cell-title a').first().click()
|
||||
await page.waitForSelector('.doc-header__title', { state: 'visible' })
|
||||
await page.goto(`${page.url()}/versions`)
|
||||
expect(page.url()).toMatch(/\/versions/)
|
||||
await expect(() => {
|
||||
expect(page.url()).toMatch(/\/versions/)
|
||||
}).toPass({ timeout: 10000, intervals: [100] })
|
||||
})
|
||||
|
||||
test('should show collection versions view level action in collection versions view', async () => {
|
||||
@@ -388,7 +392,9 @@ describe('Versions', () => {
|
||||
const global = new AdminUrlUtil(serverURL, autoSaveGlobalSlug)
|
||||
const versionsURL = `${global.global(autoSaveGlobalSlug)}/versions`
|
||||
await page.goto(versionsURL)
|
||||
expect(page.url()).toMatch(/\/versions$/)
|
||||
await expect(() => {
|
||||
expect(page.url()).toMatch(/\/versions/)
|
||||
}).toPass({ timeout: 10000, intervals: [100] })
|
||||
})
|
||||
|
||||
test('collection - should autosave', async () => {
|
||||
@@ -1237,4 +1243,74 @@ describe('Versions', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Scheduled publish', () => {
|
||||
test.use({
|
||||
timezoneId: londonTimezone,
|
||||
})
|
||||
|
||||
test('correctly sets a UTC date for the chosen timezone', async () => {
|
||||
const post = await payload.create({
|
||||
collection: draftCollectionSlug,
|
||||
data: {
|
||||
title: 'new post',
|
||||
description: 'new description',
|
||||
},
|
||||
})
|
||||
|
||||
await page.goto(`${serverURL}/admin/collections/${draftCollectionSlug}/${post.id}`)
|
||||
|
||||
const publishDropdown = page.locator('.doc-controls__controls .popup-button')
|
||||
await publishDropdown.click()
|
||||
|
||||
const schedulePublishButton = page.locator(
|
||||
'.popup-button-list__button:has-text("Schedule Publish")',
|
||||
)
|
||||
await schedulePublishButton.click()
|
||||
|
||||
const drawerContent = page.locator('.schedule-publish__scheduler')
|
||||
|
||||
const dropdownControlSelector = drawerContent.locator(`.timezone-picker .rs__control`)
|
||||
const timezoneOptionSelector = drawerContent.locator(
|
||||
`.timezone-picker .rs__menu .rs__option:has-text("Paris")`,
|
||||
)
|
||||
await dropdownControlSelector.click()
|
||||
await timezoneOptionSelector.click()
|
||||
|
||||
const dateInput = drawerContent.locator('.date-time-picker__input-wrapper input')
|
||||
// Create a date for 2049-01-01 18:00:00
|
||||
const date = new Date(2049, 0, 1, 18, 0)
|
||||
|
||||
await dateInput.fill(date.toISOString())
|
||||
await page.keyboard.press('Enter') // formats the date to the correct format
|
||||
|
||||
const saveButton = drawerContent.locator('.schedule-publish__actions button')
|
||||
|
||||
await saveButton.click()
|
||||
|
||||
const upcomingContent = page.locator('.schedule-publish__upcoming')
|
||||
const createdDate = await upcomingContent.locator('.row-1 .cell-waitUntil').textContent()
|
||||
|
||||
await expect(() => {
|
||||
expect(createdDate).toContain('6:00:00 PM')
|
||||
}).toPass({ timeout: 10000, intervals: [100] })
|
||||
|
||||
const {
|
||||
docs: [createdJob],
|
||||
} = await payload.find({
|
||||
collection: 'payload-jobs',
|
||||
where: {
|
||||
'input.doc.value': {
|
||||
equals: String(post.id),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// eslint-disable-next-line payload/no-flaky-assertions
|
||||
expect(createdJob).toBeTruthy()
|
||||
|
||||
// eslint-disable-next-line payload/no-flaky-assertions
|
||||
expect(createdJob?.waitUntil).toEqual('2049-01-01T17:00:00.000Z')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user