- it('should format unformatted json', async () => {
- const textArea = formGroup.get('policyJsonTextArea');
- textArea.setValue('{"A":"A"}');
- component.noTypePolicyEditorComponent.formatJsonInput();
- expect(component.noTypePolicyEditorComponent.policyJson).toEqual('{\n "A": "A"\n}');
+ it("should send valid json", async () => {
+ const textAreaHarness: MatInputHarness = await loader.getHarness(
+ MatInputHarness.with({ selector: "#policyJsonTextArea" })
+ );
+ expect(await textAreaHarness.getValue()).toEqual('{"A":"A"}');
+
+ let validJson: string;
+ component.noTypePolicyEditorComponent.validJson.subscribe(
+ (json: string) => {
+ validJson = json;
+ }
+ );
+
+ const textArea = component.noTypePolicyEditorComponent.instanceForm.get(
+ "policyJsonTextArea"
+ );
+ textArea.setValue('{"B":"B"}');
+ expect(validJson).toEqual('{"B":"B"}');
+ });
+
+ it("should send null when invalid json", async () => {
+ const textArea: MatInputHarness = await loader.getHarness(
+ MatInputHarness.with({ selector: "#policyJsonTextArea" })
+ );
+ expect(await textArea.getValue()).toEqual('{"A":"A"}');
+
+ let invalidJson: string;
+ component.noTypePolicyEditorComponent.validJson.subscribe(
+ (json: string) => {
+ invalidJson = json;
+ }
+ );
+
+ textArea.setValue("{");
+ expect(invalidJson).toBeFalsy();