online-validator-badge.jsx 972 B

123456789101112131415161718192021222324252627282930313233
  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/> Anchor Target Safety", function () {
  8. it("should render a validator link with safe `rel` attributes", 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. const anchor = wrapper.find("a")
  21. // Then
  22. expect(anchor.props().href).toEqual(
  23. "https://validator.swagger.io/validator/debug?url=swagger.json"
  24. )
  25. expect(anchor.props().target).toEqual("_blank")
  26. expect(anchor.props().rel || "").toInclude("noopener")
  27. expect(anchor.props().rel || "").toInclude("noreferrer")
  28. })
  29. })