in with the new

This commit is contained in:
Ron
2017-03-17 21:17:53 -07:00
parent bd8344c808
commit f22a628934
157 changed files with 12952 additions and 0 deletions

75
test/core/utils.js Normal file
View 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([])
})
})
})