Skip to content

Commit

Permalink
fix: add missing tests (#293)
Browse files Browse the repository at this point in the history
This will also make the required changes after bumping `faker`.

Co-authored-by: Akanksh Saxena <akanksh.saxena@adfinis-sygroup.ch>
  • Loading branch information
aziiee and Akanksh Saxena authored Nov 9, 2021
1 parent 96e5335 commit bbb972b
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 13 deletions.
13 changes: 7 additions & 6 deletions addon/components/meta-fields.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
{{/if}}
{{#if (eq field.type "text")}}
<input
class="uk-input"
type="text"
value={{get @model.meta field.slug}}
disabled={{field.readOnly}}
{{on "input" (fn this.updateMetaField field @model)}}
data-test-meta-field-text
class="uk-input"
type="text"
value={{get @model.meta field.slug}}
disabled={{field.readOnly}}
{{on "input" (fn this.updateMetaField field @model)}}
>
{{/if}}
</EditForm::Element>
{{/if}}
{{/each}}
{{/each}}
31 changes: 31 additions & 0 deletions tests/acceptance/scopes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
3 changes: 2 additions & 1 deletion tests/dummy/mirage/factories/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {},
});
6 changes: 3 additions & 3 deletions tests/dummy/mirage/factories/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
4 changes: 2 additions & 2 deletions tests/dummy/mirage/identity-managers/uuid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
139 changes: 138 additions & 1 deletion tests/integration/components/meta-fields-test.js
Original file line number Diff line number Diff line change
@@ -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`<MetaFields />`);

assert.dom(this.element).hasText("");
});

test("it renders meta field of type select and text", async function (assert) {
assert.expect(4);

await render(hbs`
<MetaFields
@model={{this.model}}
@fields={{this.emeisOptions.metaFields.scope}}
/>
`);

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`
<MetaFields
@model={{this.model}}
@fields={{this.emeisOptions.metaFields.scope}}
/>
`);

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`
<MetaFields
@model={{this.model}}
@fields={{this.emeisOptions.metaFields.scope}}
/>
`);

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");
});
});

0 comments on commit bbb972b

Please sign in to comment.