This file contains hidden or 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
| module.exports.initialState = { display: '0', initial: true } | |
| module.exports.nextState = (calculatorState, character) => { | |
| if (isDigit(character)) { | |
| return addDigit(calculatorState, character) | |
| } else if (isOperator(character)) { | |
| return addOperator(calculatorState, character) | |
| } else if (isEqualSign(character)) { | |
| return compute(calculatorState) | |
| } else { |
This file contains hidden or 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
| let server | |
| before((done) => { | |
| const app = express() | |
| app.use('/', express.static(path.resolve(__dirname, '../../dist'))) | |
| server = app.listen(8080, done) | |
| }) | |
| after(() => { | |
| server.close() | |
| }) |
This file contains hidden or 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
| const {prepareDriver, cleanupDriver} = require('../utils/browser-automation') | |
| //... | |
| describe('calculator app', function () { | |
| let driver | |
| ... | |
| before(async () => { | |
| driver = await prepareDriver() | |
| }) | |
| after(() => cleanupDriver(driver)) |
This file contains hidden or 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
| const webdriver = require('selenium-webdriver') | |
| const chromeDriver = require('chromedriver') | |
| const path = require('path') | |
| const chromeDriverPathAddition = `:${path.dirname(chromeDriver.path)}` | |
| exports.prepareDriver = async () => { | |
| process.on('beforeExit', () => this.browser && this.browser.quit()) | |
| process.env.PATH += chromeDriverPathAddition |
This file contains hidden or 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
| // ... | |
| const retry = require('promise-retry') | |
| // ... | |
| it('should work', async function () { | |
| await driver.get('http://localhost:8080') | |
| await retry(async () => { | |
| const title = await driver.getTitle() |
This file contains hidden or 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
| const {By} = require('selenium-webdriver') | |
| it('should work', async function () { | |
| await driver.get('http://localhost:8080') | |
| //... | |
| await retry(async () => { | |
| const displayElement = await driver.findElement(By.css('.display')) | |
| const displayText = await displayElement.getText() | |
| expect(displayText).to.equal('0') |
This file contains hidden or 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
| const digit4Element = await driver.findElement(By.css('.digit-4')) | |
| const digit2Element = await driver.findElement(By.css('.digit-2')) | |
| const operatorMultiply = await driver.findElement(By.css('.operator-multiply')) | |
| const operatorEquals = await driver.findElement(By.css('.operator-equals')) | |
| await digit4Element.click() | |
| await digit2Element.click() | |
| await operatorMultiply.click() | |
| await digit2Element.click() | |
| await operatorEquals.click() |
This file contains hidden or 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
| before(function () { | |
| global.document = jsdom(`<!doctype html><html><body><div id="container"/></div></body></html>`) | |
| global.window = document.defaultView | |
| }) | |
| after(function () { | |
| delete global.window | |
| delete global.document | |
| }) |
This file contains hidden or 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
| ReactDom.render(e(CalculatorApp), document.getElementById('container')) | |
| const displayElement = document.querySelector('.display') | |
| expect(displayElement.textContent).to.equal('0') | |
| const digit4Element = document.querySelector('.digit-4') | |
| const digit2Element = document.querySelector('.digit-2') | |
| const operatorMultiply = document.querySelector('.operator-multiply') | |
| const operatorEquals = document.querySelector('.operator-equals') |
This file contains hidden or 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
| var ev = new Event("keyup", ...); | |
| document.dispatchEvent(ev); |