-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mobileHtml(), get mobile-optimised HTML
Returns HTML for mobile for a given page. resolving #14
- Loading branch information
1 parent
ba806cc
commit f4a156d
Showing
4 changed files
with
64 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
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
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,26 @@ | ||
import * as request from '../source/request'; | ||
import wiki from "../source/index"; | ||
import { htmlString, notFoundJson } from './samples'; | ||
const requestMock = jest.spyOn(request, "makeRestRequest"); | ||
|
||
afterAll(() => { | ||
requestMock.mockRestore(); | ||
}); | ||
|
||
test('Returns HTML when page successfully queried', async () => { | ||
requestMock.mockImplementation(async () => { return htmlString }); | ||
const result = await wiki.mobileHtml("ACID"); | ||
expect(result).toStrictEqual(htmlString); | ||
}); | ||
|
||
test('Returns notFound if page not found', async () => { | ||
requestMock.mockImplementation(async () => { return notFoundJson }); | ||
const result = await wiki.mobileHtml("does-not-exist-on-wikipedia"); | ||
expect(result).toEqual(notFoundJson); | ||
}); | ||
|
||
test('Returns empty body on redirect page with redirect set to false', async () => { | ||
requestMock.mockImplementation(async () => { return null }); | ||
const result = await wiki.mobileHtml("homestar", false); | ||
expect(result).toBeNull(); | ||
}); |
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