Skip to content

Commit

Permalink
feat(permissions): add a create view
Browse files Browse the repository at this point in the history
  • Loading branch information
velrest committed Oct 14, 2020
1 parent ac278ec commit c5846ae
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addon/routes/permissions/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import CreateRoute from "ember-emeis/routes/create";

export default class PermissionsNewRoute extends CreateRoute {
detailView = "permissions.edit";

model() {
return this.store.createRecord("permission");
}
}
1 change: 1 addition & 0 deletions app/routes/permissions/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "ember-emeis/routes/permissions/new";
45 changes: 45 additions & 0 deletions tests/acceptance/permissions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,51 @@ module("Acceptance | permissions", function (hooks) {
assert.equal(currentURL(), "/permissions");
});

test("create view /permissions/new", async function (assert) {
assert.expect(11);

const role = this.server.create("role");

await visit("/permissions");
assert.equal(currentURL(), "/permissions");
assert.dom("[data-test-permission-name]").doesNotExist();

await click("[data-test-new]");
assert.equal(currentURL(), "/permissions/new");

const name = "Permission 1",
description = "The one and only",
slug = "permission-1";

await fillIn('[name="name"]', name);
await fillIn('[name="description"]', description);
await fillIn('[name="slug"]', slug);
await selectChoose(".ember-power-select-trigger", role.name.en);

this.assertRequest("POST", "/api/v1/permissions", (request) => {
const { attributes, relationships } = JSON.parse(
request.requestBody
).data;

assert.equal(attributes.slug, slug);
assert.equal(attributes.name.en, name);
assert.equal(attributes.description.en, description);
assert.equal(relationships.roles.data[0].id, role.id);
});
await click("[data-test-save]");

// For some reason the await click is not actually waiting for the save task to finish.
// Probably some runloop issue.
await waitUntil(() => currentURL() !== "/permissions/new");

const permission = this.server.schema.permissions.first();
assert.equal(currentURL(), `/permissions/${permission.id}`);

assert.dom('[name="slug"]').hasAttribute("disabled");
assert.dom('[name="name"]').hasValue(permission.name.en);
assert.dom('[name="description"]').hasValue(permission.description.en);
});

test("delete /permissions/:id", async function (assert) {
assert.expect(5);

Expand Down

0 comments on commit c5846ae

Please sign in to comment.