From 72508796fadafaefef9436cbd0d5e99699f1e4a4 Mon Sep 17 00:00:00 2001 From: Michael Winberry Date: Fri, 3 Sep 2021 12:36:33 -0600 Subject: [PATCH] Update missionappdns fields to only be required if one or more fields is filled out. --- src/components/MissionAppDns.vue | 27 ++++++++++++++------- tests/unit/components/MissionAppDns.spec.js | 16 ++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/components/MissionAppDns.vue b/src/components/MissionAppDns.vue index b1affd4..ca9ed99 100644 --- a/src/components/MissionAppDns.vue +++ b/src/components/MissionAppDns.vue @@ -7,29 +7,26 @@ class="mb-8" label="Dns Credential Name" v-model="dns.credentialName" - hint="* Required" + :hint="hint" persistent-hint - required - :rules="[inputRules.required]" + :required="isRequired" /> @@ -48,6 +45,18 @@ export default { inputRules, environments: ["IL2", "IL4", "IL5"], }), + computed: { + isRequired() { + return ( + this.dns.credentialName || + this.dns.appHostname || + this.dns.targetEnvironment + ); + }, + hint() { + return this.isRequired ? "* Required" : ""; + }, + }, watch: { dns() { this.$emit("input", this.dns); diff --git a/tests/unit/components/MissionAppDns.spec.js b/tests/unit/components/MissionAppDns.spec.js index bdf3000..8bbca70 100644 --- a/tests/unit/components/MissionAppDns.spec.js +++ b/tests/unit/components/MissionAppDns.spec.js @@ -42,4 +42,20 @@ describe("Mission App Dns Form Section", () => { wrapper.vm.environments[0] ); }); + + describe("Required behavior | all or none", () => { + it("sets required to true if any of the fields are defined", () => { + inputs.at(0).setValue("dns-credentials"); + expect(wrapper.vm.isRequired).toBeTruthy(); + }); + + it("sets the hint to required if any of the fields are defined", () => { + inputs.at(0).setValue("dns-credentials"); + expect(wrapper.vm.hint).toBe("* Required"); + }); + + it("Does not return a hint if none of the fields are defined", () => { + expect(wrapper.vm.hint).toBe(""); + }); + }); }); -- GitLab