Skip to content

Commit 44789ea

Browse files
kcinay055679njaeggi
authored andcommitted
write tests
1 parent 4ad7cb9 commit 44789ea

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

Diff for: frontend/app/components/encryptable/form.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class Form extends BaseFormComponent {
4949
if (!this.record.isFullyLoaded)
5050
this.store.findRecord("encryptable-credential", this.record.id);
5151

52-
this.setRandomPassword(this.withSymbols, this.passwordLength);
52+
this.setRandomPassword();
5353
}
5454

5555
presetTeamAndFolder() {
@@ -80,7 +80,11 @@ export default class Form extends BaseFormComponent {
8080
}
8181

8282
@action
83-
setRandomPassword(withSymbols, passwordLength) {
83+
setRandomPassword(
84+
withSymbols = this.withSymbols,
85+
passwordLength = this.passwordLength
86+
) {
87+
console.log("tes");
8488
let pass = "";
8589
const array = new Uint32Array(1);
8690
const PASSWORD_CHARS =

Diff for: frontend/app/templates/components/encryptable/form.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<label>
7676
Symbols
7777
<Input
78+
id="withSymbols"
7879
@type="checkbox"
7980
@checked={{this.withSymbols}} {{on "change" (fn this.setRandomPassword invertedWithSymbols passwordLength)}}></Input>
8081
</label>

Diff for: frontend/tests/integration/components/encryptable/form-test.js

+63-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { module, test } from "qunit";
22
import { setupRenderingTest } from "ember-qunit";
3-
import { render } from "@ember/test-helpers";
3+
import {
4+
click,
5+
render,
6+
triggerKeyEvent,
7+
pauseTest,
8+
triggerEvent,
9+
find
10+
} from "@ember/test-helpers";
411
import { hbs } from "ember-cli-htmlbars";
512
import Service from "@ember/service";
613
import { clickTrigger } from "ember-power-select/test-support/helpers";
714
import { selectChoose } from "ember-power-select/test-support";
815
import { setLocale } from "ember-intl/test-support";
16+
import { scrollTo } from "@ember/test-helpers";
917

1018
const navServiceStub = Service.extend({
1119
/* eslint-disable ember/avoid-leaking-state-in-ember-objects */
@@ -295,4 +303,58 @@ module("Integration | Component | encryptable/form", function (hooks) {
295303
assert.ok(this.element.textContent.trim().includes("supporting"));
296304
assert.ok(this.element.textContent.trim().includes("bbt"));
297305
});
306+
307+
test("generates a 14 digit password per default", async function (assert) {
308+
await render(hbs`<Encryptable::Form />`);
309+
310+
assert.equal(
311+
this.element.querySelector("input[name='cleartextPassword']").value
312+
.length,
313+
14
314+
);
315+
});
316+
317+
test("Symbols are enabled per default", async function (assert) {
318+
await render(hbs`<Encryptable::Form />`);
319+
assert.equal(this.element.querySelector("input#withSymbols").checked, true);
320+
});
321+
322+
test("Password does not contain symbols after unchecking checkbox", async function (assert) {
323+
await render(hbs`<Encryptable::Form />`);
324+
await click("input#withSymbols");
325+
assert.equal(
326+
this.element.querySelector("input[name='cleartextPassword']").value
327+
.length,
328+
14
329+
);
330+
331+
assert.equal(
332+
this.element.querySelector("input#withSymbols").checked,
333+
false
334+
);
335+
assert.notOk(
336+
this.element.querySelector("input#withSymbols").value.match(/[^\w\s]/)
337+
);
338+
});
339+
340+
//Last test to fix
341+
//The function in called correctly but the value passwordLength isnt updated
342+
test("Password with the right length should be generated", async function (assert) {
343+
await render(hbs`<Encryptable::Form />`);
344+
const slider = this.element.querySelector("input#formControlRange");
345+
slider.value = 17;
346+
await triggerEvent(slider, "change");
347+
await triggerEvent(slider, "input");
348+
await pauseTest();
349+
console.log(slider.value);
350+
assert.equal(
351+
this.element.querySelector("input[name='cleartextPassword']").value
352+
.length,
353+
17
354+
);
355+
await click("input#withSymbols");
356+
assert.notOk(
357+
this.element.querySelector("input#withSymbols").value.match(/[^\w\s]/)
358+
);
359+
});
298360
});

0 commit comments

Comments
 (0)