diff --git a/addon/decorators/confirm-task.js b/addon/decorators/confirm-task.js index 59204b3e..4b4fd711 100644 --- a/addon/decorators/confirm-task.js +++ b/addon/decorators/confirm-task.js @@ -1,6 +1,8 @@ import { assert } from "@ember/debug"; import UIkit from "uikit"; +import ENV from "ember-emeis/config/environment"; + /** * This decorator makes heavy use of the UIKit modal. If anything breaks in future releases, it could be * caused by the use of non-public API in this decorator. @@ -19,15 +21,15 @@ async function confirm(text, options) { } } -function validate(args) { +function initOptions(args) { if (args.length === 1) { assert( "You should pass the confirm-task options as an object looking like this: { message: 'emeis.form.deleteMessage', cancel: 'emeis.form.back' } ", typeof args[0] === "object" ); - return true; + return args[0]; } - return false; + return {}; } function validateIntl(context) { @@ -40,7 +42,7 @@ function validateIntl(context) { function translateOptions(context, options) { const translated = {}; for (const key in options) { - if (LABELS.includes(key)) { + if (LABELS.includes(key) && context.intl.exists(options[key])) { translated[key] = context.intl.t(options[key]); } } @@ -56,6 +58,17 @@ function translateOptions(context, options) { }; } +function filterOptions(options) { + const filteredOptions = Object.fromEntries( + Object.entries(options).filter(([key]) => !LABELS.includes(key)) + ); + + if (ENV.environment === "test") { + filteredOptions.container = "#ember-testing"; + } + return filteredOptions; +} + // make sure that decorator can be called with or without arguments const makeFlexibleDecorator = (decorateFn, args) => { if (args.length === 3 && !args[0].message) { @@ -67,19 +80,23 @@ const makeFlexibleDecorator = (decorateFn, args) => { }; export function confirmTask(...decoratorArgs) { - const options = validate(decoratorArgs) ? decoratorArgs[0] : {}; + const options = initOptions(decoratorArgs); function decorate(target, property, desc) { const gen = desc.value; desc.value = function* (...args) { + const event = args.find((arg) => arg instanceof Event); + + if (event) { + event.preventDefault(); + } + validateIntl(this); const translatedOptions = translateOptions(this, options); // append other options which are not confirm-labels to the modal object // that way you can modify the modal with further options like "container" - const filteredOptions = Object.fromEntries( - Object.entries(options).filter(([key]) => !LABELS.includes(key)) - ); + const filteredOptions = filterOptions(options); if ( !(yield confirm(translatedOptions.labels.message, { ...translatedOptions, diff --git a/addon/templates/users/index.hbs b/addon/templates/users/index.hbs index c14c3a85..b3649a58 100644 --- a/addon/templates/users/index.hbs +++ b/addon/templates/users/index.hbs @@ -31,7 +31,6 @@ {{t "emeis.scopes.title"}} - {{t "emeis.actions"}} @@ -92,7 +91,7 @@ {{/each}} - + diff --git a/app/styles/ember-emeis.scss b/app/styles/ember-emeis.scss index 3c0df837..8940e035 100644 --- a/app/styles/ember-emeis.scss +++ b/app/styles/ember-emeis.scss @@ -67,6 +67,10 @@ div.uk-grid-divider-fix.uk-grid-stack > .uk-grid-margin::before { } } +.uk-table td.small-padding-right { + padding-right: 1.75em; +} + .sortable-th { cursor: pointer; diff --git a/tests/acceptance/permissions-test.js b/tests/acceptance/permissions-test.js index bd20e10a..43718634 100644 --- a/tests/acceptance/permissions-test.js +++ b/tests/acceptance/permissions-test.js @@ -3,6 +3,7 @@ import { currentURL, fillIn, click, + waitFor, waitUntil, settled, } from "@ember/test-helpers"; @@ -151,6 +152,9 @@ module("Acceptance | permissions", function (hooks) { }); await click("[data-test-delete]"); + await waitFor(".uk-modal.uk-open"); + await click(".uk-modal .uk-button-primary"); + // For some reason the await click is not actually waiting for the delete task to finish. // Probably some runloop issue. await waitUntil(() => currentURL() !== `/permissions/${permission.id}`); diff --git a/tests/acceptance/roles-test.js b/tests/acceptance/roles-test.js index 6e6117b0..a0a7b67b 100644 --- a/tests/acceptance/roles-test.js +++ b/tests/acceptance/roles-test.js @@ -4,6 +4,7 @@ import { click, fillIn, findAll, + waitFor, waitUntil, settled, } from "@ember/test-helpers"; @@ -131,6 +132,8 @@ module("Acceptance | roles", function (hooks) { assert.strictEqual(role.id, request.params.id); }); await click("[data-test-delete]"); + await waitFor(".uk-modal.uk-open"); + await click(".uk-modal .uk-button-primary"); // For some reason the await click is not actually waiting for the delete task to finish. // Probably some runloop issue. diff --git a/tests/acceptance/scopes-test.js b/tests/acceptance/scopes-test.js index 513de558..61a96b7e 100644 --- a/tests/acceptance/scopes-test.js +++ b/tests/acceptance/scopes-test.js @@ -3,6 +3,7 @@ import { currentURL, fillIn, click, + waitFor, waitUntil, settled, } from "@ember/test-helpers"; @@ -140,6 +141,8 @@ module("Acceptance | scopes", function (hooks) { assert.strictEqual(scope.id, request.params.id); }); await click("[data-test-delete]"); + await waitFor(".uk-modal.uk-open"); + await click(".uk-modal .uk-button-primary"); // For some reason the await click is not actually waiting for the delete task to finish. // Probably some runloop issue. diff --git a/tests/integration/components/edit-form-test.js b/tests/integration/components/edit-form-test.js index e944d9a1..964f09b4 100644 --- a/tests/integration/components/edit-form-test.js +++ b/tests/integration/components/edit-form-test.js @@ -1,5 +1,5 @@ import Service from "@ember/service"; -import { render, click } from "@ember/test-helpers"; +import { render, click, waitFor } from "@ember/test-helpers"; import { hbs } from "ember-cli-htmlbars"; import { setupIntl } from "ember-intl/test-support"; import { setupRenderingTest } from "ember-qunit"; @@ -89,6 +89,9 @@ module("Integration | Component | edit-form", function (hooks) { await render(hbs``); await click("[data-test-delete]"); + await waitFor(".uk-modal.uk-open"); + await click(".uk-modal .uk-button-primary"); + assert.verifySteps(["destroyRecord"]); });