76 lines
1.4 KiB
JavaScript
76 lines
1.4 KiB
JavaScript
/* eslint-env mocha */
|
|
import expect from "expect"
|
|
import { fromJS } from "immutable"
|
|
import { mapToList } from "core/utils"
|
|
|
|
describe("utils", function(){
|
|
|
|
describe("mapToList", function(){
|
|
|
|
it("should convert a map to a list, setting `key`", function(){
|
|
// With
|
|
const aMap = fromJS({
|
|
a: {
|
|
one: 1,
|
|
},
|
|
b: {
|
|
two: 2,
|
|
}
|
|
})
|
|
|
|
// When
|
|
const aList = mapToList(aMap, "someKey")
|
|
|
|
// Then
|
|
expect(aList.toJS()).toEqual([
|
|
{ someKey: "a", one: 1 },
|
|
{ someKey: "b", two: 2 },
|
|
])
|
|
})
|
|
|
|
it("should flatten an arbitrarily deep map", function(){
|
|
// With
|
|
const aMap = fromJS({
|
|
a: {
|
|
one: {
|
|
alpha: true
|
|
}
|
|
},
|
|
b: {
|
|
two: {
|
|
bravo: true
|
|
},
|
|
three: {
|
|
charlie: true
|
|
}
|
|
}
|
|
})
|
|
|
|
// When
|
|
const aList = mapToList(aMap, ["levelA", "levelB"])
|
|
|
|
// Then
|
|
expect(aList.toJS()).toEqual([
|
|
{ levelA: "a", levelB: "one", alpha: true },
|
|
{ levelA: "b", levelB: "two", bravo: true },
|
|
{ levelA: "b", levelB: "three", charlie: true },
|
|
])
|
|
|
|
})
|
|
|
|
it("should handle an empty map", function(){
|
|
// With
|
|
const aMap = fromJS({})
|
|
|
|
// When
|
|
const aList = mapToList(aMap, ["levelA", "levelB"])
|
|
|
|
// Then
|
|
expect(aList.toJS()).toEqual([])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|