Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DynamicWebsite/acceptance tests/users.test.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
141 lines (92 sloc)
3.56 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable max-len */ | |
'use strict' | |
const puppeteer = require('puppeteer') | |
const { configureToMatchImageSnapshot } = require('jest-image-snapshot') | |
const width = 800 | |
const height = 600 | |
const delayMS = 10 | |
const shell = require('shelljs') | |
let browser | |
let page | |
// threshold is the difference in pixels before the snapshots dont match | |
const toMatchImageSnapshot = configureToMatchImageSnapshot({ | |
customDiffConfig: { threshold: 2 }, | |
noColors: true, | |
}) | |
expect.extend({ toMatchImageSnapshot }) | |
beforeAll( async() => { | |
browser = await puppeteer.launch({ headless: true, slowMo: delayMS, args: [`--window-size=${width},${height}`, '--no-sandbox'] }) | |
page = await browser.newPage() | |
await page.setViewport({ width, height }) | |
}) | |
beforeEach( () => shell.exec('./abolishDB.sh')) | |
afterAll( () => browser.close() ) | |
describe('login test cases', () => { | |
test('No Username', async done => { | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.type('input[name=pass]', 'bread') | |
await page.click('input[type=submit]') | |
const title = await page.title() | |
expect(title).toBe('ERROR') | |
const image = await page.screenshot() | |
expect(image).toMatchImageSnapshot() | |
done() | |
}) | |
test('No password', async done => { | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.type('input[name=user]', 'bread') | |
await page.click('input[type=submit]') | |
const title = await page.title() | |
expect(title).toBe('ERROR') | |
const image = await page.screenshot() | |
expect(image).toMatchImageSnapshot() | |
done() | |
}) | |
}) | |
describe('register', () => { | |
test('No Username register', async done => { | |
shell.exec('abolishDB.sh') | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.click('[href="/register"]') | |
await page.type('input[name=pass]', 'bread') | |
await page.click('input[type=submit]') | |
const title = await page.title() | |
expect(title).toBe('ERROR') | |
const image = await page.screenshot() | |
expect(image).toMatchImageSnapshot() | |
done() | |
}) | |
test('No Password register', async done => { | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.click('[href="/register"]') | |
await page.type('input[name=user]', 'bread') | |
await page.click('input[type=submit]') | |
const title = await page.title() | |
expect(title).toBe('ERROR') | |
const image = await page.screenshot() | |
expect(image).toMatchImageSnapshot() | |
done() | |
}) | |
test('Successful register', async done => { | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.click('[href="/register"]') | |
await page.type('input[name=user]', 'Craig') | |
await page.type('input[name=pass]', 'bread') | |
await page.click('input[type=submit]') | |
let title = await page.title() | |
expect(title).toBe('Log In') | |
await page.type('input[name=user]', 'Craig') | |
await page.type('input[name=pass]', 'bread') | |
await page.click('input[type=submit]') | |
title = await page.title() | |
expect(title).toBe('Main Menu') | |
const image = await page.screenshot() | |
expect(image).toMatchImageSnapshot() | |
done() | |
}) | |
}) | |