2020-05-14 22:04:08 +08:00
|
|
|
import I18n from "I18n";
|
2018-10-15 13:03:53 +08:00
|
|
|
import componentTest from "helpers/component-test";
|
|
|
|
moduleForComponent("secret-value-list", { integration: true });
|
|
|
|
|
|
|
|
componentTest("adding a value", {
|
|
|
|
template: "{{secret-value-list values=values}}",
|
|
|
|
|
|
|
|
async test(assert) {
|
|
|
|
this.set("values", "firstKey|FirstValue\nsecondKey|secondValue");
|
|
|
|
|
|
|
|
await fillIn(".new-value-input.key", "thirdKey");
|
|
|
|
await click(".add-value-btn");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".values .value").length === 2,
|
|
|
|
"it doesn't add the value to the list if secret is missing"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(".new-value-input.key", "");
|
|
|
|
await fillIn(".new-value-input.secret", "thirdValue");
|
|
|
|
await click(".add-value-btn");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".values .value").length === 2,
|
|
|
|
"it doesn't add the value to the list if key is missing"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(".new-value-input.key", "thirdKey");
|
|
|
|
await fillIn(".new-value-input.secret", "thirdValue");
|
|
|
|
await click(".add-value-btn");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".values .value").length === 3,
|
|
|
|
"it adds the value to the list of values"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.values,
|
2018-10-15 13:03:53 +08:00
|
|
|
"firstKey|FirstValue\nsecondKey|secondValue\nthirdKey|thirdValue",
|
|
|
|
"it adds the value to the list of values"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-05 04:18:58 +08:00
|
|
|
componentTest("adding an invalid value", {
|
|
|
|
template: "{{secret-value-list values=values}}",
|
|
|
|
|
|
|
|
async test(assert) {
|
|
|
|
await fillIn(".new-value-input.key", "someString");
|
|
|
|
await fillIn(".new-value-input.secret", "keyWithAPipe|Hidden");
|
|
|
|
await click(".add-value-btn");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".values .value").length === 0,
|
|
|
|
"it doesn't add the value to the list of values"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.values,
|
2018-11-05 04:18:58 +08:00
|
|
|
undefined,
|
|
|
|
"it doesn't add the value to the list of values"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".validation-error")
|
|
|
|
.html()
|
|
|
|
.indexOf(I18n.t("admin.site_settings.secret_list.invalid_input")) > -1,
|
|
|
|
"it shows validation error"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-15 13:03:53 +08:00
|
|
|
componentTest("removing a value", {
|
|
|
|
template: "{{secret-value-list values=values}}",
|
|
|
|
|
|
|
|
async test(assert) {
|
|
|
|
this.set("values", "firstKey|FirstValue\nsecondKey|secondValue");
|
|
|
|
|
|
|
|
await click(".values .value[data-index='0'] .remove-value-btn");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".values .value").length === 1,
|
|
|
|
"it removes the value from the list of values"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.values,
|
2018-10-15 13:03:53 +08:00
|
|
|
"secondKey|secondValue",
|
|
|
|
"it removes the expected value"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|