Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Dec 23, 2020
1 parent f475578 commit c785b71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/assets/styles/amp-custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ $bg-color: #0cf;

body {
background: $bg-color;
font-family: Langar;
}
8 changes: 6 additions & 2 deletions example/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,19 @@
export default {
head () {
return {
title: 'AMP module for Nuxtjs'
title: 'AMP module for Nuxtjs',
link: [
{ rel: 'preconnecy', href: 'https://fonts.gstatic.com' },
{ hid: 'google-font', rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Langar&display=swap' }
]
}
}
}
</script>

<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-family: Langar, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
body > * {
margin: 0.5rem 0 0.5rem 0.5rem;
Expand Down
9 changes: 8 additions & 1 deletion test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ describe('Render AMP version of home page', () => {
const canonical = document.querySelector('[rel=canonical]').getAttribute('href')
const amphtml = document.querySelector('[rel=amphtml]')

const googleFont = document.querySelector('[data-hid="google-font"]').getAttribute('href')

const detectedTags = [...document.querySelectorAll('script[custom-element],script[custom-template]')]
.map(a => a.getAttribute('custom-element') || a.getAttribute('custom-template'))

return {
ampAttr,
detectedTags,
canonical,
amphtml
amphtml,
googleFont
}
})
source = await response.text()
Expand All @@ -102,6 +105,10 @@ describe('Render AMP version of home page', () => {
expect(info.canonical).toEqual(url(''))
})

test('Keep valid font providers links', () => {
expect(info.googleFont).toEqual('https://fonts.googleapis.com/css2?family=Langar&display=swap')
})

test('Detect all tags', () => {
const expected = ['amp-carousel', 'amp-list', 'amp-bind', 'amp-mustache']
expect(info.detectedTags).toEqual(expect.arrayContaining(expected))
Expand Down

0 comments on commit c785b71

Please # to comment.