online-validator-badge.jsx 2.5 KB

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