import { describe, expect, test } from 'bun:test' import { readFileSync } from 'node:fs' import { resolve } from 'node:path' /** * What a record's edit page says when Save changes is clicked. * * Saving with nothing changed returned to the list in silence, which read as * the click doing nothing; a save with no changes now says so rather than * claiming a success it did not have. The toasts stack in the top right, * over the workspace bar, where the dashboard's owner wants them (they spent * a day in the top left, over the sidebar's project switcher). */ const layout = readFileSync(resolve('storage/framework/defaults/views/dashboard/layouts/default.stx'), 'utf8') const edit = readFileSync(resolve('storage/framework/defaults/resources/components/Dashboard/Models/ModelRecordEdit.stx'), 'utf8') describe('feedback after Save changes', () => { test('the dashboard\'s toasts stack in the top right', () => { const container = layout.match(/
\s*
/^left-/.test(name))).toEqual([]) }) test('a save with nothing changed says so before returning', () => { const save = edit.slice(edit.indexOf('async function save()'), edit.indexOf('/** The record and its rows in one request')) const unchanged = save.slice(save.indexOf('if (Object.keys(fields).length === 0 && related.length === 0) {'), save.indexOf('saving.set(true)')) expect(unchanged).toMatch(/pushToast\('info', 'No changes to save'/) expect(unchanged.indexOf('pushToast(')).toBeLessThan(unchanged.indexOf('navigate(returnHref())')) }) test('a save that wrote something still reports its success', () => { expect(edit).toContain("pushToast('success', `${current.modelName} ${recordId()} updated`)") expect(edit).toContain("pushToast('success', `${current.modelName} ${recordId()} saved`") }) })