Skip to content

Commit 3ed335e

Browse files
committed
test(test:unit-jest): fix all failing tests for this script
We needed to align new cheerio and enzyme APIS with tests. Refs #7341
1 parent 6405fe7 commit 3ed335e

File tree

8 files changed

+61
-65
lines changed

8 files changed

+61
-65
lines changed

test/unit/bugs/3199-sanitization-escaping.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ describe("UI-3199: Sanitized Markdown causing code examples to be double escaped
1616
let el = render(<Markdown {...props}/>)
1717

1818
expect(el.find("code").first().text()).toEqual("{\"abc\": \"def\"}\n")
19-
expect(el.find("code").first().html()).toEqual("{&quot;abc&quot;: &quot;def&quot;}\n")
19+
expect(el.find("code").first().html()).toEqual("{\"abc\": \"def\"}\n")
2020
})
2121
})

test/unit/components/json-schema-form.jsx

+15-13
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ describe("<JsonSchemaForm/>", function(){
3131

3232
let wrapper = render(<JsonSchemaForm {...props}/>)
3333

34-
expect(wrapper.find("select").length).toEqual(1)
35-
expect(wrapper.find("select option").length).toEqual(3)
36-
expect(wrapper.find("select option").eq(0).text()).toEqual("--")
37-
expect(wrapper.find("select option").eq(1).text()).toEqual("one")
38-
expect(wrapper.find("select option").eq(2).text()).toEqual("two")
34+
expect(wrapper.get(0).name).toEqual("select")
35+
expect(wrapper.find("option").length).toEqual(3)
36+
expect(wrapper.find("option").eq(0).text()).toEqual("--")
37+
expect(wrapper.find("option").eq(1).text()).toEqual("one")
38+
expect(wrapper.find("option").eq(2).text()).toEqual("two")
3939
})
4040

4141
it("should render a string enum as disabled when JsonSchemaForm is disabled", function(){
@@ -55,7 +55,7 @@ describe("<JsonSchemaForm/>", function(){
5555

5656
let wrapper = render(<JsonSchemaForm {...props}/>)
5757

58-
expect(wrapper.find("select").attr("disabled")).toEqual("disabled")
58+
expect(wrapper.attr("disabled")).toEqual("disabled")
5959
})
6060

6161

@@ -76,7 +76,7 @@ describe("<JsonSchemaForm/>", function(){
7676

7777
let wrapper = render(<JsonSchemaForm {...props}/>)
7878

79-
expect(wrapper.find("select").length).toEqual(1)
79+
expect(wrapper.get(0).name).toEqual("select")
8080
expect(wrapper.find("select option").length).toEqual(2)
8181
expect(wrapper.find("select option").eq(0).text()).toEqual("one")
8282
expect(wrapper.find("select option").eq(1).text()).toEqual("two")
@@ -98,7 +98,7 @@ describe("<JsonSchemaForm/>", function(){
9898

9999
let wrapper = render(<JsonSchemaForm {...props}/>)
100100

101-
expect(wrapper.find("select").length).toEqual(1)
101+
expect(wrapper.get(0).name).toEqual("select")
102102
expect(wrapper.find("select option").length).toEqual(3)
103103
expect(wrapper.find("select option").eq(0).text()).toEqual("--")
104104
expect(wrapper.find("select option").eq(1).text()).toEqual("true")
@@ -122,7 +122,7 @@ describe("<JsonSchemaForm/>", function(){
122122

123123
let wrapper = render(<JsonSchemaForm {...props}/>)
124124

125-
expect(wrapper.find("select").length).toEqual(1)
125+
expect(wrapper.get(0).name).toEqual("select")
126126
expect(wrapper.find("select option").length).toEqual(2)
127127
expect(wrapper.find("select option").eq(0).text()).toEqual("--")
128128
expect(wrapper.find("select option").eq(1).text()).toEqual("true")
@@ -145,7 +145,7 @@ describe("<JsonSchemaForm/>", function(){
145145

146146
let wrapper = render(<JsonSchemaForm {...props}/>)
147147

148-
expect(wrapper.find("select").length).toEqual(1)
148+
expect(wrapper.get(0).name).toEqual("select")
149149
expect(wrapper.find("select option").length).toEqual(3)
150150
expect(wrapper.find("select option").eq(0).text()).toEqual("--")
151151
expect(wrapper.find("select option").eq(1).text()).toEqual("true")
@@ -170,7 +170,7 @@ describe("<JsonSchemaForm/>", function(){
170170

171171
let wrapper = render(<JsonSchemaForm {...props}/>)
172172

173-
expect(wrapper.find("select").length).toEqual(1)
173+
expect(wrapper.get(0).name).toEqual("select")
174174
expect(wrapper.find("select option").length).toEqual(1)
175175
expect(wrapper.find("select option").eq(0).text()).toEqual("true")
176176
expect(wrapper.find("select option:checked").first().text()).toEqual("true")
@@ -225,7 +225,8 @@ describe("<JsonSchemaForm/>", function(){
225225

226226
let wrapper = render(<JsonSchemaForm {...props}/>)
227227

228-
expect(wrapper.find("input").length).toEqual(1)
228+
expect(wrapper.length).toEqual(1)
229+
expect(wrapper.get(0).name).toEqual("input")
229230
// expect(wrapper.find("select input").length).toEqual(1)
230231
// expect(wrapper.find("select option").first().text()).toEqual("true")
231232
})
@@ -247,7 +248,8 @@ describe("<JsonSchemaForm/>", function(){
247248

248249
let wrapper = render(<JsonSchemaForm {...props}/>)
249250

250-
expect(wrapper.find("input").length).toEqual(1)
251+
expect(wrapper.length).toEqual(1)
252+
expect(wrapper.get(0).name).toEqual("input")
251253
// expect(wrapper.find("select input").length).toEqual(1)
252254
// expect(wrapper.find("select option").first().text()).toEqual("true")
253255
})

test/unit/components/markdown.jsx

+14-14
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,38 @@ describe("Markdown component", function () {
99
const getConfigs = () => ({ useUnsafeMarkdown: true })
1010
const str = `<span class="method" style="border-width: 1px" data-attr="value">ONE</span>`
1111
const el = render(<Markdown source={str} getConfigs={getConfigs} />)
12-
expect(el.html()).toEqual(`<div class="markdown"><p><span data-attr="value" style="border-width: 1px" class="method">ONE</span></p>\n</div>`)
12+
expect(el.prop("outerHTML")).toEqual(`<div class="markdown"><p><span data-attr="value" style="border-width: 1px" class="method">ONE</span></p>\n</div>`)
1313
})
1414

1515
it("strips class, style and data-* attribs from elements", function () {
1616
const getConfigs = () => ({ useUnsafeMarkdown: false })
1717
const str = `<span class="method" style="border-width: 1px" data-attr="value">ONE</span>`
1818
const el = render(<Markdown source={str} getConfigs={getConfigs} />)
19-
expect(el.html()).toEqual(`<div class="markdown"><p><span>ONE</span></p>\n</div>`)
19+
expect(el.prop("outerHTML")).toEqual(`<div class="markdown"><p><span>ONE</span></p>\n</div>`)
2020
})
2121

2222
it("allows td elements with colspan attrib", function () {
2323
const str = `<table><tr><td>ABC</td></tr></table>`
2424
const el = render(<Markdown source={str} />)
25-
expect(el.html()).toEqual(`<div class="markdown"><table><tbody><tr><td>ABC</td></tr></tbody></table></div>`)
25+
expect(el.prop("outerHTML")).toEqual(`<div class="markdown"><table><tbody><tr><td>ABC</td></tr></tbody></table></div>`)
2626
})
2727

2828
it("allows image elements", function () {
2929
const str = `![Image alt text](http://image.source "Image title")`
3030
const el = render(<Markdown source={str} />)
31-
expect(el.html()).toEqual(`<div class="markdown"><p><img title="Image title" alt="Image alt text" src="http://image.source"></p>\n</div>`)
31+
expect(el.prop("outerHTML")).toEqual(`<div class="markdown"><p><img title="Image title" alt="Image alt text" src="http://image.source"></p>\n</div>`)
3232
})
3333

3434
it("allows image elements with https scheme", function () {
3535
const str = `![Image alt text](https://image.source "Image title")`
3636
const el = render(<Markdown source={str} />)
37-
expect(el.html()).toEqual(`<div class="markdown"><p><img title="Image title" alt="Image alt text" src="https://image.source"></p>\n</div>`)
37+
expect(el.prop("outerHTML")).toEqual(`<div class="markdown"><p><img title="Image title" alt="Image alt text" src="https://image.source"></p>\n</div>`)
3838
})
3939

4040
it("allows image elements with data scheme", function () {
4141
const str = `<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==">`
4242
const el = render(<Markdown source={str} />)
43-
expect(el.html()).toEqual(`<div class="markdown"><p>` + str + `</p>\n</div>`)
43+
expect(el.prop("outerHTML")).toEqual(`<div class="markdown"><p>` + str + `</p>\n</div>`)
4444
})
4545

4646
it("allows heading elements", function () {
@@ -52,13 +52,13 @@ describe("Markdown component", function () {
5252
##### h5
5353
###### h6`
5454
const el = render(<Markdown source={str} />)
55-
expect(el.html()).toEqual(`<div class="markdown"><h1>h1</h1>\n<h2>h2</h2>\n<h3>h3</h3>\n<h4>h4</h4>\n<h5>h5</h5>\n<h6>h6</h6>\n</div>`)
55+
expect(el.prop("outerHTML")).toEqual(`<div class="markdown"><h1>h1</h1>\n<h2>h2</h2>\n<h3>h3</h3>\n<h4>h4</h4>\n<h5>h5</h5>\n<h6>h6</h6>\n</div>`)
5656
})
5757

5858
it("allows links", function () {
5959
const str = `[Link](https://example.com/)`
6060
const el = render(<Markdown source={str} />)
61-
expect(el.html()).toEqual(`<div class="markdown"><p><a rel="noopener noreferrer" target="_blank" href="https://example.com/">Link</a></p>\n</div>`)
61+
expect(el.prop("outerHTML")).toEqual(`<div class="markdown"><p><a rel="noopener noreferrer" target="_blank" href="https://example.com/">Link</a></p>\n</div>`)
6262
})
6363
})
6464

@@ -67,32 +67,32 @@ describe("Markdown component", function () {
6767
const getConfigs = () => ({ useUnsafeMarkdown: true })
6868
const str = `<span class="method" style="border-width: 1px" data-attr="value">ONE</span>`
6969
const el = render(<OAS3Markdown source={str} getConfigs={getConfigs} />)
70-
expect(el.html()).toEqual(`<div class="renderedMarkdown"><p><span data-attr="value" style="border-width: 1px" class="method">ONE</span></p></div>`)
70+
expect(el.prop("outerHTML")).toEqual(`<div class="renderedMarkdown"><p><span data-attr="value" style="border-width: 1px" class="method">ONE</span></p></div>`)
7171
})
7272

7373
it("strips class, style and data-* attribs from elements", function () {
7474
const getConfigs = () => ({ useUnsafeMarkdown: false })
7575
const str = `<span class="method" style="border-width: 1px" data-attr="value">ONE</span>`
7676
const el = render(<OAS3Markdown source={str} getConfigs={getConfigs} />)
77-
expect(el.html()).toEqual(`<div class="renderedMarkdown"><p><span>ONE</span></p></div>`)
77+
expect(el.prop("outerHTML")).toEqual(`<div class="renderedMarkdown"><p><span>ONE</span></p></div>`)
7878
})
7979

8080
it("allows image elements", function () {
8181
const str = `![Image alt text](http://image.source "Image title")`
8282
const el = render(<OAS3Markdown source={str} />)
83-
expect(el.html()).toEqual(`<div class="renderedMarkdown"><p><img title="Image title" alt="Image alt text" src="http://image.source"></p></div>`)
83+
expect(el.prop("outerHTML")).toEqual(`<div class="renderedMarkdown"><p><img title="Image title" alt="Image alt text" src="http://image.source"></p></div>`)
8484
})
8585

8686
it("allows image elements with https scheme", function () {
8787
const str = `![Image alt text](https://image.source "Image title")`
8888
const el = render(<OAS3Markdown source={str} />)
89-
expect(el.html()).toEqual(`<div class="renderedMarkdown"><p><img title="Image title" alt="Image alt text" src="https://image.source"></p></div>`)
89+
expect(el.prop("outerHTML")).toEqual(`<div class="renderedMarkdown"><p><img title="Image title" alt="Image alt text" src="https://image.source"></p></div>`)
9090
})
9191

9292
it("allows image elements with data scheme", function () {
9393
const str = `<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==">`
9494
const el = render(<OAS3Markdown source={str} />)
95-
expect(el.html()).toEqual(`<div class="renderedMarkdown"><p>` + str + `</p></div>`)
95+
expect(el.prop("outerHTML")).toEqual(`<div class="renderedMarkdown"><p>` + str + `</p></div>`)
9696
})
9797

9898
it("allows heading elements", function () {
@@ -104,7 +104,7 @@ describe("Markdown component", function () {
104104
##### h5
105105
###### h6`
106106
const el = render(<OAS3Markdown source={str} />)
107-
expect(el.html()).toEqual(`<div class="renderedMarkdown"><h1>h1</h1>\n<h2>h2</h2>\n<h3>h3</h3>\n<h4>h4</h4>\n<h5>h5</h5>\n<h6>h6</h6></div>`)
107+
expect(el.prop("outerHTML")).toEqual(`<div class="renderedMarkdown"><h1>h1</h1>\n<h2>h2</h2>\n<h3>h3</h3>\n<h4>h4</h4>\n<h5>h5</h5>\n<h6>h6</h6></div>`)
108108
})
109109
})
110110
})

test/unit/components/operation-tag.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("<OperationTag/>", function(){
4444

4545
const opblockTag = wrapper.find(".opblock-tag")
4646
expect(opblockTag.length).toEqual(1)
47-
expect(opblockTag.getNode().type).toEqual("h3")
47+
expect(opblockTag.getElement().type).toEqual("h3")
4848

4949
const renderedLink = wrapper.find("Link")
5050
expect(renderedLink.length).toEqual(1)

test/unit/core/system/wrapComponent.jsx

+12-18
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ describe("wrapComponents", () => {
3131
let Component = system.getSystem().getComponents("wow")
3232
const wrapper = render(<Component name="Normal" />)
3333

34-
const container = wrapper.children().first()
35-
expect(container[0].name).toEqual("container")
34+
expect(wrapper.get(0).name).toEqual("container")
3635

37-
const children = container.children()
36+
const children = wrapper.children()
3837
expect(children.length).toEqual(2)
3938
expect(children.eq(0).text()).toEqual("Normal component")
4039
expect(children.eq(1).text()).toEqual("Wrapped component")
@@ -76,10 +75,9 @@ describe("wrapComponents", () => {
7675
let Component = system.getSystem().getComponents("wow")
7776
const wrapper = render(<Component name="Normal" />)
7877

79-
const container = wrapper.children().first()
80-
expect(container[0].name).toEqual("container")
78+
expect(wrapper.get(0).name).toEqual("container")
8179

82-
const children = container.children()
80+
const children = wrapper.children()
8381
expect(children.length).toEqual(2)
8482
expect(children.eq(0).text()).toEqual("Normal component")
8583
expect(children.eq(1).text()).toEqual("Wrapped component")
@@ -128,10 +126,9 @@ describe("wrapComponents", () => {
128126
let Component = mySystem.getSystem().getComponents("wow")
129127
const wrapper = render(<Component name="Normal" />)
130128

131-
const container = wrapper.children().first()
132-
expect(container[0].name).toEqual("container")
129+
expect(wrapper.get(0).name).toEqual("container")
133130

134-
const children = container.children()
131+
const children = wrapper.children()
135132
expect(children.length).toEqual(2)
136133
expect(children.eq(0).text()).toEqual("Original component")
137134
expect(children.eq(1).text()).toEqual("WOW much data")
@@ -182,10 +179,9 @@ describe("wrapComponents", () => {
182179
let Component = mySystem.getSystem().getComponents("wow")
183180
const wrapper = render(<Component name="Normal" />)
184181

185-
const container = wrapper.children().first()
186-
expect(container[0].name).toEqual("container")
182+
expect(wrapper.get(0).name).toEqual("container")
187183

188-
const children = container.children()
184+
const children = wrapper.children()
189185
expect(children.length).toEqual(2)
190186
expect(children.eq(0).text()).toEqual("Original component")
191187
expect(children.eq(1).text()).toEqual("WOW much data")
@@ -241,10 +237,9 @@ describe("wrapComponents", () => {
241237
let Component = mySystem.getSystem().getComponents("wow")
242238
const wrapper = render(<Component name="Normal" />)
243239

244-
const container2 = wrapper.children().first()
245-
expect(container2[0].name).toEqual("container2")
240+
expect(wrapper.get(0).name).toEqual("container2")
246241

247-
const children2 = container2.children()
242+
const children2 = wrapper.children()
248243
expect(children2.length).toEqual(2)
249244
expect(children2[0].name).toEqual("div")
250245
expect(children2.eq(0).text()).toEqual("Injected before")
@@ -302,10 +297,9 @@ describe("wrapComponents", () => {
302297
let Component = secondSystem.getSystem().getComponents("wow")
303298
const wrapper = render(<Component name="Normal" />)
304299

305-
const container = wrapper.children().first()
306-
expect(container[0].name).toEqual("container")
300+
expect(wrapper.get(0).name).toEqual("container")
307301

308-
const children = container.children()
302+
const children = wrapper.children()
309303
expect(children.length).toEqual(2)
310304
expect(children.eq(0).text()).toEqual("Original component")
311305
expect(children.eq(1).text()).toEqual("WOW much data")

test/unit/setup.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import win from "../../src/core/window"
2-
// import { configure } from "enzyme" // enzyme@3
3-
// import Adapter from "enzyme-adapter-react-15" // enzyme@3
41
import { JSDOM } from "jsdom"
2+
import Enzyme from "enzyme"
3+
import Adapter from "@wojtekmaj/enzyme-adapter-react-17"
4+
5+
import win from "../../src/core/window"
56

7+
Enzyme.configure({ adapter: new Adapter() })
68

79
function copyProps(src, target) {
810
const props = Object.getOwnPropertyNames(src)

test/unit/xss/anchor-target-rel/link.jsx

+7-9
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ describe("<Link/> Anchor Target Safety", function () {
1717
href: "http://google.com/"
1818
}
1919
let wrapper = render(<Link {...props} />)
20-
const anchor = wrapper.find("a")
2120

22-
expect(anchor.attr("href")).toEqual("http://google.com/")
23-
expect(anchor.attr("rel") || "").toMatch("noopener")
24-
expect(anchor.attr("rel") || "").toMatch("noreferrer")
21+
expect(wrapper.attr("href")).toEqual("http://google.com/")
22+
expect(wrapper.attr("rel") || "").toMatch("noopener")
23+
expect(wrapper.attr("rel") || "").toMatch("noreferrer")
2524
})
2625

2726
it("enforces `noreferrer` and `noopener` on target=_blank links", function () {
@@ -31,11 +30,10 @@ describe("<Link/> Anchor Target Safety", function () {
3130
target: "_blank"
3231
}
3332
let wrapper = render(<Link {...props} />)
34-
const anchor = wrapper.find("a")
3533

36-
expect(anchor.attr("href")).toEqual("http://google.com/")
37-
expect(anchor.attr("target")).toEqual("_blank")
38-
expect(anchor.attr("rel") || "").toMatch("noopener")
39-
expect(anchor.attr("rel") || "").toMatch("noreferrer")
34+
expect(wrapper.attr("href")).toEqual("http://google.com/")
35+
expect(wrapper.attr("target")).toEqual("_blank")
36+
expect(wrapper.attr("rel") || "").toMatch("noopener")
37+
expect(wrapper.attr("rel") || "").toMatch("noreferrer")
4038
})
4139
})

0 commit comments

Comments
 (0)