Skip to content

Commit

Permalink
add testing utility, update platforms tests to accommodate name chang…
Browse files Browse the repository at this point in the history
…e from issue-816
  • Loading branch information
naomatheus committed Sep 6, 2023
1 parent 334e495 commit 6dcd48a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/utils/__tests__/use-platform-list.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from "@testing-library/react-hooks"

import { getCategoryName } from "../rename-category-test-util"
import usePlatformList from "../use-platform-list"
import { explorePlatformsQuery } from "../../../test/__fixtures__"

Expand All @@ -16,7 +16,11 @@ it("the default platform list (without filters)", () => {
const firstPlatform = platformList.filtered[0]
const lastPlatform = platformList.filtered[platformList.filtered.length - 1]
const platformGroups = Object.keys(platformList.grouped)
const firstGroup = platformList.grouped[platformGroups[0]]
// console.log({ platformList })
// console.log({ platformGroups })
const firstGroup = platformList.grouped[platformGroups[platformGroups.length - 1]]

Check failure on line 21 in src/utils/__tests__/use-platform-list.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎···`
console.log({ firstGroup })

Check failure on line 22 in src/utils/__tests__/use-platform-list.test.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`


expect(platformList.filtered.length).toEqual(list.length)
expect(platformGroups.length).toBeGreaterThanOrEqual(5)
Expand Down Expand Up @@ -48,7 +52,7 @@ it("the platform list sorted a > z (without filters)", () => {
const firstPlatform = platformList.filtered[0]
const lastPlatform = platformList.filtered[platformList.filtered.length - 1]
const platformGroups = Object.keys(platformList.grouped)
const firstGroup = platformList.grouped[platformGroups[0]]
const firstGroup = platformList.grouped[platformGroups[platformGroups.length - 1]]

Check failure on line 55 in src/utils/__tests__/use-platform-list.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎···`

expect(platformList.filtered.length).toEqual(list.length)
expect(platformGroups.length).toBeGreaterThanOrEqual(5)
Expand Down Expand Up @@ -80,7 +84,7 @@ it("the platform list sorted z > a (without filters)", () => {
const firstPlatform = platformList.filtered[0]
const lastPlatform = platformList.filtered[platformList.filtered.length - 1]
const platformGroups = Object.keys(platformList.grouped)
const firstGroup = platformList.grouped[platformGroups[0]]
const firstGroup = platformList.grouped[platformGroups[platformGroups.length - 1]]

Check failure on line 87 in src/utils/__tests__/use-platform-list.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎···`

expect(platformList.filtered.length).toEqual(list.length)
expect(platformGroups.length).toBeGreaterThanOrEqual(5)
Expand Down Expand Up @@ -115,7 +119,7 @@ it("the platform list with a filter selected", () => {
const firstPlatform = platformList.filtered[0]
const lastPlatform = platformList.filtered[platformList.filtered.length - 1]
const platformGroups = Object.keys(platformList.grouped)
const firstGroup = platformList.grouped[platformGroups[0]]
const firstGroup = platformList.grouped[platformGroups[platformGroups.length - 1]]

Check failure on line 122 in src/utils/__tests__/use-platform-list.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎···`

expect(platformList.filtered.length).toBeLessThan(list.length)
expect(platformGroups.length).toBeGreaterThanOrEqual(5)
Expand All @@ -137,7 +141,10 @@ it("the platform list with a filter selected", () => {
expect(platform.instruments.map(x => x.id)).toContain(instrumentId)
})
platformGroups.forEach(group => {
platformList.grouped[group].forEach(platform => {
// Adjusting group name for the changed category name
const adjustedGroupName = getCategoryName(group);

Check failure on line 145 in src/utils/__tests__/use-platform-list.test.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

platformList.grouped[adjustedGroupName].forEach(platform => {
expect(platform.instruments.map(x => x.id)).toContain(instrumentId)
})
})
Expand Down
4 changes: 4 additions & 0 deletions src/utils/rename-category-test-util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const getCategoryName = (category) => {

Check failure on line 1 in src/utils/rename-category-test-util.js

View workflow job for this annotation

GitHub Actions / lint

Replace `(category)` with `category`
if (category === "Aircraft") return "Air-based platforms";

Check failure on line 2 in src/utils/rename-category-test-util.js

View workflow job for this annotation

GitHub Actions / lint

Replace `····if·(category·===·"Aircraft")·return·"Air-based·platforms";` with `··if·(category·===·"Aircraft")·return·"Air-based·platforms"`
return category;

Check failure on line 3 in src/utils/rename-category-test-util.js

View workflow job for this annotation

GitHub Actions / lint

Replace `····return·category;` with `··return·category`
};

Check failure on line 4 in src/utils/rename-category-test-util.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

0 comments on commit 6dcd48a

Please sign in to comment.