From ede1e456e31287da69de33c53aa27fef8392b164 Mon Sep 17 00:00:00 2001 From: Emily Jablonski Date: Tue, 11 Feb 2025 14:42:48 -0700 Subject: [PATCH 1/3] fix: occupancy issues --- .../__tests__/occupancyFormatting.test.tsx | 37 ++++++++++-- shared-helpers/src/locales/ar.json | 2 + shared-helpers/src/locales/bn.json | 2 + shared-helpers/src/locales/es.json | 2 + shared-helpers/src/locales/general.json | 2 + shared-helpers/src/locales/tl.json | 2 + shared-helpers/src/locales/vi.json | 2 + shared-helpers/src/locales/zh.json | 2 + .../src/views/occupancyFormatting.tsx | 34 ++++++----- shared-helpers/src/views/summaryTables.tsx | 57 +++++++++++-------- 10 files changed, 98 insertions(+), 44 deletions(-) diff --git a/shared-helpers/__tests__/occupancyFormatting.test.tsx b/shared-helpers/__tests__/occupancyFormatting.test.tsx index bd52453c99..dc98e16fcd 100644 --- a/shared-helpers/__tests__/occupancyFormatting.test.tsx +++ b/shared-helpers/__tests__/occupancyFormatting.test.tsx @@ -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" @@ -85,7 +89,7 @@ const unitsSummarized = { max: "20", }, occupancyRange: { - min: 2, + min: 1, max: 1, }, rentAsPercentIncomeRange: { @@ -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" }, @@ -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, @@ -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, @@ -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") + }) +}) diff --git a/shared-helpers/src/locales/ar.json b/shared-helpers/src/locales/ar.json index 827c56b2aa..0184b63256 100644 --- a/shared-helpers/src/locales/ar.json +++ b/shared-helpers/src/locales/ar.json @@ -998,6 +998,7 @@ "t.areYouSure": "هل أنت متأكد؟", "t.area": "منطقة", "t.at": "في", + "t.atLeast": "على الأقل %{amount}", "t.automatic": "تلقائي", "t.availability": "التوافر", "t.back": "عودة", @@ -1055,6 +1056,7 @@ "t.neighborhood": "حي", "t.next": "التالي", "t.no": "رقم", + "t.noMoreThan": "لا أكثر من %{amount}", "t.none": "لا أحد", "t.noneFound": "لا شيء وجد.", "t.notes": "ملحوظات", diff --git a/shared-helpers/src/locales/bn.json b/shared-helpers/src/locales/bn.json index 342abbf526..e6fbb2f503 100644 --- a/shared-helpers/src/locales/bn.json +++ b/shared-helpers/src/locales/bn.json @@ -924,6 +924,7 @@ "t.areYouSure": "তুমি কি নিশ্চিত?", "t.area": "এলাকা", "t.at": "এ", + "t.atLeast": "অন্তত %{amount}", "t.automatic": "স্বয়ংক্রিয়", "t.availability": "প্রাপ্যতা", "t.back": "পেছনে", @@ -981,6 +982,7 @@ "t.neighborhood": "প্রতিবেশ", "t.next": "পরবর্তী", "t.no": "না", + "t.noMoreThan": "এর বেশি নয় %{amount}", "t.none": "কোনটিই নয়", "t.noneFound": "কোন পাওয়া যায়নি।", "t.notes": "মন্তব্য", diff --git a/shared-helpers/src/locales/es.json b/shared-helpers/src/locales/es.json index d71236187c..dfb5bfa717 100644 --- a/shared-helpers/src/locales/es.json +++ b/shared-helpers/src/locales/es.json @@ -864,6 +864,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", @@ -912,6 +913,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", diff --git a/shared-helpers/src/locales/general.json b/shared-helpers/src/locales/general.json index 51d377c46d..f8f71cfbd5 100644 --- a/shared-helpers/src/locales/general.json +++ b/shared-helpers/src/locales/general.json @@ -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", @@ -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", diff --git a/shared-helpers/src/locales/tl.json b/shared-helpers/src/locales/tl.json index 4934354b4f..a687073c95 100644 --- a/shared-helpers/src/locales/tl.json +++ b/shared-helpers/src/locales/tl.json @@ -859,6 +859,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", @@ -907,6 +908,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", diff --git a/shared-helpers/src/locales/vi.json b/shared-helpers/src/locales/vi.json index 6e67c1c037..f145ec695a 100644 --- a/shared-helpers/src/locales/vi.json +++ b/shared-helpers/src/locales/vi.json @@ -859,6 +859,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", @@ -907,6 +908,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ụ", diff --git a/shared-helpers/src/locales/zh.json b/shared-helpers/src/locales/zh.json index b49101b5a8..549ed1f46b 100644 --- a/shared-helpers/src/locales/zh.json +++ b/shared-helpers/src/locales/zh.json @@ -859,6 +859,7 @@ "t.area": "地區", "t.areYouStillWorking": "您是否仍在工作?", "t.at": "於", + "t.atLeast": "至少 %{amount}", "t.availability": "供應情況", "t.back": "返回", "t.backToListing": "返回列表", @@ -907,6 +908,7 @@ "t.neighborhood": "鄰里", "t.next": "下一頁", "t.no": "否", + "t.noMoreThan": "不超過 %{amount}", "t.none": "無", "t.noneFound": "找不到。", "t.occupancy": "入住人數", diff --git a/shared-helpers/src/views/occupancyFormatting.tsx b/shared-helpers/src/views/occupancyFormatting.tsx index 1c8efd0b0c..f64c06b07e 100644 --- a/shared-helpers/src/views/occupancyFormatting.tsx +++ b/shared-helpers/src/views/occupancyFormatting.tsx @@ -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 && 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: { diff --git a/shared-helpers/src/views/summaryTables.tsx b/shared-helpers/src/views/summaryTables.tsx index 4f24352444..c0a1487f2c 100644 --- a/shared-helpers/src/views/summaryTables.tsx +++ b/shared-helpers/src/views/summaryTables.tsx @@ -159,32 +159,39 @@ export const UnitTables = (props: UnitTablesProps) => { ) const unitsFormatted = [] as StandardTableData let floorSection: React.ReactNode - units.forEach((unit: Unit) => { - unitsFormatted.push({ - number: { content: unit.number }, - sqFeet: { - content: ( - <> - {unit.sqFeet ? ( - <> - {parseInt(unit.sqFeet)} {t("t.sqFeet")} - - ) : ( - <> - )} - - ), - }, - numBathrooms: { - content: ( - - {unit.numBathrooms === 0 ? t("listings.unit.sharedBathroom") : unit.numBathrooms} - - ), - }, - floor: { content: {unit.floor} }, + units + .sort((unitA, unitB) => (unitA.numBathrooms || 0) - (unitB.numBathrooms || 0)) + .sort((unitA, unitB) => parseInt(unitA.sqFeet || "0") - parseInt(unitB.sqFeet || "0")) + .sort((unitA, unitB) => (unitA.floor || 0) - (unitB.floor || 0)) + .sort((unitA, unitB) => (unitA.number || "").localeCompare(unitB.number || "")) + .forEach((unit: Unit) => { + unitsFormatted.push({ + number: { content: unit.number }, + sqFeet: { + content: ( + <> + {unit.sqFeet ? ( + <> + {parseInt(unit.sqFeet)} {t("t.sqFeet")} + + ) : ( + <> + )} + + ), + }, + numBathrooms: { + content: ( + + {unit.numBathrooms === 0 + ? t("listings.unit.sharedBathroom") + : unit.numBathrooms} + + ), + }, + floor: { content: {unit.floor} }, + }) }) - }) let areaRangeSection: React.ReactNode if (unitSummary.areaRange?.min || unitSummary.areaRange?.max) { From edd96ed23a41cdf072d25c87edd0a88a659f42e8 Mon Sep 17 00:00:00 2001 From: Emily Jablonski Date: Tue, 11 Feb 2025 14:53:01 -0700 Subject: [PATCH 2/3] fix: revert --- shared-helpers/src/views/summaryTables.tsx | 57 ++++++++++------------ 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/shared-helpers/src/views/summaryTables.tsx b/shared-helpers/src/views/summaryTables.tsx index c0a1487f2c..4f24352444 100644 --- a/shared-helpers/src/views/summaryTables.tsx +++ b/shared-helpers/src/views/summaryTables.tsx @@ -159,39 +159,32 @@ export const UnitTables = (props: UnitTablesProps) => { ) const unitsFormatted = [] as StandardTableData let floorSection: React.ReactNode - units - .sort((unitA, unitB) => (unitA.numBathrooms || 0) - (unitB.numBathrooms || 0)) - .sort((unitA, unitB) => parseInt(unitA.sqFeet || "0") - parseInt(unitB.sqFeet || "0")) - .sort((unitA, unitB) => (unitA.floor || 0) - (unitB.floor || 0)) - .sort((unitA, unitB) => (unitA.number || "").localeCompare(unitB.number || "")) - .forEach((unit: Unit) => { - unitsFormatted.push({ - number: { content: unit.number }, - sqFeet: { - content: ( - <> - {unit.sqFeet ? ( - <> - {parseInt(unit.sqFeet)} {t("t.sqFeet")} - - ) : ( - <> - )} - - ), - }, - numBathrooms: { - content: ( - - {unit.numBathrooms === 0 - ? t("listings.unit.sharedBathroom") - : unit.numBathrooms} - - ), - }, - floor: { content: {unit.floor} }, - }) + units.forEach((unit: Unit) => { + unitsFormatted.push({ + number: { content: unit.number }, + sqFeet: { + content: ( + <> + {unit.sqFeet ? ( + <> + {parseInt(unit.sqFeet)} {t("t.sqFeet")} + + ) : ( + <> + )} + + ), + }, + numBathrooms: { + content: ( + + {unit.numBathrooms === 0 ? t("listings.unit.sharedBathroom") : unit.numBathrooms} + + ), + }, + floor: { content: {unit.floor} }, }) + }) let areaRangeSection: React.ReactNode if (unitSummary.areaRange?.min || unitSummary.areaRange?.max) { From 295621427e1afdf5923ae3cc0e9ddcd76fa254fe Mon Sep 17 00:00:00 2001 From: Emily Jablonski Date: Mon, 17 Feb 2025 13:00:40 -0700 Subject: [PATCH 3/3] refactor: removed unnecessary check --- shared-helpers/src/views/occupancyFormatting.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-helpers/src/views/occupancyFormatting.tsx b/shared-helpers/src/views/occupancyFormatting.tsx index f64c06b07e..b39e204140 100644 --- a/shared-helpers/src/views/occupancyFormatting.tsx +++ b/shared-helpers/src/views/occupancyFormatting.tsx @@ -3,7 +3,7 @@ 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 && minOcc < maxOcc) { + if (minOcc && maxOcc && minOcc < maxOcc) { return `${minOcc}-${maxOcc} ${t("t.people")}` } if (minOcc && maxOcc && minOcc === maxOcc) {