-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[THEMES-968] Updated Article body block test cases to react-testing-l…
…ibrary (#2130) Updated testcases to react-testing-library Co-authored-by: Malavika Koppula <[email protected]>
- Loading branch information
1 parent
ab6ca04
commit 0e48887
Showing
10 changed files
with
3,020 additions
and
2,944 deletions.
There are no files selected for viewing
97 changes: 47 additions & 50 deletions
97
blocks/article-body-block/chains/article-body/_children/heading.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,52 @@ | ||
describe("This test is disabled", () => { | ||
it("should succeed", () => { | ||
expect(true); | ||
}); | ||
}); | ||
|
||
// import React from "react"; | ||
// import { mount } from "enzyme"; | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
|
||
// import Heading from "./heading"; | ||
import Heading from "./heading"; | ||
|
||
// describe("the article body Heading component", () => { | ||
// it("should render the correct heading", () => { | ||
// const headingData = { | ||
// _id: "CF5ARXXK6BHJ5LO45DZCCBHL7U", | ||
// type: "header", | ||
// level: 3, | ||
// additional_properties: { | ||
// comments: [], | ||
// inline_comments: [], | ||
// _id: 1563473120776, | ||
// }, | ||
// content: | ||
// 'Heading 3 - <b>bold</b> <i>italic</i> <u>underline</u> <a href="https://www.washingtonpost.com/" target=_blank>hyperlink</a>', | ||
// }; | ||
describe("the article body Heading component", () => { | ||
it("should render the correct heading", () => { | ||
const headingData = { | ||
_id: "CF5ARXXK6BHJ5LO45DZCCBHL7U", | ||
type: "header", | ||
level: 3, | ||
additional_properties: { | ||
comments: [], | ||
inline_comments: [], | ||
_id: 1563473120776, | ||
}, | ||
content: | ||
'Heading 3 - <b>bold</b> <i>italic</i> <u>underline</u> <a href="https://www.washingtonpost.com/" target=_blank>hyperlink</a>', | ||
}; | ||
|
||
// const wrapper = mount(<Heading element={headingData} />); | ||
// expect(wrapper.find("h3").length).toBe(1); | ||
// expect(wrapper.find("h3").text()).toMatch("Heading 3 - bold italic underline hyperlink"); | ||
// expect(wrapper.find("h3").html()).toMatchInlineSnapshot( | ||
// `"<h3>Heading 3 - <b>bold</b> <i>italic</i> <u>underline</u> <a href=\\"https://www.washingtonpost.com/\\" target=\\"_blank\\">hyperlink</a></h3>"` | ||
// ); | ||
// }); | ||
render(<Heading element={headingData} />); | ||
const heading = screen.getByRole('heading', { level: 3 }); | ||
expect(heading).toBeInTheDocument(); | ||
expect(heading.textContent).toMatch('Heading 3 - bold italic underline hyperlink'); | ||
expect(heading.innerHTML).toMatchInlineSnapshot( | ||
`"Heading 3 - <b>bold</b> <i>italic</i> <u>underline</u> <a href="https://www.washingtonpost.com/" target="_blank">hyperlink</a>"` | ||
); | ||
}); | ||
|
||
// it("should default to h2 if no heading level is given", () => { | ||
// const headingData = { | ||
// _id: "CF5ARXXK6BHJ5LO45DZCCBHL7U", | ||
// type: "header", | ||
// additional_properties: { | ||
// comments: [], | ||
// inline_comments: [], | ||
// _id: 1563473120776, | ||
// }, | ||
// content: | ||
// 'Heading 3 - <b>bold</b> <i>italic</i> <u>underline</u> <a href="https://www.washingtonpost.com/" target=_blank>hyperlink</a>', | ||
// }; | ||
it("should default to h2 if no heading level is given", () => { | ||
const headingData = { | ||
_id: "CF5ARXXK6BHJ5LO45DZCCBHL7U", | ||
type: "header", | ||
additional_properties: { | ||
comments: [], | ||
inline_comments: [], | ||
_id: 1563473120776, | ||
}, | ||
content: | ||
'Heading 3 - <b>bold</b> <i>italic</i> <u>underline</u> <a href="https://www.washingtonpost.com/" target=_blank>hyperlink</a>', | ||
}; | ||
|
||
// const wrapper = mount(<Heading element={headingData} />); | ||
// expect(wrapper.find("h2").length).toBe(1); | ||
// expect(wrapper.find("h2").html()).toMatchInlineSnapshot( | ||
// `"<h2>Heading 3 - <b>bold</b> <i>italic</i> <u>underline</u> <a href=\\"https://www.washingtonpost.com/\\" target=\\"_blank\\">hyperlink</a></h2>"` | ||
// ); | ||
// expect(wrapper.find("h2").text()).toMatch("Heading 3 - bold italic underline hyperlink"); | ||
// }); | ||
// }); | ||
render(<Heading element={headingData} />); | ||
const heading = screen.getByRole('heading', { level: 2 }); | ||
expect(heading).toBeInTheDocument(); | ||
expect(heading.textContent).toMatch('Heading 3 - bold italic underline hyperlink'); | ||
expect(heading.innerHTML).toMatchInlineSnapshot( | ||
`"Heading 3 - <b>bold</b> <i>italic</i> <u>underline</u> <a href="https://www.washingtonpost.com/" target="_blank">hyperlink</a>"` | ||
); | ||
}); | ||
}); |
49 changes: 22 additions & 27 deletions
49
blocks/article-body-block/chains/article-body/_children/html.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,26 @@ | ||
describe("This test is disabled", () => { | ||
it("should succeed", () => { | ||
expect(true); | ||
}); | ||
}); | ||
|
||
// import React from "react"; | ||
// import { mount } from "enzyme"; | ||
|
||
// import HTML from "./html"; | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
|
||
// describe("the article body raw_html component", () => { | ||
// it("should not render raw_html when it is not provided with the necessary data", () => { | ||
// const rawHTML = { | ||
// _id: "44CZ46VGIBBOZAZH4OXB4ND4U4", | ||
// }; | ||
import HTML from "./html"; | ||
|
||
// const wrapper = mount(<HTML id={rawHTML._id} content={rawHTML.content} />); | ||
// expect(wrapper.html()).toBe(null); | ||
// }); | ||
describe("the article body raw_html component", () => { | ||
it("should not render raw_html when it is not provided with the necessary data", () => { | ||
const rawHTML = { | ||
_id: "44CZ46VGIBBOZAZH4OXB4ND4U4", | ||
}; | ||
|
||
// it("should render raw_html when it is provided with the necessary data", () => { | ||
// const rawHTML = { | ||
// _id: "44CZ46VGIBBOZAZH4OXB4ND4U4", | ||
// content: "<p>Some HTML</p>", | ||
// }; | ||
render(<HTML id={rawHTML._id} content={rawHTML.content} />); | ||
expect(screen.innerHTML).toBe(); | ||
}); | ||
|
||
// const wrapper = mount(<HTML id={rawHTML._id} content={rawHTML.content} />); | ||
// expect(wrapper.html()).toMatch(rawHTML.content); | ||
// }); | ||
// }); | ||
it("should render raw_html when it is provided with the necessary data", () => { | ||
const rawHTML = { | ||
_id: "44CZ46VGIBBOZAZH4OXB4ND4U4", | ||
content: "<p>Some HTML</p>", | ||
}; | ||
render(<HTML id={rawHTML._id} content={rawHTML.content} />); | ||
const element = screen.getByText('Some HTML'); | ||
expect(element).toBeInTheDocument(); | ||
}); | ||
}); |
207 changes: 99 additions & 108 deletions
207
blocks/article-body-block/chains/article-body/_children/list.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,107 @@ | ||
describe("This test is disabled", () => { | ||
it("should succeed", () => { | ||
expect(true); | ||
}); | ||
}); | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import List from "./list"; | ||
|
||
// import React from "react"; | ||
// import { mount } from "enzyme"; | ||
describe("the article body List component", () => { | ||
it("should render unordered list correctly", () => { | ||
const listContent = { | ||
type: "list", | ||
list_type: "unordered", | ||
items: [ | ||
{ | ||
type: "text", | ||
content: "Indented under 2", | ||
_id: "IOY3SN76GVFI3MUDN3PX4V32AA", | ||
}, | ||
{ | ||
type: "text", | ||
content: "Another thing indented under 2", | ||
_id: "MX643WWQPZCYZHTZYMHCIML6SU", | ||
}, | ||
], | ||
_id: "PSQTOBXAGZGKNOSBMOAUJ6EYSA", | ||
}; | ||
|
||
// import List from "./list"; | ||
render(<List listType={listContent.list_type} listItems={listContent.items} />); | ||
|
||
// describe("the article body List component", () => { | ||
// it("should render unordered list correctly", () => { | ||
// const listContent = { | ||
// type: "list", | ||
// list_type: "unordered", | ||
// items: [ | ||
// { | ||
// type: "text", | ||
// content: "Indented under 2", | ||
// _id: "IOY3SN76GVFI3MUDN3PX4V32AA", | ||
// }, | ||
// { | ||
// type: "text", | ||
// content: "Another thing indented under 2", | ||
// _id: "MX643WWQPZCYZHTZYMHCIML6SU", | ||
// }, | ||
// ], | ||
// _id: "PSQTOBXAGZGKNOSBMOAUJ6EYSA", | ||
// }; | ||
const ul = screen.getByRole('list'); | ||
expect(ul).toBeInTheDocument(); | ||
|
||
const listItems = screen.getAllByRole('listitem'); | ||
expect(listItems).toHaveLength(2); | ||
expect(listItems[0].textContent).toBe('Indented under 2'); | ||
expect(listItems[1].textContent).toBe('Another thing indented under 2'); | ||
}); | ||
|
||
// const wrapper = mount(<List listType={listContent.list_type} listItems={listContent.items} />); | ||
// expect(wrapper.find("ul").length).toBe(1); | ||
// expect(wrapper.find("ul").childAt(0).html()).toMatchInlineSnapshot( | ||
// `"<li>Indented under 2</li>"` | ||
// ); | ||
// expect(wrapper.find("ul").childAt(1).html()).toMatchInlineSnapshot( | ||
// `"<li>Another thing indented under 2</li>"` | ||
// ); | ||
// }); | ||
it("should render ordered list correctly", () => { | ||
const listContent = { | ||
type: "list", | ||
list_type: "ordered", | ||
items: [ | ||
{ | ||
type: "text", | ||
content: "Indented under 2", | ||
_id: "OWQEXQT6N5BTPF2CDZYVND6IAQ", | ||
}, | ||
{ | ||
type: "text", | ||
content: "Another thing indented under 2", | ||
_id: "UG52XTXHHRDN5KUPKCGTKE4NMM", | ||
}, | ||
], | ||
_id: "FLXZDZLOFRGNLMALFGLJGLDPAM", | ||
}; | ||
|
||
// it("should render ordered list correctly", () => { | ||
// const listContent = { | ||
// type: "list", | ||
// list_type: "ordered", | ||
// items: [ | ||
// { | ||
// type: "text", | ||
// content: "Indented under 2", | ||
// _id: "OWQEXQT6N5BTPF2CDZYVND6IAQ", | ||
// }, | ||
// { | ||
// type: "text", | ||
// content: "Another thing indented under 2", | ||
// _id: "UG52XTXHHRDN5KUPKCGTKE4NMM", | ||
// }, | ||
// ], | ||
// _id: "FLXZDZLOFRGNLMALFGLJGLDPAM", | ||
// }; | ||
render(<List listType={listContent.list_type} listItems={listContent.items} />); | ||
const listItems = screen.getAllByRole('listitem'); | ||
|
||
// const wrapper = mount(<List listType={listContent.list_type} listItems={listContent.items} />); | ||
// expect(wrapper.find("ol").length).toBe(1); | ||
// expect(wrapper.find("ol").childAt(0).html()).toMatchInlineSnapshot( | ||
// `"<li>Indented under 2</li>"` | ||
// ); | ||
// expect(wrapper.find("ol").childAt(1).html()).toMatchInlineSnapshot( | ||
// `"<li>Another thing indented under 2</li>"` | ||
// ); | ||
// }); | ||
expect(listItems).toHaveLength(2); | ||
expect(listItems[0].textContent).toBe('Indented under 2'); | ||
expect(listItems[1].textContent).toBe('Another thing indented under 2'); | ||
}); | ||
|
||
// it("should render nested list correctly", () => { | ||
// const listContent = { | ||
// type: "list", | ||
// list_type: "ordered", | ||
// items: [ | ||
// { | ||
// type: "list", | ||
// list_type: "unordered", | ||
// items: [ | ||
// { | ||
// type: "text", | ||
// content: "Indented under 2", | ||
// _id: "IOY3SN76GVFI3MUDN3PX4V32AA", | ||
// }, | ||
// { | ||
// type: "text", | ||
// content: "Another thing indented under 2", | ||
// _id: "MX643WWQPZCYZHTZYMHCIML6SU", | ||
// }, | ||
// ], | ||
// _id: "PSQTOBXAGZGKNOSBMOAUJ6EYSA", | ||
// }, | ||
// { | ||
// type: "text", | ||
// content: "Another thing indented under 3", | ||
// _id: "UG52XTXHHRDN5KUPKCGTKE4NMM", | ||
// }, | ||
// ], | ||
// _id: "FLXZDZLOFRGNLMALFGLJGLDPAM", | ||
// }; | ||
it("should render nested list correctly", () => { | ||
const listContent = { | ||
type: "list", | ||
list_type: "ordered", | ||
items: [ | ||
{ | ||
type: "list", | ||
list_type: "unordered", | ||
items: [ | ||
{ | ||
type: "text", | ||
content: "Indented under 2", | ||
_id: "IOY3SN76GVFI3MUDN3PX4V32AA", | ||
}, | ||
{ | ||
type: "text", | ||
content: "Another thing indented under 2", | ||
_id: "MX643WWQPZCYZHTZYMHCIML6SU", | ||
}, | ||
], | ||
_id: "PSQTOBXAGZGKNOSBMOAUJ6EYSA", | ||
}, | ||
{ | ||
type: "text", | ||
content: "Another thing indented under 3", | ||
_id: "UG52XTXHHRDN5KUPKCGTKE4NMM", | ||
}, | ||
], | ||
_id: "FLXZDZLOFRGNLMALFGLJGLDPAM", | ||
}; | ||
|
||
// const wrapper = mount(<List listType={listContent.list_type} listItems={listContent.items} />); | ||
// expect(wrapper.find("ol").length).toBe(1); | ||
// expect(wrapper.children().find("ul").length).toBe(1); | ||
// expect(wrapper.children().find("li").length).toBe(3); | ||
// expect(wrapper.find("ul").childAt(0).html()).toMatchInlineSnapshot( | ||
// `"<li>Indented under 2</li>"` | ||
// ); | ||
// expect(wrapper.find("ul").childAt(1).html()).toMatchInlineSnapshot( | ||
// `"<li>Another thing indented under 2</li>"` | ||
// ); | ||
// expect(wrapper.find("ol").childAt(1).html()).toMatchInlineSnapshot( | ||
// `"<li>Another thing indented under 3</li>"` | ||
// ); | ||
// }); | ||
// }); | ||
render(<List listType={listContent.list_type} listItems={listContent.items} />); | ||
|
||
const listItems = screen.getAllByRole('listitem'); | ||
|
||
expect(listItems).toHaveLength(3); | ||
|
||
const [firstItem, secondItem, thirdItem] = listItems; | ||
|
||
expect(firstItem.textContent).toBe('Indented under 2'); | ||
expect(secondItem.textContent).toBe('Another thing indented under 2'); | ||
expect(thirdItem.textContent).toBe('Another thing indented under 3'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.