-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#98] Add tests for various node parsers
- Loading branch information
1 parent
3699c36
commit e234cba
Showing
20 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"osrs-web-scraper": patch | ||
--- | ||
|
||
Add tests for various node parsers. |
3 changes: 3 additions & 0 deletions
3
src/scrapers/news/sections/newsContent/nodes/__tests__/__snapshots__/bold.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`bold node Bold text should parse and render 1`] = `"'''test'''"`; |
7 changes: 7 additions & 0 deletions
7
src/scrapers/news/sections/newsContent/nodes/__tests__/__snapshots__/details.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`summary node summary elements should parse and render 1`] = ` | ||
"{{Collapsed section|18|test}} | ||
'''test'''{{Collapsed section end}} | ||
" | ||
`; |
6 changes: 6 additions & 0 deletions
6
src/scrapers/news/sections/newsContent/nodes/__tests__/__snapshots__/div.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`div node poll-box class should parse and render 1`] = ` | ||
"{{News Poll|1|If While Guthix Sleeps is added to the game, should we continue to explore the idea of offering the Rites of Balance as a rewards from the quest? This question is for developer consideration and not binding.}} | ||
" | ||
`; |
5 changes: 5 additions & 0 deletions
5
src/scrapers/news/sections/newsContent/nodes/__tests__/__snapshots__/font.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`font node Font node should parse and render a 2-level header 1`] = `"==test=="`; | ||
|
||
exports[`font node Font node should parse and render a 3-level header 1`] = `"===test==="`; |
3 changes: 3 additions & 0 deletions
3
src/scrapers/news/sections/newsContent/nodes/__tests__/__snapshots__/italics.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`italics node Italic text should parse and render 1`] = `"''test''"`; |
3 changes: 3 additions & 0 deletions
3
src/scrapers/news/sections/newsContent/nodes/__tests__/__snapshots__/link.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`link node Links should parse and render 1`] = `"[link test]"`; |
8 changes: 8 additions & 0 deletions
8
src/scrapers/news/sections/newsContent/nodes/__tests__/__snapshots__/list.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`list node list should parse and render 1`] = ` | ||
" | ||
* test1 | ||
* test2 | ||
" | ||
`; |
6 changes: 6 additions & 0 deletions
6
src/scrapers/news/sections/newsContent/nodes/__tests__/__snapshots__/paragraph.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`p node Paragraph should parse and render 1`] = ` | ||
"'''test''' | ||
" | ||
`; |
3 changes: 3 additions & 0 deletions
3
src/scrapers/news/sections/newsContent/nodes/__tests__/__snapshots__/underline.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`underline node Underlined text should parse and render 1`] = `"'''test'''"`; |
13 changes: 13 additions & 0 deletions
13
src/scrapers/news/sections/newsContent/nodes/__tests__/bold.test.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MediaWikiBuilder } from "@osrs-wiki/mediawiki-builder"; | ||
import parse from "node-html-parser"; | ||
|
||
import boldParser from "../bold"; | ||
|
||
describe("bold node", () => { | ||
test("Bold text should parse and render", () => { | ||
const root = parse("<b>test</b>"); | ||
const builder = new MediaWikiBuilder(); | ||
builder.addContents([boldParser(root.firstChild)].flat()); | ||
expect(builder.build()).toMatchSnapshot(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/scrapers/news/sections/newsContent/nodes/__tests__/details.test.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MediaWikiBuilder } from "@osrs-wiki/mediawiki-builder"; | ||
import parse from "node-html-parser"; | ||
|
||
import detailsParser from "../details"; | ||
|
||
describe("summary node", () => { | ||
test("summary elements should parse and render", () => { | ||
const root = parse("<details><summary>test</summary><b>test</b></details>"); | ||
const builder = new MediaWikiBuilder(); | ||
builder.addContents([detailsParser(root.firstChild)].flat()); | ||
expect(builder.build()).toMatchSnapshot(); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
src/scrapers/news/sections/newsContent/nodes/__tests__/div.test.ts
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MediaWikiBuilder } from "@osrs-wiki/mediawiki-builder"; | ||
import parse from "node-html-parser"; | ||
|
||
import divParser from "../div"; | ||
|
||
describe("div node", () => { | ||
test("poll-box class should parse and render", () => { | ||
const root = parse( | ||
"<div class='poll-box'><p>Question #X:</p><p><b>If While Guthix Sleeps is added to the game, should we continue to explore the idea of offering the Rites of Balance as a rewards from the quest? This question is for developer consideration and not binding.</b></p></div>" | ||
); | ||
const builder = new MediaWikiBuilder(); | ||
builder.addContents([divParser(root.firstChild)].flat()); | ||
expect(builder.build()).toMatchSnapshot(); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
src/scrapers/news/sections/newsContent/nodes/__tests__/font.test.ts
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { MediaWikiBuilder } from "@osrs-wiki/mediawiki-builder"; | ||
import parse from "node-html-parser"; | ||
|
||
import fontParser from "../font"; | ||
|
||
describe("font node", () => { | ||
test("Font node should parse and render a 2-level header", () => { | ||
const root = parse( | ||
'<font style="font-family:Cinzel,serif;font-size:22px;font-weight:bold;color:#FFFFFF;text-shadow:1px 1px #121212;">test</font>' | ||
); | ||
const builder = new MediaWikiBuilder(); | ||
builder.addContents([fontParser(root.firstChild)].flat()); | ||
expect(builder.build()).toMatchSnapshot(); | ||
}); | ||
|
||
test("Font node should parse and render a 3-level header", () => { | ||
const root = parse( | ||
'<font style="font-size:18px;font-weight:bold;color:#000000;">test</font>' | ||
); | ||
const builder = new MediaWikiBuilder(); | ||
builder.addContents([fontParser(root.firstChild)].flat()); | ||
expect(builder.build()).toMatchSnapshot(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/scrapers/news/sections/newsContent/nodes/__tests__/italics.test.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MediaWikiBuilder } from "@osrs-wiki/mediawiki-builder"; | ||
import parse from "node-html-parser"; | ||
|
||
import italicsParser from "../italics"; | ||
|
||
describe("italics node", () => { | ||
test("Italic text should parse and render", () => { | ||
const root = parse("<b>test</b>"); | ||
const builder = new MediaWikiBuilder(); | ||
builder.addContents([italicsParser(root.firstChild)].flat()); | ||
expect(builder.build()).toMatchSnapshot(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/scrapers/news/sections/newsContent/nodes/__tests__/link.test.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MediaWikiBuilder } from "@osrs-wiki/mediawiki-builder"; | ||
import parse from "node-html-parser"; | ||
|
||
import linkParser from "../link"; | ||
|
||
describe("link node", () => { | ||
test("Links should parse and render", () => { | ||
const root = parse("<a href='link'>test</a>"); | ||
const builder = new MediaWikiBuilder(); | ||
builder.addContents([linkParser(root.firstChild)].flat()); | ||
expect(builder.build()).toMatchSnapshot(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/scrapers/news/sections/newsContent/nodes/__tests__/list.test.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MediaWikiBuilder } from "@osrs-wiki/mediawiki-builder"; | ||
import parse from "node-html-parser"; | ||
|
||
import listParser from "../list"; | ||
|
||
describe("list node", () => { | ||
test("list should parse and render", () => { | ||
const root = parse("<ul><li>test1</li><li>test2</li></ul>"); | ||
const builder = new MediaWikiBuilder(); | ||
builder.addContents([listParser(root.firstChild)].flat()); | ||
expect(builder.build()).toMatchSnapshot(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/scrapers/news/sections/newsContent/nodes/__tests__/paragraph.test.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MediaWikiBuilder } from "@osrs-wiki/mediawiki-builder"; | ||
import parse from "node-html-parser"; | ||
|
||
import paragraphParser from "../paragraph"; | ||
|
||
describe("p node", () => { | ||
test("Paragraph should parse and render", () => { | ||
const root = parse("<p><b>test</b></p>"); | ||
const builder = new MediaWikiBuilder(); | ||
builder.addContents([paragraphParser(root.firstChild)].flat()); | ||
expect(builder.build()).toMatchSnapshot(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/scrapers/news/sections/newsContent/nodes/__tests__/underline.test.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MediaWikiBuilder } from "@osrs-wiki/mediawiki-builder"; | ||
import parse from "node-html-parser"; | ||
|
||
import boldParser from "../bold"; | ||
|
||
describe("underline node", () => { | ||
test("Underlined text should parse and render", () => { | ||
const root = parse("<u>test</u>"); | ||
const builder = new MediaWikiBuilder(); | ||
builder.addContents([boldParser(root.firstChild)].flat()); | ||
expect(builder.build()).toMatchSnapshot(); | ||
}); | ||
}); |
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