Skip to content

Commit

Permalink
fix: fix e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Feb 2, 2024
1 parent 0f54d1a commit e63b561
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 174 deletions.
2 changes: 2 additions & 0 deletions e2e/docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import process from 'node:process'
import { viteBundler } from '@vuepress/bundler-vite'
import { webpackBundler } from '@vuepress/bundler-webpack'
import { copyrightPlugin } from '@vuepress/plugin-copyright'
import { feedPlugin } from '@vuepress/plugin-feed'
import { defaultTheme } from '@vuepress/theme-default'
import { defineUserConfig } from 'vuepress/cli'
Expand Down Expand Up @@ -84,6 +85,7 @@ export default defineUserConfig({
}),

plugins: [
copyrightPlugin({}),
feedPlugin({
hostname: 'https://ecosystem-e2e-test.com',
devServer: true,
Expand Down
6 changes: 6 additions & 0 deletions e2e/docs/copy-code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copy code

```ts
const a = 1
const b = 2
```
6 changes: 6 additions & 0 deletions e2e/docs/copyright/selection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
copy:
disableSelection: true
---

No selection
1 change: 1 addition & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@vuepress/bundler-vite": "2.0.0-rc.2",
"@vuepress/bundler-webpack": "2.0.0-rc.2",
"@vuepress/client": "2.0.0-rc.2",
"@vuepress/plugin-copyright": "workspace:*",
"@vuepress/plugin-feed": "workspace:*",
"@vuepress/theme-default": "workspace:*",
"sass": "^1.70.0",
Expand Down
19 changes: 13 additions & 6 deletions e2e/tests/plugin-copy-code/copy-code.cy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
describe('copy-code', () => {
it('have copy code button', () => {
cy.visit('/markdown.html')
.get('.copy-code-button')
.then((el) => {
expect(el.length).to.be.greaterThan(0)
cy.visit('/copy-code/')
.get('.theme-default-content')
.within(() => {
cy.get('.copy-code-button')
.should('have.lengthOf.greaterThan', 0)
.each((el) => {
cy.wrap(el).click()
cy.wrap(el).should('have.class', 'copied')
cy.window()
.then((win) => win.navigator.clipboard.readText())
.should('eq', `const a = 1\nconst b = 2\n`)

cy.wrap(el).click({ multiple: true })
cy.wrap(el).should('have.class', 'copied')
cy.window().then((win) => win.navigator.clipboard.writeText(''))
})
})
})
})
13 changes: 13 additions & 0 deletions e2e/tests/plugin-copyright/copyright.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe('copyright', () => {
it('disable selection', () => {
cy.visit('/')
.get('#app')
.should('have.length', 1)
.should('have.css', 'user-select', 'auto')

cy.visit('/copyright/selection.html')
.get('#app')
.should('have.length', 1)
.should('have.css', 'user-select', 'none')
})
})
114 changes: 61 additions & 53 deletions e2e/tests/plugin-feed/feed.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,84 @@ describe('feed', () => {
const BASE = Cypress.env('E2E_BASE')

it('have atom feed', () => {
cy.request(`${BASE}atom.xml`).then((res) => {
expect(res.body).to.be.a('string')
expect(res.body).to.contain('<?xml version="1.0"')
expect(res.body).to.contain('<strong>article excerpt</strong>')
})
cy.request(`${BASE}atom.xsl`).then((res) => {
expect(res.body).to.be.a('string')
expect(res.body).to.contain('<?xml version="1.0"')
})
cy.request(`${BASE}atom.xml`)
.its('body')
.should('be.a', 'string')
.and('contain', '<?xml version="1.0"')
.and('contain', '<strong>article excerpt</strong>')

cy.request(`${BASE}atom.xsl`)
.its('body')
.should('be.a', 'string')
.and('contain', '<?xml version="1.0"')
})

it('have json feed', () => {
cy.request(`${BASE}feed.json`).then((res) => {
expect(res.body).to.be.a('object')
expect(res.body).to.have.property(
'version',
'https://jsonfeed.org/version/1.1',
)
expect(JSON.stringify(res.body)).to.contain(
'<strong>article excerpt</strong>',
)
})
cy.request(`${BASE}feed.json`)
.its('body')
.should('be.a', 'object')
.and((json) => {
expect(JSON.stringify(json)).to.contain(
'<strong>article excerpt</strong>',
)
})
.and('have.a.property', 'version', 'https://jsonfeed.org/version/1.1')
})

it('have rss feed', () => {
cy.request(`${BASE}rss.xml`).then((res) => {
expect(res.body).to.be.a('string')
expect(res.body).to.contain('<?xml version="1.0"')
expect(res.body).to.contain('<strong>article excerpt</strong>')
})
cy.request(`${BASE}rss.xsl`).then((res) => {
expect(res.body).to.be.a('string')
expect(res.body).to.contain('<?xml version="1.0"')
})
cy.request(`${BASE}rss.xml`)
.its('body')
.should('be.a', 'string')
.and('contain', '<?xml version="1.0"')
.and('contain', '<strong>article excerpt</strong>')

cy.request(`${BASE}rss.xsl`)
.its('body')
.should('be.a', 'string')
.and('contain', '<?xml version="1.0"')
})

it('customize feed', () => {
cy.request(`${BASE}atom.xml`).then((res) => {
expect(res.body).to.contain('Custom feed title')
expect(res.body).to.contain('Custom feed content.')
})
cy.request(`${BASE}atom.xml`)
.its('body')
.should('be.a', 'string')
.and('contain', 'Custom feed title')
.and('contain', 'Custom feed content.')

cy.request(`${BASE}feed.json`).then((res) => {
const content = JSON.stringify(res.body)
cy.request(`${BASE}feed.json`)
.its('body')
.should('be.a', 'object')
.and((json) => {
const content = JSON.stringify(json)

expect(content).to.contain('Custom feed title')
expect(content).to.contain('Custom feed description')
expect(content).to.contain('Custom feed content.')
})
expect(content).to.contain('Custom feed title')
expect(content).to.contain('Custom feed description')
expect(content).to.contain('Custom feed content.')
})

cy.request(`${BASE}rss.xml`).then((res) => {
expect(res.body).to.contain('Custom feed title')
expect(res.body).to.contain('Custom feed description')
expect(res.body).to.contain('Custom feed content.')
})
cy.request(`${BASE}rss.xml`)
.its('body')
.should('be.a', 'string')
.and('contain', 'Custom feed title')
.and('contain', 'Custom feed description')
.and('contain', 'Custom feed content.')
})

it('exclude feed', () => {
cy.request(`${BASE}atom.xml`).then((res) => {
expect(res.body).to.not.contain('Excluded feed page content.')
})
cy.request(`${BASE}atom.xml`)
.its('body')
.should('not.contain', 'Excluded feed page content.')

cy.request(`${BASE}feed.json`).then((res) => {
const content = JSON.stringify(res.body)
cy.request(`${BASE}feed.json`)
.its('body')
.and((json) => {
const content = JSON.stringify(json)

expect(content).to.not.contain('Excluded feed page content.')
})
expect(content).to.not.contain('Excluded feed page content.')
})

cy.request(`${BASE}rss.xml`).then((res) => {
expect(res.body).to.not.contain('Excluded feed page content.')
})
cy.request(`${BASE}rss.xml`)
.its('body')
.should('not.contain', 'Excluded feed page content.')
})
})
107 changes: 49 additions & 58 deletions e2e/tests/plugin-seo/seo.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,60 @@ describe('seo', () => {
it('have OGP', () => {
cy.visit('/seo/')

cy.get('head meta[property="og:url"]').should(
'have.attr',
'content',
`https://ecosystem-e2e-test.com${BASE}seo/`,
)
cy.get('head meta[property="og:site_name"]').should(
'have.attr',
'content',
'VuePress Ecosystem E2E',
)
cy.get('head meta[property="og:title"]').should(
'have.attr',
'content',
'SEO Demo Page',
)
cy.get('head meta[property="og:description"]').should(
'have.attr',
'content',
'Here is article excerpt. Content alt Here is main content of article. A B C ',
)
cy.get('head meta[property="og:type"]').should(
'have.attr',
'content',
'article',
)
cy.get('head meta[property="og:locale"]').should(
'have.attr',
'content',
'en-US',
)
cy.get('head meta[property="article:author"]').should(
'have.attr',
'content',
'Mr.Hope',
)
cy.get('head meta[property="article:tag"]').should(
'have.attr',
'content',
'Demo',
)
cy.get('head meta[property="article:published_time"]').should(
'have.attr',
'content',
'2021-01-01T00:00:00.000Z',
)
.get('head meta[property="og:url"]')
.should(
'have.attr',
'content',
`https://ecosystem-e2e-test.com${BASE}seo/`,
)

.get('head meta[property="og:site_name"]')
.should('have.attr', 'content', 'VuePress Ecosystem E2E')

.get('head meta[property="og:title"]')
.should('have.attr', 'content', 'SEO Demo Page')

.get('head meta[property="og:description"]')
.should(
'have.attr',
'content',
'Here is article excerpt. Content alt Here is main content of article. A B C ',
)

.get('head meta[property="og:type"]')
.should('have.attr', 'content', 'article')

.get('head meta[property="og:locale"]')
.should('have.attr', 'content', 'en-US')

.get('head meta[property="article:author"]')
.should('have.attr', 'content', 'Mr.Hope')

.get('head meta[property="article:tag"]')
.should('have.attr', 'content', 'Demo')

.get('head meta[property="article:published_time"]')
.should('have.attr', 'content', '2021-01-01T00:00:00.000Z')
})

it('have JSONLD', () => {
cy.visit('/seo/')

cy.get('head script[type="application/ld+json"]').then((el) => {
const json = JSON.parse(el[0].innerText)
cy.get('head script[type="application/ld+json"]')
.should('have.length', 1)
.each((el) => {
const json = JSON.parse(el[0].innerText)

expect(json['@context']).to.equal('https://schema.org')
expect(json['@type']).to.equal('Article')
expect(json.headline).to.equal('SEO Demo Page')
expect(json.image).to.deep.equal([
`https://ecosystem-e2e-test.com${BASE}logo.png`,
])
expect(json.datePublished).to.equal('2021-01-01T00:00:00.000Z')
expect(json).to.has.property('dateModified')
expect(json.author[0]['@type']).to.equal('Person')
expect(json.author[0].name).to.equal('Mr.Hope')
})
expect(json['@context']).to.equal('https://schema.org')
expect(json['@type']).to.equal('Article')
expect(json.headline).to.equal('SEO Demo Page')
expect(json.image).to.deep.equal([
`https://ecosystem-e2e-test.com${BASE}logo.png`,
])
expect(json.datePublished).to.equal('2021-01-01T00:00:00.000Z')
expect(json).to.has.property('dateModified')
expect(json.author[0]['@type']).to.equal('Person')
expect(json.author[0].name).to.equal('Mr.Hope')
})
})
})
42 changes: 24 additions & 18 deletions e2e/tests/theme-default/home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,36 @@ describe('homepage', () => {
const BASE = Cypress.env('E2E_BASE')

it('has hero info', () => {
const title = 'VuePress Ecosystem E2E'
const description = 'VuePress Ecosystem E2E Test Site'
const heroImage = 'https://v2.vuepress.vuejs.org/images/hero.png'

cy.visit('/')

cy.get('.hero img')
.should('have.attr', 'src', heroImage)
.should('have.attr', 'alt', title)
cy.get('.hero').within(() => {
const title = 'VuePress Ecosystem E2E'
const description = 'VuePress Ecosystem E2E Test Site'
const heroImage = 'https://v2.vuepress.vuejs.org/images/hero.png'

cy.get('img')
.should('have.attr', 'src', heroImage)
.should('have.attr', 'alt', title)

cy.get('#main-title').should('have.text', title)
cy.get('#main-title').should('have.text', title)

cy.get('.hero .description').should('have.text', description)
cy.get('.description').should('have.text', description)

cy.get('.actions .action-button')
.should('have.length', 2)
.each((el, index) => {
cy.wrap(el)
.should('have.attr', 'href', `${BASE}action${index + 1}.html`)
.should('have.attr', 'aria-label', `Action${index + 1}`)
.contains(`Action${index + 1}`)
})
cy.get('.action-button')
.should('have.length', 2)
.each((el, index) => {
cy.wrap(el)
.should('have.attr', 'href', `${BASE}action${index + 1}.html`)
.should('have.attr', 'aria-label', `Action${index + 1}`)
.contains(`Action${index + 1}`)
})
})
})

it('has feature', () => {
cy.visit('/')

cy.get('.features .feature').then((el) => {
cy.get('.feature').then((el) => {
cy.wrap(el)
.should('have.length', 3)
.each((el, index) => {
Expand Down
Loading

0 comments on commit e63b561

Please sign in to comment.