2017-10-19 20:34:56 -04:00
|
|
|
import { componentTest } from "wizard/test/helpers/component-test";
|
2016-09-13 15:14:17 -04:00
|
|
|
moduleForComponent("invite-list", { integration: true });
|
|
|
|
|
2017-10-19 20:34:56 -04:00
|
|
|
componentTest("can add users", {
|
2016-09-13 15:14:17 -04:00
|
|
|
template: `{{invite-list field=field}}`,
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2016-09-13 15:14:17 -04:00
|
|
|
this.set("field", {});
|
|
|
|
},
|
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
async test(assert) {
|
2016-09-13 15:14:17 -04:00
|
|
|
assert.ok(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".users-list .invite-list-user").length === 0,
|
2016-09-13 15:14:17 -04:00
|
|
|
"no users at first"
|
|
|
|
);
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".new-user .invalid").length === 0, "not invalid at first");
|
2016-09-13 15:14:17 -04:00
|
|
|
|
|
|
|
const firstVal = JSON.parse(this.get("field.value"));
|
|
|
|
assert.equal(firstVal.length, 0, "empty JSON at first");
|
|
|
|
|
2016-09-20 12:28:22 -04:00
|
|
|
assert.ok(
|
|
|
|
this.get("field.warning"),
|
|
|
|
"it has a warning since no users were added"
|
|
|
|
);
|
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
await click(".add-user");
|
|
|
|
assert.ok(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".users-list .invite-list-user").length === 0,
|
2018-07-29 16:51:32 -04:00
|
|
|
"doesn't add a blank user"
|
|
|
|
);
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".new-user .invalid").length === 1);
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
await fillIn(".invite-email", "eviltrout@example.com");
|
|
|
|
await click(".add-user");
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
assert.ok(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".users-list .invite-list-user").length === 1,
|
2018-07-29 16:51:32 -04:00
|
|
|
"adds the user"
|
|
|
|
);
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".new-user .invalid").length === 0);
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
const val = JSON.parse(this.get("field.value"));
|
|
|
|
assert.equal(val.length, 1);
|
|
|
|
assert.equal(
|
|
|
|
val[0].email,
|
|
|
|
"eviltrout@example.com",
|
|
|
|
"adds the email to the JSON"
|
|
|
|
);
|
|
|
|
assert.ok(val[0].role.length, "adds the role to the JSON");
|
|
|
|
assert.ok(!this.get("field.warning"), "no warning once the user is added");
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
await fillIn(".invite-email", "eviltrout@example.com");
|
|
|
|
await click(".add-user");
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
assert.ok(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".users-list .invite-list-user").length === 1,
|
2018-07-29 16:51:32 -04:00
|
|
|
"can't add the same user twice"
|
|
|
|
);
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".new-user .invalid").length === 1);
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
await fillIn(".invite-email", "not-an-email");
|
|
|
|
await click(".add-user");
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
assert.ok(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".users-list .invite-list-user").length === 1,
|
2018-07-29 16:51:32 -04:00
|
|
|
"won't add an invalid email"
|
|
|
|
);
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".new-user .invalid").length === 1);
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
await click(".invite-list .invite-list-user:eq(0) .remove-user");
|
|
|
|
assert.ok(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".users-list .invite-list-user").length === 0,
|
2018-07-29 16:51:32 -04:00
|
|
|
"removed the user"
|
|
|
|
);
|
2016-09-13 15:14:17 -04:00
|
|
|
},
|
|
|
|
});
|