You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

73 lines
1.8 KiB

  1. /* eslint-env mocha */
  2. import React from "react"
  3. import expect, { createSpy } from "expect"
  4. import { shallow } from "enzyme"
  5. import { fromJS } from "immutable"
  6. import Schemes from "components/schemes"
  7. describe("<Schemes/>", function(){
  8. it("calls props.specActions.setScheme() when no currentScheme is selected", function(){
  9. let setSchemeSpy = createSpy()
  10. // Given
  11. let props = {
  12. specActions: {
  13. setScheme: setSchemeSpy
  14. },
  15. schemes: fromJS([
  16. "http",
  17. "https"
  18. ]),
  19. currentScheme: undefined,
  20. path: "/test",
  21. method: "get"
  22. }
  23. // When
  24. let wrapper = shallow(<Schemes {...props}/>)
  25. // Then currentScheme should default to first scheme in options list
  26. expect(props.specActions.setScheme).toHaveBeenCalledWith("http", "/test" , "get")
  27. // When the currentScheme is no longer in the list of options
  28. props.schemes = fromJS([
  29. "https"
  30. ])
  31. wrapper.setProps(props)
  32. // Then currentScheme should default to first scheme in options list, again
  33. expect(props.specActions.setScheme).toHaveBeenCalledWith("https", "/test", "get")
  34. })
  35. it("doesn't call props.specActions.setScheme() when schemes hasn't changed", function(){
  36. let setSchemeSpy = createSpy()
  37. // Given
  38. let props = {
  39. specActions: {
  40. setScheme: setSchemeSpy
  41. },
  42. schemes: fromJS([
  43. "http",
  44. "https"
  45. ]),
  46. currentScheme: "https"
  47. }
  48. // When
  49. let wrapper = shallow(<Schemes {...props}/>)
  50. // Should be called initially, to set the global state
  51. expect(setSchemeSpy.calls.length).toEqual(1)
  52. // After an update
  53. wrapper.instance().componentWillReceiveProps(props)
  54. // Should not be called again, since `currentScheme` is in schemes
  55. expect(setSchemeSpy.calls.length).toEqual(1)
  56. })
  57. })