diff --git a/addon/components/meta-fields.hbs b/addon/components/meta-fields.hbs
index 8bc10c26..2fbc4846 100644
--- a/addon/components/meta-fields.hbs
+++ b/addon/components/meta-fields.hbs
@@ -16,13 +16,14 @@
{{/if}}
{{#if (eq field.type "text")}}
{{/if}}
{{/if}}
-{{/each}}
\ No newline at end of file
+{{/each}}
diff --git a/tests/acceptance/scopes-test.js b/tests/acceptance/scopes-test.js
index e5e8a615..3b502ffc 100644
--- a/tests/acceptance/scopes-test.js
+++ b/tests/acceptance/scopes-test.js
@@ -143,4 +143,35 @@ module("Acceptance | scopes", function (hooks) {
assert.equal(currentURL(), `/scopes?page=1`);
assert.dom("[data-test-scope-name]").doesNotExist();
});
+
+ test("list view /scopes/:id/acl", async function (assert) {
+ assert.expect(8);
+
+ const acl = this.server.createList("acl", 3)[0];
+ const scope = this.server.create("scope");
+
+ await visit(`/scopes/${scope.id}`);
+ await settled();
+
+ assert.dom("[data-test-scopes-edit-index-link]").exists();
+ assert.dom("[data-test-scopes-edit-acl-link]").exists();
+
+ this.assertRequest("GET", `/api/v1/acls`, (request) => {
+ assert.equal(scope.id, request.queryParams["filter[scope]"]);
+ });
+ await click("[data-test-scopes-edit-acl-link]");
+ assert.equal(currentURL(), `/scopes/${scope.id}/acl`);
+
+ // For some reason the await click is not actually waiting for the fetch task to finish.
+ // Probably some runloop issue.
+ await waitUntil(() => this.element.querySelector("table thead"));
+
+ assert.dom("[data-test-acl-role]").exists({ count: 3 });
+
+ assert
+ .dom("[data-test-acl-name]")
+ .hasText(`${acl.user.firstName} ${acl.user.lastName}`);
+ assert.dom("[data-test-acl-username]").hasText(acl.user.username);
+ assert.dom("[data-test-acl-role]").hasText(acl.role.name.en);
+ });
});
diff --git a/tests/dummy/mirage/factories/scope.js b/tests/dummy/mirage/factories/scope.js
index 46361b1c..3f7db9fb 100644
--- a/tests/dummy/mirage/factories/scope.js
+++ b/tests/dummy/mirage/factories/scope.js
@@ -6,5 +6,6 @@ import localize from "./localize";
export default Factory.extend({
name: () => localize(faker.company.companyName()),
description: () => localize(faker.lorem.paragraph()),
- level: () => faker.random.number({ max: 3 }),
+ level: () => faker.datatype.number({ max: 3 }),
+ meta: () => {},
});
diff --git a/tests/dummy/mirage/factories/user.js b/tests/dummy/mirage/factories/user.js
index 87b588c4..35c45551 100644
--- a/tests/dummy/mirage/factories/user.js
+++ b/tests/dummy/mirage/factories/user.js
@@ -9,11 +9,11 @@ export default Factory.extend({
lastName: () => faker.name.lastName(),
email: () => faker.internet.email(),
phone: () => faker.phone.phoneNumber(),
- disabled: () => faker.random.boolean(),
+ disabled: () => faker.datatype.boolean(),
language: () => faker.random.arrayElement(["en", "de"]),
address: () => faker.address.streetAddress(),
city: () => localize(faker.address.city()),
- zip: () => faker.random.number(),
+ zip: () => faker.datatype.number(),
meta: () => {},
- isActive: () => faker.random.boolean(),
+ isActive: () => faker.datatype.boolean(),
});
diff --git a/tests/dummy/mirage/identity-managers/uuid.js b/tests/dummy/mirage/identity-managers/uuid.js
index 2ebcaa4f..ff65799c 100644
--- a/tests/dummy/mirage/identity-managers/uuid.js
+++ b/tests/dummy/mirage/identity-managers/uuid.js
@@ -7,9 +7,9 @@ export default class {
// Returns a new unused unique identifier.
fetch() {
- let uuid = faker.random.uuid();
+ let uuid = faker.datatype.uuid();
while (this.ids.has(uuid)) {
- uuid = faker.random.uuid();
+ uuid = faker.datatype.uuid();
}
this.ids.add(uuid);
diff --git a/tests/integration/components/meta-fields-test.js b/tests/integration/components/meta-fields-test.js
index f6e035b1..70e18d77 100644
--- a/tests/integration/components/meta-fields-test.js
+++ b/tests/integration/components/meta-fields-test.js
@@ -1,14 +1,151 @@
-import { render } from "@ember/test-helpers";
+import Service from "@ember/service";
+import { fillIn, render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
+import { selectChoose } from "ember-power-select/test-support";
import { setupRenderingTest } from "ember-qunit";
import { module, test } from "qunit";
+class IntlStub extends Service {
+ primaryLocale = "en";
+}
+
+class EmeisOptionsStub extends Service {
+ metaFields = {
+ scope: [
+ {
+ slug: "meta-example",
+ label: {
+ en: "Example for custom choice field",
+ de: "Beispiel für benutzerdefiniertes Dropdown-Feld",
+ },
+ type: "choice",
+ options: [
+ {
+ value: "option-1",
+ label: {
+ en: "Ham",
+ de: "Schinken",
+ },
+ },
+ {
+ value: "Option 2",
+ label: {
+ en: "Cheese",
+ de: "Käse",
+ },
+ },
+ ],
+ visible: true,
+ readOnly: false,
+ },
+ {
+ slug: "meta-example-2",
+ label: {
+ en: "Example for custom text field",
+ de: "Beispiel für benutzerdefiniertes Textfeld",
+ },
+ type: "text",
+ visible: true,
+ readOnly: false,
+ },
+ ],
+ };
+}
+
module("Integration | Component | meta-fields", function (hooks) {
setupRenderingTest(hooks);
+ hooks.beforeEach(function () {
+ this.owner.register("service:intl", IntlStub);
+ this.owner.register("service:emeisOptions", EmeisOptionsStub);
+
+ this.intl = this.owner.lookup("service:intl");
+ this.emeisOptions = this.owner.lookup("service:emeisOptions");
+
+ this.model = {
+ name: {
+ de: "Hase",
+ en: "Rabbit",
+ },
+ description: {
+ de: "Ich bin ein Hase",
+ en: "I am a rabbit",
+ },
+ level: 1,
+ meta: {},
+ notifyPropertyChange: () => {},
+ };
+ });
+
test("it renders", async function (assert) {
await render(hbs``);
assert.dom(this.element).hasText("");
});
+
+ test("it renders meta field of type select and text", async function (assert) {
+ assert.expect(4);
+
+ await render(hbs`
+
+ `);
+
+ assert.dom(".ember-power-select-trigger").exists();
+ assert.dom("[data-test-meta-field-text]").exists();
+
+ await selectChoose(".ember-power-select-trigger", "Ham");
+ assert.deepEqual(this.model.meta, {
+ "meta-example": "option-1",
+ });
+
+ await fillIn("[data-test-meta-field-text]", "My value");
+ assert.deepEqual(this.model.meta, {
+ "meta-example": "option-1",
+ "meta-example-2": "My value",
+ });
+ });
+
+ test("it does not render meta fields", async function (assert) {
+ assert.expect(2);
+
+ // Set visibility to `false` for each field
+ this.emeisOptions.metaFields.scope.forEach(
+ (field) => (field.visible = false)
+ );
+
+ await render(hbs`
+
+ `);
+
+ assert.dom(".ember-power-select-trigger").doesNotExist();
+ assert.dom("[data-test-meta-field-text]").doesNotExist();
+ });
+
+ test("it renders disabled meta fields", async function (assert) {
+ assert.expect(4);
+
+ // Set fields to read-only
+ this.emeisOptions.metaFields.scope.forEach(
+ (field) => (field.readOnly = true)
+ );
+
+ await render(hbs`
+
+ `);
+
+ assert.dom(".ember-power-select-trigger").exists();
+ assert.dom("[data-test-meta-field-text]").exists();
+
+ assert.dom(".ember-power-select-trigger").hasAttribute("aria-disabled");
+ assert.dom("[data-test-meta-field-text]").hasAttribute("disabled");
+ });
});