Skip to content

Commit

Permalink
Merge branch 'main' into pangeo_forge_oisst
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrjones committed Mar 20, 2024
2 parents cc3c4ce + 9fa3ee3 commit 598b037
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carbonplan/maps",
"version": "3.1.2",
"version": "3.1.3",
"description": "interactive data-driven web maps",
"main": "dst/index.js",
"module": "dst/index.esm.js",
Expand Down
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ export const getBandInformation = (selector) => {
return updatedBands
}, {})

Object.keys(selector).forEach((key) => {
if (!Array.isArray(selector[key])) {
Object.keys(combinedBands).forEach((combinedKey) => {
combinedBands[combinedKey][key] = selector[key]
})
}
})
return combinedBands
}

Expand Down
71 changes: 71 additions & 0 deletions src/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { getBandInformation } from './utils'

describe('utils', () => {
describe('getBandInformation()', () => {
it('returns no bands for empty selectors', () => {
expect(getBandInformation({})).toEqual({})
})

it('returns no bands for non-array selector values', () => {
expect(getBandInformation({ time: 0 })).toEqual({})
expect(getBandInformation({ time: 0, variable: 'pr' })).toEqual({})
})

it('handles array selector values', () => {
expect(getBandInformation({ time: ['jan', 'feb'] })).toEqual({
jan: { time: 'jan' },
feb: { time: 'feb' },
})
})

it('handles array selector values with number entries', () => {
expect(getBandInformation({ time: [1, 2] })).toEqual({
time_1: { time: 1 },
time_2: { time: 2 },
})
})

it('handles multiple array selector values', () => {
expect(
getBandInformation({ time: ['jan', 'feb'], variable: ['pr', 'tavg'] })
).toEqual({
jan_pr: { time: 'jan', variable: 'pr' },
feb_pr: { time: 'feb', variable: 'pr' },
jan_tavg: { time: 'jan', variable: 'tavg' },
feb_tavg: { time: 'feb', variable: 'tavg' },
})
})

it('handles multiple array selector values with number entries', () => {
expect(
getBandInformation({ time: [1, 2], variable: ['pr', 'tavg'] })
).toEqual({
time_1_pr: { time: 1, variable: 'pr' },
time_2_pr: { time: 2, variable: 'pr' },
time_1_tavg: { time: 1, variable: 'tavg' },
time_2_tavg: { time: 2, variable: 'tavg' },
})
expect(getBandInformation({ time: [1, 2], variable: [3, 4] })).toEqual({
time_1_variable_3: { time: 1, variable: 3 },
time_2_variable_3: { time: 2, variable: 3 },
time_1_variable_4: { time: 1, variable: 4 },
time_2_variable_4: { time: 2, variable: 4 },
})
})

it('handles mix of array selector values with non-array selector values', () => {
expect(
getBandInformation({ time: ['jan', 'feb'], variable: 'pr' })
).toEqual({
jan: { time: 'jan', variable: 'pr' },
feb: { time: 'feb', variable: 'pr' },
})
expect(getBandInformation({ time: ['jan', 'feb'], variable: 3 })).toEqual(
{
jan: { time: 'jan', variable: 3 },
feb: { time: 'feb', variable: 3 },
}
)
})
})
})

0 comments on commit 598b037

Please sign in to comment.