|
| 1 | +import updateMeta from '../../root-mixins/updateMeta' |
| 2 | + |
| 3 | +describe('getMergedMetaTags', () => { |
| 4 | + function metaFaker (pageMeta = null, siteMeta = []) { |
| 5 | + return { |
| 6 | + $page: { |
| 7 | + frontmatter: { meta: pageMeta } |
| 8 | + }, |
| 9 | + $description: '$description', |
| 10 | + siteMeta: siteMeta |
| 11 | + } |
| 12 | + } |
| 13 | + |
| 14 | + test('empty', () => { |
| 15 | + const me = metaFaker() |
| 16 | + const sut = updateMeta.methods.getMergedMetaTags.bind(me) |
| 17 | + const actual = sut() |
| 18 | + expect(actual).toEqual([ |
| 19 | + { name: 'description', content: '$description' } |
| 20 | + ]) |
| 21 | + }) |
| 22 | + |
| 23 | + test('description in pageMeta, $description and siteMeta should use pageMeta', () => { |
| 24 | + const me = metaFaker([ |
| 25 | + { name: 'description', content: 'pageMeta' } |
| 26 | + ], [ |
| 27 | + { name: 'description', content: 'siteMeta' } |
| 28 | + ]) |
| 29 | + const sut = updateMeta.methods.getMergedMetaTags.bind(me) |
| 30 | + const actual = sut() |
| 31 | + expect(actual).toEqual([ |
| 32 | + { name: 'description', content: 'pageMeta' } |
| 33 | + ]) |
| 34 | + }) |
| 35 | + |
| 36 | + test('description in $description and siteMeta should use $description', () => { |
| 37 | + const me = metaFaker(null, [ |
| 38 | + { name: 'description', content: 'siteMeta' } |
| 39 | + ]) |
| 40 | + const sut = updateMeta.methods.getMergedMetaTags.bind(me) |
| 41 | + const actual = sut() |
| 42 | + expect(actual).toEqual([ |
| 43 | + { name: 'description', content: '$description' } |
| 44 | + ]) |
| 45 | + }) |
| 46 | + |
| 47 | + test('allow multiple article:tag', () => { |
| 48 | + const me = metaFaker([ |
| 49 | + { property: 'article:tag', content: 'tag1' }, |
| 50 | + { property: 'article:tag', content: 'tag2' }, |
| 51 | + { property: 'article:tag', content: 'tag3' } |
| 52 | + ], []) |
| 53 | + const sut = updateMeta.methods.getMergedMetaTags.bind(me) |
| 54 | + const actual = sut() |
| 55 | + expect(actual).toEqual([ |
| 56 | + { property: 'article:tag', content: 'tag1' }, |
| 57 | + { property: 'article:tag', content: 'tag2' }, |
| 58 | + { property: 'article:tag', content: 'tag3' }, |
| 59 | + { name: 'description', content: '$description' } |
| 60 | + ]) |
| 61 | + }) |
| 62 | + |
| 63 | + test('pageMeta order should not be changed', () => { |
| 64 | + const me = metaFaker([ |
| 65 | + { property: 'og:image', content: 'https://example.com/rock.jpg' }, |
| 66 | + { property: 'og:image:width', content: '300' }, |
| 67 | + { property: 'og:image:height', content: '300' }, |
| 68 | + { property: 'og:image', content: 'https://example.com/rock2.jpg' }, |
| 69 | + { property: 'og:image', content: 'https://example.com/rock3.jpg' }, |
| 70 | + { property: 'og:image:height', content: '1000' } |
| 71 | + ], []) |
| 72 | + const sut = updateMeta.methods.getMergedMetaTags.bind(me) |
| 73 | + const actual = sut() |
| 74 | + expect(actual).toEqual([ |
| 75 | + { property: 'og:image', content: 'https://example.com/rock.jpg' }, |
| 76 | + { property: 'og:image:width', content: '300' }, |
| 77 | + { property: 'og:image:height', content: '300' }, |
| 78 | + { property: 'og:image', content: 'https://example.com/rock2.jpg' }, |
| 79 | + { property: 'og:image', content: 'https://example.com/rock3.jpg' }, |
| 80 | + { property: 'og:image:height', content: '1000' }, |
| 81 | + { name: 'description', content: '$description' } |
| 82 | + ]) |
| 83 | + }) |
| 84 | + |
| 85 | + test('siteMeta with same meta identifier of pageMeta should be ignore', () => { |
| 86 | + const me = metaFaker([ |
| 87 | + { property: 'og:image', content: 'https://example.com/rock2.jpg' }, |
| 88 | + { property: 'og:image:width', content: '300' }, |
| 89 | + { property: 'og:image:height', content: '300' } |
| 90 | + ], [ |
| 91 | + { property: 'og:image', content: 'https://example.com/rock1.jpg' }, |
| 92 | + { property: 'og:image:width', content: '100' }, |
| 93 | + { property: 'og:image:height', content: '100' }, |
| 94 | + { property: 'og:site_name', content: 'siteMeta' } |
| 95 | + ]) |
| 96 | + const sut = updateMeta.methods.getMergedMetaTags.bind(me) |
| 97 | + const actual = sut() |
| 98 | + expect(actual).toEqual([ |
| 99 | + { property: 'og:image', content: 'https://example.com/rock2.jpg' }, |
| 100 | + { property: 'og:image:width', content: '300' }, |
| 101 | + { property: 'og:image:height', content: '300' }, |
| 102 | + { name: 'description', content: '$description' }, |
| 103 | + { property: 'og:site_name', content: 'siteMeta' } |
| 104 | + ]) |
| 105 | + }) |
| 106 | +}) |
0 commit comments