online-validator-badge.jsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import React from "react"
  2. import { mount } from "enzyme"
  3. import OnlineValidatorBadge from "components/online-validator-badge"
  4. describe("<OnlineValidatorBadge/>", function () {
  5. it("should render a validator link and image correctly for the default validator", function () {
  6. // When
  7. const props = {
  8. getConfigs: () => ({}),
  9. getComponent: () => null,
  10. specSelectors: {
  11. url: () => "swagger.json"
  12. }
  13. }
  14. const wrapper = mount(
  15. <OnlineValidatorBadge {...props} />
  16. )
  17. // Then
  18. expect(wrapper.find("a").props().href).toEqual(
  19. "https://validator.swagger.io/validator/debug?url=swagger.json"
  20. )
  21. expect(wrapper.find("ValidatorImage").length).toEqual(1)
  22. expect(wrapper.find("ValidatorImage").props().src).toEqual(
  23. "https://validator.swagger.io/validator?url=swagger.json"
  24. )
  25. })
  26. it("should encode a definition URL correctly", function () {
  27. // When
  28. const props = {
  29. getConfigs: () => ({}),
  30. getComponent: () => null,
  31. specSelectors: {
  32. url: () => "http://google.com/swagger.json"
  33. }
  34. }
  35. const wrapper = mount(
  36. <OnlineValidatorBadge {...props} />
  37. )
  38. // Then
  39. expect(wrapper.find("a").props().href).toEqual(
  40. "https://validator.swagger.io/validator/debug?url=http%3A%2F%2Fgoogle.com%2Fswagger.json"
  41. )
  42. expect(wrapper.find("ValidatorImage").length).toEqual(1)
  43. expect(wrapper.find("ValidatorImage").props().src).toEqual(
  44. "https://validator.swagger.io/validator?url=http%3A%2F%2Fgoogle.com%2Fswagger.json"
  45. )
  46. })
  47. it.skip("should resolve a definition URL against the browser's location", function () {
  48. // TODO: mock `window`
  49. // When
  50. const props = {
  51. getConfigs: () => ({}),
  52. getComponent: () => null,
  53. specSelectors: {
  54. url: () => "http://google.com/swagger.json"
  55. }
  56. }
  57. const wrapper = mount(
  58. <OnlineValidatorBadge {...props} />
  59. )
  60. // Then
  61. expect(wrapper.find("a").props().href).toEqual(
  62. "https://validator.swagger.io/validator/debug?url=http%3A%2F%2Fgoogle.com%2Fswagger.json"
  63. )
  64. expect(wrapper.find("ValidatorImage").length).toEqual(1)
  65. expect(wrapper.find("ValidatorImage").props().src).toEqual(
  66. "https://validator.swagger.io/validator?url=http%3A%2F%2Fgoogle.com%2Fswagger.json"
  67. )
  68. })
  69. // should resolve a definition URL against the browser's location
  70. })