in with the new
This commit is contained in:
75
test/core/utils.js
Normal file
75
test/core/utils.js
Normal file
@@ -0,0 +1,75 @@
|
||||
/* eslint-env mocha */
|
||||
import expect, { createSpy } 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([])
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user