|
| 1 | +import cases from 'jest-in-case'; |
| 2 | + |
| 3 | +import plugin from '../..'; |
| 4 | +import { getHTML, shouldTransform } from '../../transformers/Pinterest'; |
| 5 | + |
| 6 | +import { cache, getMarkdownASTForFile, parseASTToMarkdown } from '../helpers'; |
| 7 | + |
| 8 | +cases( |
| 9 | + 'url validation', |
| 10 | + ({ url, valid }) => { |
| 11 | + expect(shouldTransform(url)).toBe(valid); |
| 12 | + }, |
| 13 | + { |
| 14 | + 'non-Pinterest url': { |
| 15 | + url: 'https://not-a-pinterest-url.com', |
| 16 | + valid: false, |
| 17 | + }, |
| 18 | + "non-Pinterest url ending with 'pinterest.com'": { |
| 19 | + url: 'https://this-is-not-pinterest.com', |
| 20 | + valid: false, |
| 21 | + }, |
| 22 | + "non-Pinterest url ending with 'pinterest.com' and having '/pin/' in the url": { |
| 23 | + url: 'https://this-is-not-pinterest.com/pin/99360735500167749', |
| 24 | + valid: false, |
| 25 | + }, |
| 26 | + 'board url': { |
| 27 | + url: 'https://pinterest.com/pinterest/official-news', |
| 28 | + valid: true, |
| 29 | + }, |
| 30 | + "board url having 'www' subdomain": { |
| 31 | + url: 'https://www.pinterest.com/pinterest/official-news', |
| 32 | + valid: true, |
| 33 | + }, |
| 34 | + 'pin url': { |
| 35 | + url: 'https://pinterest.com/pin/99360735500167749', |
| 36 | + valid: true, |
| 37 | + }, |
| 38 | + "pin url having 'www' subdomain": { |
| 39 | + url: 'https://www.pinterest.com/pin/99360735500167749', |
| 40 | + valid: true, |
| 41 | + }, |
| 42 | + 'profile url': { |
| 43 | + url: 'https://pinterest.com/pinterest', |
| 44 | + valid: true, |
| 45 | + }, |
| 46 | + "profile url having 'www' subdomain": { |
| 47 | + url: 'https://www.pinterest.com/pinterest', |
| 48 | + valid: true, |
| 49 | + }, |
| 50 | + } |
| 51 | +); |
| 52 | + |
| 53 | +test('Gets the correct Pinterest board link', () => { |
| 54 | + const html = getHTML('https://pinterest.com/pinterest/official-news'); |
| 55 | + |
| 56 | + expect(html).toMatchInlineSnapshot( |
| 57 | + `"<a data-pin-do=\\"embedBoard\\" data-pin-board-width=\\"400\\" data-pin-scale-height=\\"240\\" data-pin-scale-width=\\"80\\" href=\\"https://pinterest.com/pinterest/official-news\\"></a>"` |
| 58 | + ); |
| 59 | +}); |
| 60 | + |
| 61 | +test('Gets the correct Pinterest pin link', () => { |
| 62 | + const html = getHTML('https://pinterest.com/pin/99360735500167749'); |
| 63 | + |
| 64 | + expect(html).toMatchInlineSnapshot( |
| 65 | + `"<a data-pin-do=\\"embedPin\\" href=\\"https://pinterest.com/pin/99360735500167749\\"></a>"` |
| 66 | + ); |
| 67 | +}); |
| 68 | + |
| 69 | +test('Gets the correct Pinterest profile link', () => { |
| 70 | + const html = getHTML('https://pinterest.com/pinterest'); |
| 71 | + |
| 72 | + expect(html).toMatchInlineSnapshot( |
| 73 | + `"<a data-pin-do=\\"embedUser\\" data-pin-board-width=\\"400\\" data-pin-scale-height=\\"240\\" data-pin-scale-width=\\"80\\" href=\\"https://pinterest.com/pinterest\\"></a>"` |
| 74 | + ); |
| 75 | +}); |
| 76 | + |
| 77 | +test('Plugin can transform Pinterest links', async () => { |
| 78 | + const markdownAST = getMarkdownASTForFile('Pinterest'); |
| 79 | + |
| 80 | + const processedAST = await plugin({ cache, markdownAST }); |
| 81 | + |
| 82 | + expect(parseASTToMarkdown(processedAST)).toMatchInlineSnapshot(` |
| 83 | + "<https://not-a-pinterest-url.com> |
| 84 | +
|
| 85 | + <https://this-is-not-pinterest.com> |
| 86 | +
|
| 87 | + <https://this-is-not-pinterest.com/pin/99360735500167749> |
| 88 | +
|
| 89 | + <a data-pin-do=\\"embedBoard\\" data-pin-board-width=\\"400\\" data-pin-scale-height=\\"240\\" data-pin-scale-width=\\"80\\" href=\\"https://pinterest.com/pinterest/official-news\\"></a> |
| 90 | +
|
| 91 | + <a data-pin-do=\\"embedBoard\\" data-pin-board-width=\\"400\\" data-pin-scale-height=\\"240\\" data-pin-scale-width=\\"80\\" href=\\"https://www.pinterest.com/pinterest/official-news\\"></a> |
| 92 | +
|
| 93 | + <a data-pin-do=\\"embedPin\\" href=\\"https://pinterest.com/pin/99360735500167749\\"></a> |
| 94 | +
|
| 95 | + <a data-pin-do=\\"embedPin\\" href=\\"https://www.pinterest.com/pin/99360735500167749\\"></a> |
| 96 | +
|
| 97 | + <a data-pin-do=\\"embedUser\\" data-pin-board-width=\\"400\\" data-pin-scale-height=\\"240\\" data-pin-scale-width=\\"80\\" href=\\"https://pinterest.com/pinterest\\"></a> |
| 98 | +
|
| 99 | + <a data-pin-do=\\"embedUser\\" data-pin-board-width=\\"400\\" data-pin-scale-height=\\"240\\" data-pin-scale-width=\\"80\\" href=\\"https://www.pinterest.com/pinterest\\"></a> |
| 100 | + " |
| 101 | + `); |
| 102 | +}); |
0 commit comments