-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Testing Playground): Add support for Testing Playground (#124)
- Loading branch information
1 parent
3c307f0
commit 334933f
Showing
8 changed files
with
205 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
"soundcloud", | ||
"spotify", | ||
"streamable", | ||
"testing playground", | ||
"twitch", | ||
"twitter", | ||
"youtube" | ||
|
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,120 @@ | ||
import cases from 'jest-in-case'; | ||
|
||
import plugin from '../../'; | ||
import { | ||
getHTML, | ||
getTestingPlaygroundIFrameSrc, | ||
shouldTransform, | ||
} from '../../transformers/TestingPlayground'; | ||
|
||
import { cache, getMarkdownASTForFile, parseASTToMarkdown } from '../helpers'; | ||
|
||
cases( | ||
'url validation', | ||
({ url, valid }) => { | ||
expect(shouldTransform(url)).toBe(valid); | ||
}, | ||
{ | ||
'non-Testing Playground url': { | ||
url: 'https://not-a-testing-playground-url.com', | ||
valid: false, | ||
}, | ||
"non-Testing Playground url ending with 'testing-playground.com'": { | ||
url: 'https://this-is-not-testing-playground.com', | ||
valid: false, | ||
}, | ||
"non-Testing Playground url ending with 'testing-playground.com' having '/gist/' path": { | ||
url: | ||
'https://this-is-not-testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', | ||
valid: false, | ||
}, | ||
"non-Testing Playground url ending with 'testing-playground.com' and having '/embed/' path": { | ||
url: | ||
'https://this-is-not-testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', | ||
valid: false, | ||
}, | ||
'dnt policy page': { | ||
url: 'https://testing-playground.com/.well-known/dnt-policy.txt', | ||
valid: false, | ||
}, | ||
'Playground embed url': { | ||
url: | ||
'https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', | ||
valid: false, | ||
}, | ||
'Testing Playground homepage': { | ||
url: 'https://testing-playground.com', | ||
valid: true, | ||
}, | ||
'Playground url': { | ||
url: | ||
'https://testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', | ||
valid: true, | ||
}, | ||
"Playground url having 'www' subdomain": { | ||
url: | ||
'https://www.testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', | ||
valid: true, | ||
}, | ||
} | ||
); | ||
|
||
cases( | ||
'getTestingPlaygroundIFrameSrc', | ||
({ url, iframe }) => { | ||
expect(getTestingPlaygroundIFrameSrc(url)).toBe(iframe); | ||
}, | ||
{ | ||
'Testing Playground homepage': { | ||
url: 'https://testing-playground.com', | ||
iframe: `https://testing-playground.com/embed?panes=query,preview`, | ||
}, | ||
'Playground url': { | ||
url: | ||
'https://testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', | ||
iframe: `https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a?panes=query,preview`, | ||
}, | ||
"Playground url having 'www' subdomain": { | ||
url: | ||
'https://www.testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', | ||
iframe: `https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a?panes=query,preview`, | ||
}, | ||
} | ||
); | ||
|
||
test('Gets the correct Testing Playground iframe', () => { | ||
const html = getHTML( | ||
'https://testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a' | ||
); | ||
|
||
expect(html).toMatchInlineSnapshot( | ||
`"<iframe src=\\"https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a?panes=query,preview\\" height=\\"450\\" width=\\"100%\\" scrolling=\\"no\\" frameBorder=\\"0\\" allowTransparency=\\"true\\" style=\\"overflow: hidden; display: block; width: 100%\\"></iframe>"` | ||
); | ||
}); | ||
|
||
test('Plugin can transform Testing Playground links', async () => { | ||
const markdownAST = getMarkdownASTForFile('TestingPlayground'); | ||
|
||
const processedAST = await plugin({ cache, markdownAST }); | ||
|
||
expect(parseASTToMarkdown(processedAST)).toMatchInlineSnapshot(` | ||
"<https://not-a-testing-playground-url.com> | ||
<https://this-is-not-testing-playground.com> | ||
<https://this-is-not-testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a> | ||
<https://this-is-not-testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a> | ||
<https://testing-playground.com/.well-known/dnt-policy.txt> | ||
<https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a> | ||
<iframe src=\\"https://testing-playground.com/embed?panes=query,preview\\" height=\\"450\\" width=\\"100%\\" scrolling=\\"no\\" frameBorder=\\"0\\" allowTransparency=\\"true\\" style=\\"overflow: hidden; display: block; width: 100%\\"></iframe> | ||
<iframe src=\\"https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a?panes=query,preview\\" height=\\"450\\" width=\\"100%\\" scrolling=\\"no\\" frameBorder=\\"0\\" allowTransparency=\\"true\\" style=\\"overflow: hidden; display: block; width: 100%\\"></iframe> | ||
<iframe src=\\"https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a?panes=query,preview\\" height=\\"450\\" width=\\"100%\\" scrolling=\\"no\\" frameBorder=\\"0\\" allowTransparency=\\"true\\" style=\\"overflow: hidden; display: block; width: 100%\\"></iframe> | ||
" | ||
`); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/__tests__/transformers/__fixtures__/TestingPlayground.md
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,17 @@ | ||
https://not-a-testing-playground-url.com | ||
|
||
https://this-is-not-testing-playground.com | ||
|
||
https://this-is-not-testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a | ||
|
||
https://this-is-not-testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a | ||
|
||
https://testing-playground.com/.well-known/dnt-policy.txt | ||
|
||
https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a | ||
|
||
https://testing-playground.com | ||
|
||
https://testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a | ||
|
||
https://www.testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a |
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,25 @@ | ||
import { getTrimmedPathName } from './utils'; | ||
|
||
export const shouldTransform = (url) => { | ||
const { host, pathname } = new URL(url); | ||
const trimmedPathName = getTrimmedPathName(pathname); | ||
|
||
return ( | ||
['testing-playground.com', 'www.testing-playground.com'].includes(host) && | ||
(trimmedPathName.length === 0 || trimmedPathName.startsWith('gist/')) | ||
); | ||
}; | ||
|
||
export const getTestingPlaygroundIFrameSrc = (urlString) => { | ||
const { pathname } = new URL(urlString); | ||
const path = | ||
pathname === '/' ? '/embed' : pathname.replace('/gist/', '/embed/'); | ||
|
||
return `https://testing-playground.com${path}?panes=query,preview`; | ||
}; | ||
|
||
export const getHTML = (url) => { | ||
const iframeSrc = getTestingPlaygroundIFrameSrc(url); | ||
|
||
return `<iframe src="${iframeSrc}" height="450" width="100%" scrolling="no" frameBorder="0" allowTransparency="true" style="overflow: hidden; display: block; width: 100%"></iframe>`; | ||
}; |
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