Skip to content

Commit

Permalink
Merge pull request #574 from NASA-IMPACT/issue-816/update-text
Browse files Browse the repository at this point in the history
update aircraft to air-based platforms, apply linting
  • Loading branch information
naomatheus authored Sep 15, 2023
2 parents 899646b + a7e0b34 commit c281db3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
6 changes: 3 additions & 3 deletions playwright/e2e/explore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ test.describe("Explore", () => {
.locator("xpath=..") // TODO
expect(
await hamsrCard.locator("[data-cy=shortname]").textContent()
).toContain("HAMSR")
).toMatch("HAMSR")
expect(
await hamsrCard.locator("[data-cy=longname]").textContent()
).toContain(
"High Altitude Monolithic Microwave integrated Circuit(MMIC) Sounding Radiometer"
).toMatch(
"High Altitude Monolithic Microwave integrated Circuit (MMIC) Sounding Radiometer"
)

await page.waitForSelector("[data-cy=instruments-card-footer]", {
Expand Down
10 changes: 8 additions & 2 deletions src/pages/explore/platforms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useRef, useEffect } from "react"
import PropTypes from "prop-types"
import { graphql } from "gatsby"

import { replaceCategoryInGrouped } from "../../utils/replace-category-name"
import { NEGATIVE } from "../../utils/constants"
import { colors } from "../../theme"
import { selector } from "../../utils/filter-utils"
Expand Down Expand Up @@ -35,13 +35,19 @@ export default function ExplorePlatforms({ data, location }) {
}
}, [selectedFilterId])

const platformList = usePlatformList(
let platformList = usePlatformList(
allPlatform.list,
sortOrder,
selectedFilterIds,
searchResult
)

// modify after receiving from hook
platformList = {
...platformList,
grouped: replaceCategoryInGrouped(platformList.grouped),
}

const addFilter = id => setFilter([...selectedFilterIds, id])

const removeFilter = id => setFilter(selectedFilterIds.filter(f => f !== id))
Expand Down
20 changes: 14 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,9 @@ 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]]
const firstGroup =
platformList.grouped[platformGroups[platformGroups.length - 1]]
console.log({ firstGroup })

expect(platformList.filtered.length).toEqual(list.length)
expect(platformGroups.length).toBeGreaterThanOrEqual(5)
Expand Down Expand Up @@ -48,7 +50,8 @@ 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]]

expect(platformList.filtered.length).toEqual(list.length)
expect(platformGroups.length).toBeGreaterThanOrEqual(5)
Expand Down Expand Up @@ -80,7 +83,8 @@ 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]]

expect(platformList.filtered.length).toEqual(list.length)
expect(platformGroups.length).toBeGreaterThanOrEqual(5)
Expand Down Expand Up @@ -115,7 +119,8 @@ 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]]

expect(platformList.filtered.length).toBeLessThan(list.length)
expect(platformGroups.length).toBeGreaterThanOrEqual(5)
Expand All @@ -137,7 +142,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)

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 => {
if (category === "Aircraft") return "Air-based platforms"
return category
}
10 changes: 10 additions & 0 deletions src/utils/replace-category-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const replaceCategoryInGrouped = grouped => {
const updated = { ...grouped }

if (updated["Aircraft"]) {
updated["Air-based platforms"] = updated["Aircraft"]
delete updated["Aircraft"]
}

return updated
}
3 changes: 1 addition & 2 deletions src/utils/use-platform-list.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useState, useEffect } from "react"

import { sortFunctions, platformFilter } from "../utils/filter-utils"

// Setting these default search categories will ensure their order of appearance.
const searchCategories = {
Aircraft: [],
"Air-based platforms": [],
"Mobile land-based platforms": [],
"Stationary land sites": [],
"Water-based platforms": [],
Expand Down

0 comments on commit c281db3

Please sign in to comment.