Skip to content

Commit

Permalink
feat(roles): add create view
Browse files Browse the repository at this point in the history
  • Loading branch information
velrest committed Oct 14, 2020
1 parent c5846ae commit b9013d9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addon/routes/roles/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 RolesNewRoute extends CreateRoute {
detailView = "roles.edit";

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

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

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

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

const name = "Role 1",
description = "The one and only",
slug = "role-1";

await fillIn('[name="name"]', name);
await fillIn('[name="description"]', description);
await fillIn('[name="slug"]', slug);

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

assert.equal(attributes.slug, slug);
assert.equal(attributes.name.en, name);
assert.equal(attributes.description.en, description);
});
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() !== "/roles/new");

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

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

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

Expand Down

0 comments on commit b9013d9

Please sign in to comment.