Skip to content

Commit

Permalink
feat(user): add create view
Browse files Browse the repository at this point in the history
  • Loading branch information
velrest authored and anehx committed Oct 21, 2020
1 parent 2b19e3f commit 7a3caf4
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addon/routes/users/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import CreateRoute from "ember-emeis/-private/routes/create";

export default class UsersNewRoute extends CreateRoute {
detailView = "users.edit.index";

model() {
return this.store.createRecord("user");
}
}
1 change: 1 addition & 0 deletions app/routes/users/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "ember-emeis/routes/users/new";
74 changes: 74 additions & 0 deletions tests/acceptance/users-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,78 @@ module("Acceptance | users", function (hooks) {
await click("[data-test-back]");
assert.equal(currentURL(), "/users");
});

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

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

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

assert.dom("[data-test-edit-link]").doesNotExist();
assert.dom("[data-test-acl-link]").doesNotExist();

const username = "newusername",
firstName = "John",
lastName = "Doe",
email = "[email protected]",
phone = "123 123 12 23",
language = "de",
address = "Somestreet 32",
city = "Sity",
zip = "2313";

await fillIn('[name="username"]', username);
await fillIn('[name="firstName"]', firstName);
await fillIn('[name="lastName"]', lastName);
await fillIn('[name="email"]', email);
await fillIn('[name="phone"]', phone);
await fillIn('[name="language"]', language);
await fillIn('[name="address"]', address);
await fillIn('[name="city"]', city);
await fillIn('[name="zip"]', zip);

await click('[name="isActive"]');

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

assert.equal(attributes.username, username);
assert.equal(attributes["first-name"], firstName);
assert.equal(attributes["last-name"], lastName);
assert.equal(attributes.email, email);
assert.equal(attributes.phone, phone);
assert.equal(attributes.language, language);
assert.equal(attributes.address, address);
assert.equal(attributes.city.en, city);
assert.equal(attributes.zip, zip);
assert.equal(attributes["is-active"], true);
});
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() !== "/users/new");

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

assert.dom('[name="username"]').hasValue(user.username);
assert.dom('[name="firstName"]').hasValue(user.firstName);
assert.dom('[name="lastName"]').hasValue(user.lastName);
assert.dom('[name="email"]').hasValue(user.email);
assert.dom('[name="phone"]').hasValue(user.phone);
assert.dom('[name="language"]').hasValue(user.language);
assert.dom('[name="address"]').hasValue(user.address);
assert.dom('[name="city"]').hasValue(user.city.en);
assert.dom('[name="zip"]').hasValue(user.zip.toString());

assert.dom('[name="isActive"]').isChecked();

assert.dom("[data-test-edit-link]").exists();
assert.dom("[data-test-acl-link]").exists();
});
});

0 comments on commit 7a3caf4

Please sign in to comment.