Skip to content

Commit

Permalink
test: add component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fterra-encora committed Jan 11, 2024
1 parent 564bbf6 commit 1fcd9a4
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 1 deletion.
12 changes: 12 additions & 0 deletions frontend/cypress/fixtures/business.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,17 @@
"name": "Totally Shady Company",
"status": "ACTIVE",
"legalType": "SP"
},
{
"code":"BC1234567",
"name":"Unsupported Client Type Inc.",
"status":"ACTIVE",
"legalType": "BC"
},
{
"code":"SP1234567",
"name":"Unknown Sole Proprietor Ltd.",
"status":"ACTIVE",
"legalType": "SP"
}
]
119 changes: 118 additions & 1 deletion frontend/tests/pages/bceid/BusinessInformationWizardStep.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,31 @@ import BusinessInformationWizardStep from "@/pages/bceidform/BusinessInformation
import type { FormDataDto } from "@/dto/ApplyClientNumberDto";

describe('<BusinessInformationWizardStep />', () => {


beforeEach(() => {
cy.intercept("/api/clients/name/*", {
fixture: "business.json",
}).as("searchCompany");

cy.intercept("GET", "/api/clients/BC1234567", {
statusCode: 406,
body: "Client type BC is not supported at the moment",
});

cy.intercept("GET", "/api/clients/SP1234567", {
statusCode: 422,
body: "Unable to process request. This sole proprietor is not owner by a person",
});

cy.intercept("GET", "/api/clients/getClientTypeByCode/C", {
statusCode: 200,
body: {
code: "C",
name: "Corporation",
},
}).as("getClientType");
});

it('renders the BusinessInformationWizardStep component and interacts with elements', () => {
cy.mount(BusinessInformationWizardStep, {
props: {
Expand All @@ -28,4 +52,97 @@ describe('<BusinessInformationWizardStep />', () => {
cy.get('.link-button:visible span').should('exist');
cy.get('.link-button:visible span').invoke('text').should('not.be.empty');
});

it('shows "Client type not supported"', () => {
cy.mount(BusinessInformationWizardStep, {
props: {
data: {
businessInformation: {
businessType: "",
legalType: "",
clientType: "",
incorporationNumber: "",
businessName: "",
goodStandingInd: "",
birthdate: "",
address: ""
},
location: {
contacts: [
{
email: "[email protected]",
firstName: "John",
},
],
},
} as unknown as FormDataDto,
active: false,
},
});

cy.get("#businessTyperbR").click();

cy.get("#business")
.should("be.visible")
.shadow()
.find("input")
.should("have.value", "")
.type("Unsupported");
cy.wait("@searchCompany");

cy.get('cds-combo-box-item[data-id="BC1234567"]').click();

cy.get("cds-inline-notification")
.shadow()
.contains("Client type not supported")
.should("be.visible");

// The name of the client type
cy.contains("cds-inline-notification", "Corporation").should("be.visible");
});

it('shows "Unknown sole proprietor"', () => {
cy.mount(BusinessInformationWizardStep, {
props: {
data: {
businessInformation: {
businessType: "",
legalType: "",
clientType: "",
incorporationNumber: "",
businessName: "",
goodStandingInd: "",
birthdate: "",
address: ""
},
location: {
contacts: [
{
email: "[email protected]",
firstName: "John",
},
],
},
} as unknown as FormDataDto,
active: false,
},
});

cy.get("#businessTyperbR").click();

cy.get("#business")
.should("be.visible")
.shadow()
.find("input")
.should("have.value", "")
.type("Unknown");
cy.wait("@searchCompany");

cy.get('cds-combo-box-item[data-id="SP1234567"]').click();

cy.get("cds-inline-notification")
.shadow()
.contains("Unknown sole proprietor")
.should("be.visible");
});
});

0 comments on commit 1fcd9a4

Please sign in to comment.