|
| 1 | +import cases from 'jest-in-case'; |
| 2 | + |
| 3 | +import plugin from '../../'; |
| 4 | +import { |
| 5 | + getHTML, |
| 6 | + getTestingPlaygroundIFrameSrc, |
| 7 | + shouldTransform, |
| 8 | +} from '../../transformers/TestingPlayground'; |
| 9 | + |
| 10 | +import { cache, getMarkdownASTForFile, parseASTToMarkdown } from '../helpers'; |
| 11 | + |
| 12 | +cases( |
| 13 | + 'url validation', |
| 14 | + ({ url, valid }) => { |
| 15 | + expect(shouldTransform(url)).toBe(valid); |
| 16 | + }, |
| 17 | + { |
| 18 | + 'non-Testing Playground url': { |
| 19 | + url: 'https://not-a-testing-playground-url.com', |
| 20 | + valid: false, |
| 21 | + }, |
| 22 | + "non-Testing Playground url ending with 'testing-playground.com'": { |
| 23 | + url: 'https://this-is-not-testing-playground.com', |
| 24 | + valid: false, |
| 25 | + }, |
| 26 | + "non-Testing Playground url ending with 'testing-playground.com' having '/gist/' path": { |
| 27 | + url: |
| 28 | + 'https://this-is-not-testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', |
| 29 | + valid: false, |
| 30 | + }, |
| 31 | + "non-Testing Playground url ending with 'testing-playground.com' and having '/embed/' path": { |
| 32 | + url: |
| 33 | + 'https://this-is-not-testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', |
| 34 | + valid: false, |
| 35 | + }, |
| 36 | + 'dnt policy page': { |
| 37 | + url: 'https://testing-playground.com/.well-known/dnt-policy.txt', |
| 38 | + valid: false, |
| 39 | + }, |
| 40 | + 'Playground embed url': { |
| 41 | + url: |
| 42 | + 'https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', |
| 43 | + valid: false, |
| 44 | + }, |
| 45 | + 'Testing Playground homepage': { |
| 46 | + url: 'https://testing-playground.com', |
| 47 | + valid: true, |
| 48 | + }, |
| 49 | + 'Playground url': { |
| 50 | + url: |
| 51 | + 'https://testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', |
| 52 | + valid: true, |
| 53 | + }, |
| 54 | + "Playground url having 'www' subdomain": { |
| 55 | + url: |
| 56 | + 'https://www.testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', |
| 57 | + valid: true, |
| 58 | + }, |
| 59 | + } |
| 60 | +); |
| 61 | + |
| 62 | +cases( |
| 63 | + 'getTestingPlaygroundIFrameSrc', |
| 64 | + ({ url, iframe }) => { |
| 65 | + expect(getTestingPlaygroundIFrameSrc(url)).toBe(iframe); |
| 66 | + }, |
| 67 | + { |
| 68 | + 'Testing Playground homepage': { |
| 69 | + url: 'https://testing-playground.com', |
| 70 | + iframe: `https://testing-playground.com/embed?panes=query,preview`, |
| 71 | + }, |
| 72 | + 'Playground url': { |
| 73 | + url: |
| 74 | + 'https://testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', |
| 75 | + iframe: `https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a?panes=query,preview`, |
| 76 | + }, |
| 77 | + "Playground url having 'www' subdomain": { |
| 78 | + url: |
| 79 | + 'https://www.testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a', |
| 80 | + iframe: `https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a?panes=query,preview`, |
| 81 | + }, |
| 82 | + } |
| 83 | +); |
| 84 | + |
| 85 | +test('Gets the correct Testing Playground iframe', () => { |
| 86 | + const html = getHTML( |
| 87 | + 'https://testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a' |
| 88 | + ); |
| 89 | + |
| 90 | + expect(html).toMatchInlineSnapshot( |
| 91 | + `"<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>"` |
| 92 | + ); |
| 93 | +}); |
| 94 | + |
| 95 | +test('Plugin can transform Testing Playground links', async () => { |
| 96 | + const markdownAST = getMarkdownASTForFile('TestingPlayground'); |
| 97 | + |
| 98 | + const processedAST = await plugin({ cache, markdownAST }); |
| 99 | + |
| 100 | + expect(parseASTToMarkdown(processedAST)).toMatchInlineSnapshot(` |
| 101 | + "<https://not-a-testing-playground-url.com> |
| 102 | +
|
| 103 | + <https://this-is-not-testing-playground.com> |
| 104 | +
|
| 105 | + <https://this-is-not-testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a> |
| 106 | +
|
| 107 | + <https://this-is-not-testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a> |
| 108 | +
|
| 109 | + <https://testing-playground.com/.well-known/dnt-policy.txt> |
| 110 | +
|
| 111 | + <https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a> |
| 112 | +
|
| 113 | + <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> |
| 114 | +
|
| 115 | + <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> |
| 116 | +
|
| 117 | + <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> |
| 118 | + " |
| 119 | + `); |
| 120 | +}); |
0 commit comments