The provided json wasn't displayed properly.
Change-Id: I6b09218b38d88394b96bb27f721e92ab40aaec49
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Issue-ID: NONRTRIC-463
expect(await formatButton.isDisabled()).toBeTruthy();
});
expect(await formatButton.isDisabled()).toBeTruthy();
});
- it("should format unformatted json", async () => {
- const textArea = component.noTypePolicyEditorComponent.instanceForm.get(
- "policyJsonTextArea"
+ it("should send valid json", async () => {
+ const textAreaHarness: MatInputHarness = await loader.getHarness(
+ MatInputHarness.with({ selector: "#policyJsonTextArea" })
- expect(textArea.value).toEqual('{"A":"A"}');
+ expect(await textAreaHarness.getValue()).toEqual('{"A":"A"}');
- component.noTypePolicyEditorComponent.formatJsonInput();
- expect(textArea.value).toEqual('{\n "A": "A"\n}');
- });
+ let validJson: string;
+ component.noTypePolicyEditorComponent.validJson.subscribe(
+ (json: string) => {
+ validJson = json;
+ }
+ );
- it("should send valid json", async () => {
const textArea = component.noTypePolicyEditorComponent.instanceForm.get(
"policyJsonTextArea"
);
const textArea = component.noTypePolicyEditorComponent.instanceForm.get(
"policyJsonTextArea"
);
- expect(textArea.value).toEqual('{"A":"A"}');
-
- let validJson: string;
- component.noTypePolicyEditorComponent.validJson.subscribe((json: string) => {
- validJson = json;
- });
-
textArea.setValue('{"B":"B"}');
expect(validJson).toEqual('{"B":"B"}');
});
it("should send null when invalid json", async () => {
textArea.setValue('{"B":"B"}');
expect(validJson).toEqual('{"B":"B"}');
});
it("should send null when invalid json", async () => {
- const textArea = component.noTypePolicyEditorComponent.instanceForm.get(
- "policyJsonTextArea"
+ const textArea: MatInputHarness = await loader.getHarness(
+ MatInputHarness.with({ selector: "#policyJsonTextArea" })
- expect(textArea.value).toEqual('{"A":"A"}');
+ expect(await textArea.getValue()).toEqual('{"A":"A"}');
- component.noTypePolicyEditorComponent.validJson.subscribe((json: string) => {
- invalidJson = json;
- });
+ component.noTypePolicyEditorComponent.validJson.subscribe(
+ (json: string) => {
+ invalidJson = json;
+ }
+ );
- textArea.setValue('{');
+ textArea.setValue("{");
expect(invalidJson).toBeFalsy();
});
expect(invalidJson).toBeFalsy();
});
constructor() {}
ngOnInit(): void {
constructor() {}
ngOnInit(): void {
+ let initialJson: string;
+ if (this.policyJson) {
+ initialJson = formatJsonString(this.policyJson);
+ } else {
+ initialJson = "{}";
+ }
this.instanceForm.addControl(
"policyJsonTextArea",
this.instanceForm.addControl(
"policyJsonTextArea",
- new FormControl(this.policyJson, [
+ new FormControl(initialJson, [
Validators.required,
this.jsonValidator(),
])
);
Validators.required,
this.jsonValidator(),
])
);
- if (!this.policyJson) this.policyJson = "{}";
}
get policyJsonTextArea(): AbstractControl {
}
get policyJsonTextArea(): AbstractControl {