Release v2.5.6
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const path = require('node:path');
|
||||
const Handlebars = require('handlebars');
|
||||
|
||||
const { registerHandlebars } = require('../src/web/handlebars');
|
||||
|
||||
function compileActionButtons(hash) {
|
||||
const hb = Handlebars.create();
|
||||
registerHandlebars(hb, {
|
||||
viewsRoot: path.join(__dirname, '..', 'src', 'web', 'views'),
|
||||
hasPermission: () => true,
|
||||
hasAnyPermission: () => true
|
||||
});
|
||||
|
||||
const template = hb.compile('{{{saveActionButtons ' + Object.entries(hash).map(function ([key, value]) {
|
||||
return key + '="' + String(value).replace(/"/g, '"') + '"';
|
||||
}).join(' ') + '}}}');
|
||||
|
||||
return String(template({}));
|
||||
}
|
||||
|
||||
test('save action buttons render save close new cancel and delete controls', () => {
|
||||
const html = compileActionButtons({
|
||||
formId: 'example-form',
|
||||
saveUrl: '/items/1',
|
||||
cancelUrl: '/items',
|
||||
deleteUrl: '/items/1/delete',
|
||||
deleteConfirmMessage: 'Delete this item?',
|
||||
deleteTitle: 'Delete is disabled.',
|
||||
showSaveAndClose: true,
|
||||
showSaveAndNew: true,
|
||||
showDelete: true
|
||||
});
|
||||
|
||||
assert.match(html, /<button type="submit" class="btn btn-success" form="example-form" name="save_action" value="save">Save<\/button>/);
|
||||
assert.match(html, /name="save_action" value="close">Save and Close<\/button>/);
|
||||
assert.match(html, /name="save_action" value="new">Save and New<\/button>/);
|
||||
assert.match(html, /<a class="btn btn-warning" href="\/items" data-confirm-unsaved="You have unsaved changes\. Leave this page\?">Cancel<\/a>/);
|
||||
assert.match(html, /<button type="button" class="btn btn-danger" data-delete-action-url="\/items\/1\/delete" data-confirm-message="Delete this item\?">Delete<\/button>/);
|
||||
});
|
||||
|
||||
test('save action buttons can hide the secondary dropdown and delete control', () => {
|
||||
const html = compileActionButtons({
|
||||
formId: 'example-form',
|
||||
saveUrl: '/items/1',
|
||||
cancelUrl: '/items',
|
||||
showSaveAndClose: false,
|
||||
showSaveAndNew: false,
|
||||
showDelete: false
|
||||
});
|
||||
|
||||
assert.match(html, /<button type="submit" class="btn btn-success" form="example-form" name="save_action" value="save">Save<\/button>/);
|
||||
assert.doesNotMatch(html, /Save and Close/);
|
||||
assert.doesNotMatch(html, /Save and New/);
|
||||
assert.match(html, /<a class="btn btn-warning" href="\/items" data-confirm-unsaved="You have unsaved changes\. Leave this page\?">Cancel<\/a>/);
|
||||
assert.doesNotMatch(html, /Delete<\/button>/);
|
||||
});
|
||||
|
||||
test('save action buttons keep the new action wired for create pages', () => {
|
||||
const html = compileActionButtons({
|
||||
formId: 'example-form',
|
||||
saveUrl: '/users',
|
||||
cancelUrl: '/users',
|
||||
showSaveAndClose: true,
|
||||
showSaveAndNew: true,
|
||||
showDelete: true
|
||||
});
|
||||
|
||||
assert.match(html, /name="save_action" value="new">Save and New<\/button>/);
|
||||
assert.match(html, /name="save_action" value="close">Save and Close<\/button>/);
|
||||
});
|
||||
Reference in New Issue
Block a user