Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

76 Zeilen
1.4 KiB

  1. /* eslint-env mocha */
  2. import expect from "expect"
  3. import { fromJS } from "immutable"
  4. import { mapToList } from "core/utils"
  5. describe("utils", function(){
  6. describe("mapToList", function(){
  7. it("should convert a map to a list, setting `key`", function(){
  8. // With
  9. const aMap = fromJS({
  10. a: {
  11. one: 1,
  12. },
  13. b: {
  14. two: 2,
  15. }
  16. })
  17. // When
  18. const aList = mapToList(aMap, "someKey")
  19. // Then
  20. expect(aList.toJS()).toEqual([
  21. { someKey: "a", one: 1 },
  22. { someKey: "b", two: 2 },
  23. ])
  24. })
  25. it("should flatten an arbitrarily deep map", function(){
  26. // With
  27. const aMap = fromJS({
  28. a: {
  29. one: {
  30. alpha: true
  31. }
  32. },
  33. b: {
  34. two: {
  35. bravo: true
  36. },
  37. three: {
  38. charlie: true
  39. }
  40. }
  41. })
  42. // When
  43. const aList = mapToList(aMap, ["levelA", "levelB"])
  44. // Then
  45. expect(aList.toJS()).toEqual([
  46. { levelA: "a", levelB: "one", alpha: true },
  47. { levelA: "b", levelB: "two", bravo: true },
  48. { levelA: "b", levelB: "three", charlie: true },
  49. ])
  50. })
  51. it("should handle an empty map", function(){
  52. // With
  53. const aMap = fromJS({})
  54. // When
  55. const aList = mapToList(aMap, ["levelA", "levelB"])
  56. // Then
  57. expect(aList.toJS()).toEqual([])
  58. })
  59. })
  60. })