selectors.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { getSourceInitialState } from 'app/containers/Source/reducer'
  2. /*
  3. * <<
  4. * Davinci
  5. * ==
  6. * Copyright (C) 2016 - 2017 EDP
  7. * ==
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. * >>
  20. */
  21. import {
  22. selectSource,
  23. makeSelectSources
  24. } from 'app/containers/Source/selectors'
  25. const state = {
  26. source: getSourceInitialState()
  27. }
  28. describe('selectSource', () => {
  29. it('should select the source state', () => {
  30. expect(selectSource(state)).toEqual(state.source)
  31. })
  32. })
  33. describe('makeSelectSources', () => {
  34. const sourcesSelector = makeSelectSources()
  35. it('should select the sources', () => {
  36. expect(sourcesSelector(state)).toEqual(state.source.sources)
  37. })
  38. it('should memo correctly', () => {
  39. sourcesSelector(state)
  40. expect(sourcesSelector.recomputations()).toBe(1)
  41. sourcesSelector(state)
  42. expect(sourcesSelector.recomputations()).toBe(1)
  43. sourcesSelector({
  44. ...state,
  45. source: {
  46. ...state.source
  47. }
  48. })
  49. expect(sourcesSelector.recomputations()).toBe(2)
  50. })
  51. })