clipwright/dashboard/e2e/specs/schedule-autofill.spec.js
pedro-bento 26b05ab56c
All checks were successful
CI / unit (push) Successful in 48s
CI / backend-e2e (push) Successful in 1m24s
CI / dashboard-e2e (push) Successful in 2m30s
feat(clips): auto-fill publish schedule from a global start date
Add a SCHEDULE START date picker to the results panel. When set, each
clip's post modal auto-fills its date/time from the clip's virality rank
(rank 1 = most viral): odd ranks on the picked date, even ranks the next
day, sharing the 6pm / 9pm / 1pm slots and repeating three slots per day
forward. Scheduling is switched on so the suggestion is visible up front.

Mapping lives in dashboard/src/lib/schedule.js; covered by a Playwright
spec (schedule-autofill).
2026-10-16 21:14:27 +01:00

53 lines
2.5 KiB
JavaScript

// Global schedule start date (results header) auto-fills each clip's post modal
// date/time from that clip's VIRALITY RANK (rank 1 = most viral = top card).
//
// The mocked session clips are:
// clip index 0 "First viral clip" score 91 -> rank 1
// clip index 1 "Second viral clip" score 77 -> rank 2
// Per the agreed cadence (odd rank on the picked date, even rank the next day,
// shared time cycles 18:00 -> 21:00 -> 13:00):
// rank 1 -> start date @ 18:00
// rank 2 -> start date + 1 day @ 18:00
import { test, expect } from '@playwright/test';
import { openApp, completedSession } from '../fixtures/app.js';
const START = '2030-01-02';
const seed = {
session: completedSession(),
postizUrl: 'http://postiz.e2e.local',
postizKey: 'postiz-e2e-key',
};
test.describe('global schedule auto-fill', () => {
test('prefills each clip post time from its virality rank', async ({ page }) => {
await openApp(page, { seed });
await expect(page.getByRole('heading', { name: 'First viral clip' })).toBeVisible();
// Pick the global start date in the results header.
await page.getByTestId('schedule-start-date').fill(START);
// Rank 1 (top card): start date @ 18:00, scheduling auto-enabled so the
// prefilled time is visible.
await page.getByRole('button', { name: 'post', exact: true }).nth(0).click();
let dialog = page.getByRole('dialog');
await expect(dialog.getByLabel('date', { exact: true })).toHaveValue(START);
await expect(dialog.getByLabel('time (HH:MM)', { exact: true })).toHaveValue('18:00');
await expect(dialog.getByRole('checkbox', { name: /schedule post/i })).toBeChecked();
await dialog.getByRole('button', { name: 'close' }).click();
// Rank 2: next day, same first time slot.
await page.getByRole('button', { name: 'post', exact: true }).nth(1).click();
dialog = page.getByRole('dialog');
await expect(dialog.getByLabel('date', { exact: true })).toHaveValue('2030-01-03');
await expect(dialog.getByLabel('time (HH:MM)', { exact: true })).toHaveValue('18:00');
});
test('with no start date the schedule stays off', async ({ page }) => {
await openApp(page, { seed });
await expect(page.getByRole('heading', { name: 'First viral clip' })).toBeVisible();
await page.getByRole('button', { name: 'post', exact: true }).nth(0).click();
const dialog = page.getByRole('dialog');
await expect(dialog.getByRole('checkbox', { name: /schedule post/i })).not.toBeChecked();
});
});