import { defaultOptions } from '../../src/shared/constants'
const metaInfoData = {
title: {
add: {
data: 'Hello World',
expect: ['
Hello World'],
test (side, defaultTest) {
if (side === 'client') {
// client side vue-meta uses document.title and doesnt change the html
return () => {
this.expect[0] = 'Hello World'
const spy = jest.spyOn(document, 'title', 'set')
defaultTest()
expect(spy).toHaveBeenCalledTimes(1)
expect(spy).toHaveBeenCalledWith('Hello World')
}
} else {
return defaultTest
}
}
}
},
base: {
add: {
data: [{ href: 'href' }],
expect: ['']
},
change: {
data: [{ href: 'href2' }],
expect: ['']
},
remove: {
data: [],
expect: ['']
}
},
meta: {
add: {
data: [{ charset: 'utf-8' }, { property: 'a', content: 'a' }],
expect: [
'',
''
]
},
change: {
data: [
{ charset: 'utf-16' },
{ property: 'a', content: 'b' }
],
expect: [
'',
''
]
},
// make sure elements that already exists are not unnecessarily updated
duplicate: {
data: [
{ charset: 'utf-16' },
{ property: 'a', content: 'c' }
],
expect: [
'',
''
],
test (side, defaultTest) {
if (side === 'client') {
return () => {
const tags = defaultTest()
expect(tags.addedTags.meta.length).toBe(1)
// TODO: not sure if we really expect this
expect(tags.removedTags.meta.length).toBe(1)
}
}
}
},
remove: {
data: [],
expect: ['']
}
},
link: {
add: {
data: [{ rel: 'stylesheet', href: 'href' }],
expect: ['']
},
change: {
data: [{ rel: 'stylesheet', href: 'href', media: 'screen' }],
expect: ['']
},
remove: {
data: [],
expect: ['']
}
},
style: {
add: {
data: [{ type: 'text/css', cssText: '.foo { color: red; }' }],
expect: ['']
},
change: {
data: [{ type: 'text/css', cssText: '.foo { color: blue; }' }],
expect: ['']
},
remove: {
data: [],
expect: ['']
}
},
script: {
add: {
data: [
{ src: 'src1', async: false, defer: true, [defaultOptions.tagIDKeyName]: 'content', callback: () => {} },
{ src: 'src-prepend', async: true, defer: false, pbody: true },
{ src: 'src2', async: false, defer: true, body: true },
{ src: 'src3', async: false, skip: true },
{ type: 'application/ld+json',
json: {
'@context': 'http://schema.org',
'@type': 'Organization',
'name': 'MyApp',
'url': 'https://www.myurl.com',
'logo': 'https://www.myurl.com/images/logo.png'
}
}
],
expect: [
'',
'',
'',
''
],
test (side, defaultTest) {
return () => {
if (side === 'client') {
for (const index in this.expect) {
this.expect[index] = this.expect[index].replace(/(async|defer)/g, '$1=""')
this.expect[index] = this.expect[index].replace(/ onload="this.__vm_l=1"/, '')
}
const tags = defaultTest()
expect(tags.addedTags.script[0].parentNode.tagName).toBe('HEAD')
expect(tags.addedTags.script[1].parentNode.tagName).toBe('BODY')
expect(tags.addedTags.script[2].parentNode.tagName).toBe('BODY')
} else {
// ssr doesnt generate data-body tags
const bodyPrepended = this.expect[1]
const bodyAppended = this.expect[2]
this.expect = [this.expect.shift(), this.expect.pop()]
const tags = defaultTest()
const html = tags.text()
expect(html).not.toContain(bodyPrepended)
expect(html).not.toContain(bodyAppended)
}
}
}
},
// this test only runs for client so we can directly expect wrong boolean attributes
change: {
data: [{ src: 'src', async: true, defer: true, [defaultOptions.tagIDKeyName]: 'content2' }],
expect: ['']
},
remove: {
data: [],
expect: ['']
}
},
noscript: {
add: {
data: [{ innerHTML: 'noscript
' }],
expect: ['']
},
change: {
data: [{ innerHTML: 'noscript, no really
' }],
expect: ['']
},
remove: {
data: [],
expect: ['']
}
},
htmlAttrs: {
add: {
data: { foo: 'bar' },
expect: ['']
},
change: {
data: { foo: 'baz' },
expect: ['']
},
remove: {
data: {},
expect: ['']
}
},
headAttrs: {
add: {
data: { foo: 'bar' },
expect: ['']
},
change: {
data: { foo: 'baz' },
expect: ['']
},
remove: {
data: {},
expect: ['']
}
},
bodyAttrs: {
add: {
data: { foo: 'bar', fizz: ['fuzz', 'fozz'] },
expect: ['']
},
change: {
data: { foo: 'baz' },
expect: ['']
},
remove: {
data: {},
expect: ['']
}
},
empty: {
add: {
data: [{}],
expect: [''],
test: side => side === 'server'
}
}
}
export default metaInfoData