Skip to content

Commit

Permalink
test: fix component test
Browse files Browse the repository at this point in the history
  • Loading branch information
fterra-encora committed Dec 8, 2023
1 parent a8ee97b commit cccf31a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 59 deletions.
6 changes: 4 additions & 2 deletions frontend/src/components/grouping/ContactGroupComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ const updateContactType = (value: CodeNameType | undefined) => {
<br /><br />

<p class="label-01">Full name</p>
<p class="body-compact-01">{{ selectedValue.firstName }} {{ selectedValue.lastName }}</p>
<p id="fullName_0" class="body-compact-01">
{{ selectedValue.firstName }} {{ selectedValue.lastName }}
</p>
</div>
<hr class="divider" />
<div>
<p class="label-01">Email address</p>
<p class="body-compact-01">{{ selectedValue.email }}</p>
<p id="email_0" class="body-compact-01">{{ selectedValue.email }}</p>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,65 +40,14 @@ describe("<ContactGroupComponent />", () => {
});

cy.get("@contactFixture").then((contact: Contact) => {
cy.get("#firstName_0")
.should("be.visible")
.and("have.value", contact.firstName);

cy.get("#lastName_0")
.should("be.visible")
.and("have.value", contact.lastName);
cy.contains("Full name").should("be.visible");
cy.get("#fullName_0")
.contains(`${contact.firstName} ${contact.lastName}`)
.should("be.visible");

cy.get("#email_0").should("be.visible").and("have.value", "");

cy.get("#phoneNumber_0").should("be.visible").and("have.value", "");
});
});

it("should render the component with validation", () => {
cy.get("@contactFixture").then((contact: Contact) => {
cy.get("@rolesFixture").then((roles) => {
cy.get("@addressesFixture").then((addresses) => {
cy.mount(ContactGroupComponent, {
props: {
id: 0,
modelValue: {
...contact,
firstName: contact.firstName + " fault",
},
enabled: true,
roleList: roles,
addressList: addresses,
validations: [dummyValidation()],
},
});
});
});
});

cy.get("@contactFixture").then((contact: Contact) => {
cy.get("#firstName_0")
.should("be.visible")
.and("have.value", contact.firstName + " fault");

cy.get("#firstName_0")
.shadow()
.find(".cds--form-requirement")
.should("be.visible")
.find("slot")
.and("include.text", "Error");

cy.get("#lastName_0")
.should("be.visible")
.and("have.value", contact.lastName);

cy.get("#lastName_0")
.shadow()
.find(".cds--form-requirement")
.should("be.visible")
.find("slot")
.and("include.text", "Error");

cy.get("#email_0").should("be.visible").and("have.value", "");
cy.contains("Email address").should("be.visible");
cy.get("#email_0").contains(contact.email).should("be.visible");

cy.get("#phoneNumber_0").should("be.visible").and("have.value", "");
});
Expand All @@ -125,6 +74,8 @@ describe("<ContactGroupComponent />", () => {
});
});

cy.focused().should('have.id', 'phoneNumber_0');

cy.get("#addressname_0").should("be.visible").and("have.value", "");

cy.get("#addressname_0")
Expand Down Expand Up @@ -160,6 +111,8 @@ describe("<ContactGroupComponent />", () => {
});
});

cy.focused().should('have.id', 'phoneNumber_0');

cy.get("#addressname_0").should("be.visible").and("have.value", "");

cy.get("#addressname_0")
Expand Down Expand Up @@ -202,6 +155,8 @@ describe("<ContactGroupComponent />", () => {
});
});

cy.focused().should('have.id', 'phoneNumber_0');

cy.get("#addressname_0").should("be.visible").and("have.value", "");

cy.get("#addressname_0")
Expand Down Expand Up @@ -263,6 +218,7 @@ describe("<ContactGroupComponent />", () => {
});
});

cy.focused().should('have.id', 'firstName_1');
cy.get(fieldSelector).shadow().find("input").clear(); // emits false
cy.get(fieldSelector).blur(); // (doesn't emit)
cy.get(fieldSelector).shadow().find("input").type(firstContent); // emits true before blurring
Expand Down

0 comments on commit cccf31a

Please sign in to comment.