Nuxt/test/e2e/children.patch.browser.test.js

134 lines
4.1 KiB
JavaScript
Raw Normal View History

2018-03-19 08:31:25 +00:00
import { Nuxt, Utils } from '../..'
import Browser from '../utils/browser'
import { loadFixture, getPort } from '../utils'
2018-03-16 19:52:17 +00:00
2018-03-18 23:41:14 +00:00
let port
const browser = new Browser()
2018-01-13 05:22:11 +00:00
const url = route => 'http://localhost:' + port + route
2017-11-02 13:24:43 +00:00
let nuxt = null
let page
const dates = {}
2017-11-02 13:24:43 +00:00
2018-03-18 23:41:14 +00:00
describe('children patch (browser)', () => {
2018-03-18 19:31:32 +00:00
beforeAll(async () => {
2018-03-18 23:41:14 +00:00
const options = loadFixture('children')
nuxt = new Nuxt(options)
2018-03-18 23:41:14 +00:00
port = await getPort()
await nuxt.listen(port, 'localhost')
2018-03-18 23:41:14 +00:00
})
2018-03-18 19:31:32 +00:00
test('Start browser', async () => {
expect.assertions(0) // suppress 'no assertions' warning
await browser.start({
// slowMo: 50,
// headless: false
})
})
2018-03-18 19:31:32 +00:00
test('Loading /patch and keep ', async () => {
page = await browser.page(url('/patch'))
2018-03-18 19:31:32 +00:00
const h1 = await page.$text('h1')
expect(h1.includes('patch:')).toBe(true)
const h2 = await page.$text('h2')
expect(h2).toBe('Index')
dates.patch = await page.$text('[data-date-patch]')
2017-11-02 13:24:43 +00:00
})
2018-03-18 19:31:32 +00:00
test('Navigate to /patch/1', async () => {
const { hook } = await page.nuxt.navigate('/patch/1', false)
const loading = await page.nuxt.loadingData()
expect(loading.show).toBe(true)
await hook
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
const h2 = await page.$text('h2')
expect(h2.includes('_id:')).toBe(true)
dates.id = await page.$text('[data-date-id]')
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
expect(dates.patch).toBe(await page.$text('[data-date-patch]'))
})
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
test('Navigate to /patch/2', async () => {
await page.nuxt.navigate('/patch/2')
const date = await page.$text('[data-date-id]')
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
expect(await page.$text('h3')).toBe('Index')
expect(dates.patch).toBe(await page.$text('[data-date-patch]'))
expect(+dates.id < +date).toBe(true)
dates.id = date
})
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
test('Navigate to /patch/2?test=true', async () => {
await page.nuxt.navigate('/patch/2?test=true')
expect(dates.patch).toBe(await page.$text('[data-date-patch]'))
expect(dates.id).toBe(await page.$text('[data-date-id]'))
})
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
test('Navigate to /patch/2#test', async () => {
await page.nuxt.navigate('/patch/2#test')
expect(dates.patch).toBe(await page.$text('[data-date-patch]'))
expect(dates.id).toBe(await page.$text('[data-date-id]'))
})
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
test('Navigate to /patch/2/child', async () => {
await page.nuxt.navigate('/patch/2/child')
dates.child = await page.$text('[data-date-child]')
dates.slug = await page.$text('[data-date-child-slug]')
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
expect(dates.patch).toBe(await page.$text('[data-date-patch]'))
expect(dates.id).toBe(await page.$text('[data-date-id]'))
expect(+dates.child > +dates.id).toBe(true)
expect(+dates.slug > +dates.child).toBe(true)
})
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
test('Navigate to /patch/2/child/1', async () => {
await page.nuxt.navigate('/patch/2/child/1')
const date = await page.$text('[data-date-child-slug]')
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
expect(dates.patch).toBe(await page.$text('[data-date-patch]'))
expect(dates.id).toBe(await page.$text('[data-date-id]'))
expect(dates.child).toBe(await page.$text('[data-date-child]'))
expect(+date > +dates.slug).toBe(true)
dates.slug = date
})
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
test('Navigate to /patch/2/child/1?foo=bar', async () => {
await page.nuxt.navigate('/patch/2/child/1?foo=bar')
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
expect(dates.patch).toBe(await page.$text('[data-date-patch]'))
expect(dates.id).toBe(await page.$text('[data-date-id]'))
expect(dates.child).toBe(await page.$text('[data-date-child]'))
expect(dates.slug).toBe(await page.$text('[data-date-child-slug]'))
})
2017-11-02 13:24:43 +00:00
2018-03-18 19:31:32 +00:00
test('Search a country', async () => {
const countries = await page.$$text('[data-test-search-result]')
expect(countries.length).toBe(5)
await page.type('[data-test-search-input]', 'gu')
await Utils.waitFor(250)
const newCountries = await page.$$text('[data-test-search-result]')
expect(newCountries.length).toBe(1)
expect(newCountries).toEqual(['Guinea'])
expect(await page.nuxt.routeData()).toEqual({
path: '/patch/2/child/1',
query: {
foo: 'bar',
q: 'gu'
}
})
2017-11-02 13:24:43 +00:00
})
2018-03-18 19:31:32 +00:00
// Close server and ask nuxt to stop listening to file changes
test('Closing server and nuxt.js', async () => {
await nuxt.close()
})
2018-03-18 19:31:32 +00:00
test('Stop browser', async () => {
await page.close()
2018-03-18 23:41:14 +00:00
await browser.close()
2018-03-18 19:31:32 +00:00
})
2017-11-02 13:24:43 +00:00
})