37 lines
2.4 KiB
JavaScript
37 lines
2.4 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
|
|
const adminPageScript = fs.readFileSync(require.resolve('../src/web/public/js/admin/admin-page.js'), 'utf8');
|
|
|
|
test('async save errors keep validation failures as warning toasts', () => {
|
|
assert.ok(adminPageScript.includes('function isWarningSaveError(error)'));
|
|
assert.ok(adminPageScript.includes('error.status = response.status;'));
|
|
assert.ok(adminPageScript.includes('var variant = isWarningSaveError(error) ? \'warning\' : \'danger\';'));
|
|
});
|
|
|
|
test('async save runs success hooks before redirecting close or new saves', () => {
|
|
assert.ok(adminPageScript.includes('var responseText = await response.text();'));
|
|
assert.ok(adminPageScript.includes('if (typeof settings.afterSuccess === \'function\')'));
|
|
assert.ok(adminPageScript.includes('clearFormDirty(form);'));
|
|
assert.ok(adminPageScript.includes("if (submitterValue === 'close' || submitterValue === 'new')"));
|
|
});
|
|
|
|
test('data-source toggles update in place instead of reloading the edit form', () => {
|
|
assert.ok(adminPageScript.includes('function updateDataSourceToggle(form, response)'));
|
|
assert.ok(adminPageScript.includes('data-async-data-source-toggle'));
|
|
assert.ok(adminPageScript.includes("showToast(message || (willEnable ? 'Data source enabled.' : 'Data source disabled.'), 'success')"));
|
|
assert.ok(!adminPageScript.includes("/^\\/data-sources\\/(?:api-sources|rss-feeds|weather)\\/\\d+$/.test(actionPath);"));
|
|
assert.ok(adminPageScript.includes('data-source-toggle-owner'));
|
|
assert.ok(adminPageScript.includes("control.disabled = !willEnable || control.getAttribute('data-source-item-enabled') === 'false';"));
|
|
});
|
|
|
|
test('manual refresh targets poll and replace response panels instead of navigating the form', () => {
|
|
const start = adminPageScript.indexOf("var refreshButton = target.closest('[data-manual-refresh-url]');");
|
|
const end = adminPageScript.indexOf("var button = target.closest('button[name=\"save_action\"]", start);
|
|
const handler = adminPageScript.slice(start, end);
|
|
assert.match(handler, /getAttribute\('data-manual-refresh-target'\)/);
|
|
assert.match(handler, /if \(refreshTargetSelector\)\s*\{\s*return response\.json\(\)/);
|
|
assert.match(handler, /watchRefreshTask\(payload\.stateUrl, payload\.taskId, refreshTargetSelector, refreshSequence\)/);
|
|
assert.ok(handler.indexOf('return response.json()') < handler.indexOf('window.location.assign(response.url)'));
|
|
}); |