Skip to content

Commit

Permalink
test: fix tests where confirm-task decorator in passive use
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabauke committed Feb 1, 2022
1 parent 8b385ae commit 63baca5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
17 changes: 14 additions & 3 deletions addon/decorators/confirm-task.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -77,9 +90,7 @@ export function confirmTask(...decoratorArgs) {
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,
Expand Down
4 changes: 4 additions & 0 deletions tests/acceptance/permissions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
currentURL,
fillIn,
click,
waitFor,
waitUntil,
settled,
} from "@ember/test-helpers";
Expand Down Expand Up @@ -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}`);
Expand Down
3 changes: 3 additions & 0 deletions tests/acceptance/roles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
click,
fillIn,
findAll,
waitFor,
waitUntil,
settled,
} from "@ember/test-helpers";
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions tests/acceptance/scopes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
currentURL,
fillIn,
click,
waitFor,
waitUntil,
settled,
} from "@ember/test-helpers";
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/components/edit-form-test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -89,6 +89,9 @@ module("Integration | Component | edit-form", function (hooks) {
await render(hbs`<EditForm @model={{this.model}}/>`);

await click("[data-test-delete]");
await waitFor(".uk-modal.uk-open");
await click(".uk-modal .uk-button-primary");

assert.verifySteps(["destroyRecord"]);
});

Expand Down

0 comments on commit 63baca5

Please sign in to comment.