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