Skip to content

Commit

Permalink
fix: occupancy issues (bloom-housing#4640)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyjablonski committed Feb 19, 2025
1 parent eb29113 commit ed91e75
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 19 deletions.
37 changes: 31 additions & 6 deletions shared-helpers/__tests__/occupancyFormatting.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from "react"
import { cleanup } from "@testing-library/react"
import { occupancyTable, getOccupancyDescription } from "../src/views/occupancyFormatting"
import {
occupancyTable,
getOccupancyDescription,
getOccupancy,
} from "../src/views/occupancyFormatting"
import { t } from "@bloom-housing/ui-components"
import { Listing, UnitType, UnitsSummarized } from "../src/types/backend-swagger"

Expand Down Expand Up @@ -85,7 +89,7 @@ const unitsSummarized = {
max: "20",
},
occupancyRange: {
min: 2,
min: 1,
max: 1,
},
rentAsPercentIncomeRange: {
Expand All @@ -109,7 +113,7 @@ testListing.unitsSummarized = unitsSummarized
afterEach(cleanup)

describe("occupancy formatting helper", () => {
it("properly creates occupany table", () => {
it("properly creates occupancy table", () => {
expect(occupancyTable(testListing)).toStrictEqual([
{
occupancy: { content: "2-6 people" },
Expand All @@ -125,10 +129,10 @@ describe("occupancy formatting helper", () => {
},
])
})
it("properly creates occupany description for some SRO", () => {
it("properly creates occupancy description for some SRO", () => {
expect(getOccupancyDescription(testListing)).toBe(t("listings.occupancyDescriptionSomeSro"))
})
it("properly creates occupany description for no SRO", () => {
it("properly creates occupancy description for no SRO", () => {
const testListing2 = testListing
testListing2.unitsSummarized = {
...unitsSummarized,
Expand All @@ -145,7 +149,7 @@ describe("occupancy formatting helper", () => {
}
expect(getOccupancyDescription(testListing2)).toBe(t("listings.occupancyDescriptionNoSro"))
})
it("properly creates occupany description for all SRO", () => {
it("properly creates occupancy description for all SRO", () => {
const testListing3 = testListing
testListing3.unitsSummarized = {
...unitsSummarized,
Expand All @@ -159,3 +163,24 @@ describe("occupancy formatting helper", () => {
expect(getOccupancyDescription(testListing3)).toBe(t("listings.occupancyDescriptionAllSro"))
})
})

describe("getOccupancy", () => {
it("returns correctly for no data", () => {
expect(getOccupancy(null, null)).toBe("n/a")
})
it("returns correctly for both min and max", () => {
expect(getOccupancy(1, 5)).toBe("1-5 people")
})
it("returns correctly for just min plural", () => {
expect(getOccupancy(2, null)).toBe("at least 2 people")
})
it("returns correctly for just min singular", () => {
expect(getOccupancy(1, null)).toBe("at least 1 person")
})
it("returns correctly for just max plural", () => {
expect(getOccupancy(null, 2)).toBe("no more than 2 people")
})
it("returns correctly for just max singular", () => {
expect(getOccupancy(null, 1)).toBe("no more than 1 person")
})
})
2 changes: 2 additions & 0 deletions shared-helpers/src/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@
"t.areYouSure": "هل أنت متأكد؟",
"t.area": "منطقة",
"t.at": "في",
"t.atLeast": "على الأقل %{amount}",
"t.automatic": "تلقائي",
"t.availability": "التوافر",
"t.back": "عودة",
Expand Down Expand Up @@ -1055,6 +1056,7 @@
"t.neighborhood": "حي",
"t.next": "التالي",
"t.no": "رقم",
"t.noMoreThan": "لا أكثر من %{amount}",
"t.none": "لا أحد",
"t.noneFound": "لا شيء وجد.",
"t.notes": "ملحوظات",
Expand Down
2 changes: 2 additions & 0 deletions shared-helpers/src/locales/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@
"t.areYouSure": "তুমি কি নিশ্চিত?",
"t.area": "এলাকা",
"t.at": "",
"t.atLeast": "অন্তত %{amount}",
"t.automatic": "স্বয়ংক্রিয়",
"t.availability": "প্রাপ্যতা",
"t.back": "পেছনে",
Expand Down Expand Up @@ -981,6 +982,7 @@
"t.neighborhood": "প্রতিবেশ",
"t.next": "পরবর্তী",
"t.no": "না",
"t.noMoreThan": "এর বেশি নয় %{amount}",
"t.none": "কোনটিই নয়",
"t.noneFound": "কোন পাওয়া যায়নি।",
"t.notes": "মন্তব্য",
Expand Down
2 changes: 2 additions & 0 deletions shared-helpers/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@
"t.area": "área",
"t.areYouStillWorking": "¿Sigue usted trabajando?",
"t.at": "en",
"t.atLeast": "al menos %{amount}",
"t.availability": "Disponibilidad",
"t.back": "Atrás",
"t.backToListing": "Volver al listado",
Expand Down Expand Up @@ -911,6 +912,7 @@
"t.neighborhood": "Comunidad",
"t.next": "Siguiente",
"t.no": "No",
"t.noMoreThan": "no más que %{amount}",
"t.none": "Ninguno",
"t.noneFound": "No se encontró ninguno.",
"t.occupancy": "Ocupación",
Expand Down
2 changes: 2 additions & 0 deletions shared-helpers/src/locales/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@
"t.area": "area",
"t.areYouStillWorking": "Are you still working?",
"t.at": "at",
"t.atLeast": "at least %{amount}",
"t.availability": "Availability",
"t.back": "Back",
"t.backToListing": "Back to listing",
Expand Down Expand Up @@ -902,6 +903,7 @@
"t.neighborhood": "Neighborhood",
"t.next": "Next",
"t.no": "No",
"t.noMoreThan": "no more than %{amount}",
"t.none": "None",
"t.noneFound": "None found.",
"t.occupancy": "Occupancy",
Expand Down
2 changes: 2 additions & 0 deletions shared-helpers/src/locales/tl.json
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@
"t.area": "lugar",
"t.areYouStillWorking": "Nagtatrabaho ka pa rin ba?",
"t.at": "sa",
"t.atLeast": "kahit man lang %{amount}",
"t.availability": "Availability",
"t.back": "Bumalik",
"t.backToListing": "Bumalik sa listahan",
Expand Down Expand Up @@ -905,6 +906,7 @@
"t.neighborhood": "Kapitbahayan",
"t.next": "Susunod",
"t.no": "Hindi",
"t.noMoreThan": "hindi hihigit sa %{amount}",
"t.none": "Wala",
"t.noneFound": "Walang nakita.",
"t.occupancy": "Paninirahan",
Expand Down
2 changes: 2 additions & 0 deletions shared-helpers/src/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@
"t.area": "diện tích",
"t.areYouStillWorking": "Quý vị có vẫn đang làm việc hay không?",
"t.at": "vào",
"t.atLeast": "ít nhất %{amount}",
"t.availability": "Tình trạng sẵn có",
"t.back": "Quay lại",
"t.backToListing": "Quay lại danh sách",
Expand Down Expand Up @@ -906,6 +907,7 @@
"t.neighborhood": "Khu phố",
"t.next": "Tiếp theo",
"t.no": "Không",
"t.noMoreThan": "không nhiều hơn %{amount}",
"t.none": "Không",
"t.noneFound": "Không tìm thấy.",
"t.occupancy": "Số người cư ngụ",
Expand Down
2 changes: 2 additions & 0 deletions shared-helpers/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@
"t.area": "地區",
"t.areYouStillWorking": "您是否仍在工作?",
"t.at": "",
"t.atLeast": "至少 %{amount}",
"t.availability": "供應情況",
"t.back": "返回",
"t.backToListing": "返回列表",
Expand Down Expand Up @@ -906,6 +907,7 @@
"t.neighborhood": "鄰里",
"t.next": "下一頁",
"t.no": "",
"t.noMoreThan": "不超過 %{amount}",
"t.none": "",
"t.noneFound": "找不到。",
"t.occupancy": "入住人數",
Expand Down
34 changes: 21 additions & 13 deletions shared-helpers/src/views/occupancyFormatting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@ import * as React from "react"
import { StandardTableData, t } from "@bloom-housing/ui-components"
import { Listing, UnitTypeEnum } from "../types/backend-swagger"

export const getOccupancy = (minOcc?: number | null, maxOcc?: number | null) => {
if (minOcc && maxOcc && minOcc < maxOcc) {
return `${minOcc}-${maxOcc} ${t("t.people")}`
}
if (minOcc && maxOcc && minOcc === maxOcc) {
return `${minOcc} ${minOcc === 1 ? t("t.person") : t("t.people")}`
}
if (!minOcc && maxOcc) {
return t("t.noMoreThan", {
amount: `${maxOcc} ${maxOcc === 1 ? t("t.person") : t("t.people")}`,
})
}
if (minOcc && !maxOcc) {
return t("t.atLeast", {
amount: `${minOcc} ${minOcc === 1 ? t("t.person") : t("t.people")}`,
})
}
return t("t.n/a")
}

export const occupancyTable = (listing: Listing): StandardTableData => {
let occupancyData: StandardTableData = []
if (listing.unitsSummarized && listing.unitsSummarized.byUnitType) {
occupancyData = listing.unitsSummarized.byUnitType.map((unitSummary) => {
let occupancy = ""

if (unitSummary.occupancyRange.max == null) {
occupancy = `at least ${unitSummary.occupancyRange.min} ${
unitSummary.occupancyRange.min == 1 ? t("t.person") : t("t.people")
}`
} else if (unitSummary.occupancyRange.max > 1) {
occupancy = `${unitSummary.occupancyRange.min}-${unitSummary.occupancyRange.max} ${
unitSummary.occupancyRange.max == 1 ? t("t.person") : t("t.people")
}`
} else {
occupancy = `1 ${t("t.person")}`
}
const occupancy = getOccupancy(unitSummary.occupancyRange.min, unitSummary.occupancyRange.max)

return {
unitType: {
Expand Down

0 comments on commit ed91e75

Please sign in to comment.