Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
refs #117
  • Loading branch information
franthormel committed Jun 18, 2024
1 parent aa75d38 commit 8b43683
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
1 change: 0 additions & 1 deletion components/_app/listing/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function availableDateText(
}).format(availableDate);
}

// TODO: Unit test
export function depositText(deposit?: number): string {
if (deposit === undefined || deposit <= 0) {
return "None";
Expand Down
39 changes: 25 additions & 14 deletions cypress/component/_app/listing/ListingMainInfo.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import ListingMainInfo from "@/components/_app/listing/main-info";

// TODO: Add deposit

describe('Listing Main Info', () => {
describe("display correct UI when", () => {
afterEach(() => {
Expand All @@ -13,10 +11,18 @@ describe('Listing Main Info', () => {
.should('be.visible')
.and('exist')
.and('have.text', 'Date Available')
cy.get('[data-cy="listing-main-info-address-space"]')
.should('not.be.visible')
.and('exist')
cy.get('[data-cy="listing-main-info-col-label-deposit"]')
.should('be.visible')
.and('exist')
.and('have.text', 'Deposit')
})

it("Multiple beds, multiple baths, null available date, null zipcode", () => {
it("Multiple beds, multiple baths, null available date, null zipcode, negative deposit", () => {
cy.mount(<ListingMainInfo price={9900}
deposit={-12}
beds={3}
baths={2}
area={55}
Expand Down Expand Up @@ -53,20 +59,22 @@ describe('Listing Main Info', () => {
.should('be.visible')
.and('exist')
.and('have.text', 'Available Now')
cy.get('[data-cy="listing-main-info-col-value-deposit"]')
.should('be.visible')
.and('exist')
.and('have.text', 'None')
cy.get('[data-cy="listing-main-info-address-line"]')
.should('be.visible')
.and('exist')
.and('have.text', '8508 Vandervort Crest Apt. 828,')
cy.get('[data-cy="listing-main-info-address-space"]')
.should('not.be.visible')
.and('exist')
cy.get('[data-cy="listing-main-info-address-city-state-zip"]')
.should('be.visible')
.and('exist')
.and('contain.text', 'East Wallace, Louisiana')
});
it("Single bed, single bath, future available date, with zipcode", () => {
it("Single bed, single bath, future available date, with zipcode, zero deposit", () => {
cy.mount(<ListingMainInfo price={12540}
deposit={0}
beds={1}
baths={1}
area={25}
Expand Down Expand Up @@ -103,20 +111,22 @@ describe('Listing Main Info', () => {
.should('be.visible')
.and('exist')
.and('have.text', 'June 20, 2035')
cy.get('[data-cy="listing-main-info-col-value-deposit"]')
.should('be.visible')
.and('exist')
.and('have.text', 'None')
cy.get('[data-cy="listing-main-info-address-line"]')
.should('be.visible')
.and('exist')
.and('have.text', '84162 S Front Street Apt. 807,')
cy.get('[data-cy="listing-main-info-address-space"]')
.should('not.be.visible')
.and('exist')
cy.get('[data-cy="listing-main-info-address-city-state-zip"]')
.should('be.visible')
.and('exist')
.and('contain.text', 'Prosaccoborough, Hawaii 88950')
});
it("Multiple beds, single bath, before available date, with zipcode", () => {
it("Multiple beds, single bath, before available date, with zipcode, with deposit", () => {
cy.mount(<ListingMainInfo price={9562}
deposit={1236}
beds={2}
baths={1}
area={32}
Expand Down Expand Up @@ -153,13 +163,14 @@ describe('Listing Main Info', () => {
.should('be.visible')
.and('exist')
.and('have.text', 'Available Now')
cy.get('[data-cy="listing-main-info-col-value-deposit"]')
.should('be.visible')
.and('exist')
.and('have.text', '₱1,236')
cy.get('[data-cy="listing-main-info-address-line"]')
.should('be.visible')
.and('exist')
.and('have.text', '26846 Hartmann Trace Apt. 561,')
cy.get('[data-cy="listing-main-info-address-space"]')
.should('not.be.visible')
.and('exist')
cy.get('[data-cy="listing-main-info-address-city-state-zip"]')
.should('be.visible')
.and('exist')
Expand Down
31 changes: 30 additions & 1 deletion tests/app/listing-main-info.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { availableDateText } from "../../components/_app/listing/function";
import {
availableDateText,
depositText,
} from "../../components/_app/listing/function";

describe("listing page main info", () => {
test.each([
Expand All @@ -25,4 +28,30 @@ describe("listing page main info", () => {
expect(actual).toBe(output);
}
);

test.each([
{
deposit: -92232,
output: "None",
},
{
deposit: -0.001,
output: "None",
},
{
deposit: 0,
output: "None",
},
{
deposit: 998,
output: "₱998",
},
{
deposit: 76231,
output: "₱76,231",
},
])("deposit text = $deposit", ({ deposit, output }) => {
const actual = depositText(deposit);
expect(actual).toBe(output);
});
});

0 comments on commit 8b43683

Please sign in to comment.