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/admin.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.
270 lines (188 sloc)
7.5 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 = 100 | |
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('menu', () => { | |
test('Main Menu', async done => { | |
jest.setTimeout(30000) | |
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() | |
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') | |
await page.click('button[name=Menu]') | |
title = await page.title() | |
expect(title).toBe('Menu') | |
await page.click('button[name=mainmenu]') | |
title = await page.title() | |
expect(title).toBe('Main Menu') | |
await page.click('button[name=Order]') | |
title = await page.title() | |
expect(title).toBe('Order') | |
await page.click('button[name=mainmenu]') | |
title = await page.title() | |
expect(title).toBe('Main Menu') | |
await page.click('button[name=Ready]') | |
title = await page.title() | |
expect(title).toBe('Order Status') | |
await page.click('button[name=mainmenu]') | |
title = await page.title() | |
expect(title).toBe('Main Menu') | |
await page.click('button[name=LogOut]') | |
title = await page.title() | |
expect(title).toBe('Log In') | |
const image = await page.screenshot() | |
expect(image).toMatchImageSnapshot() | |
done() | |
}) | |
test('Admin add/edit', 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() | |
await page.type('input[name=user]', 'Craig') | |
await page.type('input[name=pass]', 'bread') | |
await page.click('input[type=submit]') | |
await page.click('button[name=Menu]') | |
await page.click('button[name=adding]') | |
title = await page.title() | |
expect(title).toBe('Adding an Item') | |
await page.type('input[name=itemName]', 'Spaghetti') | |
await page.type('input[name=itemPricePounds]', '8') | |
await page.type('input[name=itemPricePence]', '50') | |
await page.type('input[name=itemType]', 'main') | |
await page.click('input[type=submit]') | |
const itemName = await page.evaluate(() => { | |
const dom = document.querySelectorAll('table tr td:first-child') | |
const arr = Array.from(dom) | |
return arr.map(td => td.innerText) | |
}) | |
console.log(itemName) | |
expect(itemName).toStrictEqual(['Spaghetti']) | |
await page.click('button[name=edit]') | |
await page.type('input[name=itemName]', 'Bolognese ') | |
await page.click('input[type=submit]') | |
await page.waitFor(1000) | |
const newItemName = await page.evaluate(() => { | |
const dom = document.querySelectorAll('table tr td:first-child') | |
const arr = Array.from(dom) | |
return arr.map(td => td.innerText) | |
}) | |
console.log(newItemName) | |
expect(newItemName).toStrictEqual(['Bolognese Spaghetti']) | |
const image = await page.screenshot() | |
expect(image).toMatchImageSnapshot() | |
done() | |
}) | |
test('Admin New Order/Ready Order', 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() | |
await page.type('input[name=user]', 'Craig') | |
await page.type('input[name=pass]', 'bread') | |
await page.click('input[type=submit]') | |
await page.click('button[name=Menu]') | |
await page.click('button[name=adding]') | |
title = await page.title() | |
expect(title).toBe('Adding an Item') | |
await page.type('input[name=itemName]', 'Spaghetti') | |
await page.type('input[name=itemPricePounds]', '8') | |
await page.type('input[name=itemPricePence]', '50') | |
await page.type('input[name=itemType]', 'main') | |
await page.click('input[type=submit]') | |
await page.click('button[name=mainmenu]') | |
await page.goto('http://localhost:8080/order/1', { timeout: 30000, waitUntil: 'load' }) | |
await page.click('input[name=add]') | |
let quantity = await page.evaluate(() => { | |
const dom = document.querySelectorAll('td[name=itemQuantity]') | |
const arr = Array.from(dom) | |
return arr.map(td => td.innerText) | |
}) | |
expect(quantity).toStrictEqual(['1']) | |
await page.click('input[name=remove]') | |
quantity = await page.evaluate(() => { | |
const dom = document.querySelectorAll('td[name=itemQuantity]') | |
const arr = Array.from(dom) | |
return arr.map(td => td.innerText) | |
}) | |
expect(quantity).toStrictEqual(['0']) | |
const image = await page.screenshot() | |
expect(image).toMatchImageSnapshot() | |
done() | |
}) | |
test('Admin Ready', 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() | |
await page.type('input[name=user]', 'Craig') | |
await page.type('input[name=pass]', 'bread') | |
await page.click('input[type=submit]') | |
await page.click('button[name=Menu]') | |
await page.click('button[name=adding]') | |
title = await page.title() | |
expect(title).toBe('Adding an Item') | |
await page.type('input[name=itemName]', 'Spaghetti') | |
await page.type('input[name=itemPricePounds]', '8') | |
await page.type('input[name=itemPricePence]', '50') | |
await page.type('input[name=itemType]', 'main') | |
await page.click('input[type=submit]') | |
await page.click('button[name=mainmenu]') | |
await page.goto('http://localhost:8080/order/1', { timeout: 30000, waitUntil: 'load' }) | |
await page.click('input[name=add]') | |
await page.goto('http://localhost:8080/ready', { timeout: 30000, waitUntil: 'load' }) | |
await page.click('input[name=ready]') | |
let ID = await page.evaluate(() => { | |
const dom = document.querySelectorAll('td[name=readyID]') | |
const arr = Array.from(dom) | |
return arr.map(td => td.innerText) | |
}) | |
expect(ID).toStrictEqual(['1']) | |
await page.click('input[name=unready]') | |
ID = await page.evaluate(() => { | |
const dom = document.querySelectorAll('td[name=unreadyID]') | |
const arr = Array.from(dom) | |
return arr.map(td => td.innerText) | |
}) | |
expect(ID).toStrictEqual(['1']) | |
const image = await page.screenshot() | |
expect(image).toMatchImageSnapshot() | |
done() | |
}) | |
}) |