diff --git a/test/customCommands.js b/test/customCommands.js index 7ef6579..b4ff53f 100644 --- a/test/customCommands.js +++ b/test/customCommands.js @@ -1,125 +1,195 @@ import {Key, WebElement} from 'selenium-webdriver'; -import {nativeText, finputSwitchOptionsButton} from './pageObjects/index'; -import {isMac, isChrome, getModifierKey, driver} from './helpers'; +import {isMac, isChrome, getModifierKey} from './helpers'; import {mapKeys} from './keys'; -const shouldSkipModifierKeyTest = async () => { - const mac = await isMac(); - const chrome = await isChrome(); +const shouldSkipModifierKeyTest = async (driver) => { + const mac = await isMac(driver); + const chrome = await isChrome(driver); return mac && chrome; }; -export default (finputElement) => { - const typing = (keys) => { +export default () => { + + let driver; + let finputElement; + let finputSwitchOptionsButton; + let nativeText; + + const test = () => { + const chainFunctions = {}; + const commands = []; + let testMessage = ''; + + let startPos; + let textCut; let blurAfter = false; let pressModifier = false; let switchDelimiter = false; - const chainFunctions = {}; - + chainFunctions.copyingAndPasting = (text) => { + commands.push({ + action: async () => { + const modifierKey = await getModifierKey(driver); + + await nativeText().clear(); + await nativeText().click(); + await nativeText().sendKeys(text); + await nativeText().sendKeys(Key.chord(modifierKey, 'a')); + await nativeText().sendKeys(Key.chord(modifierKey, 'c')); + await nativeText().clear(); + + await finputElement().clear(); + await finputElement().click(); + await finputElement().sendKeys(Key.chord(modifierKey, 'v')); + }, + message: `copying and pasting "${text}" ` + }); - chainFunctions.thenSwitchingDelimiters = () => { - switchDelimiter = true; return chainFunctions; }; - chainFunctions.thenBlurring = () => { - blurAfter = true; + chainFunctions.cutting = (count) => { + commands.push({ + action: async () => { + const modifierKey = await getModifierKey(driver); + + await finputElement().clear(); + await finputElement().click(); + await finputElement().sendKeys(textCut); + await finputElement().sendKeys(Key.chord(modifierKey, 'a')); + await finputElement().sendKeys(mapKeys('←')); + await finputElement().sendKeys(Array(startPos + 1).join(mapKeys('→'))); + await finputElement().sendKeys(Key.chord(Key.SHIFT, Array(count + 1).join(mapKeys('→')))); + await finputElement().sendKeys(Key.chord(modifierKey, 'x')); + }, + message: `cutting "${count}" ` + }); + return chainFunctions; }; - chainFunctions.whileModifierPressed = () => { - pressModifier = true; + chainFunctions.characters = () => { + commands.push({ + action: () => {}, + message: `characters `, + setup: true + }); + return chainFunctions; }; - chainFunctions.shouldShow = (expected) => { - const withModifierMsg = pressModifier ? "with modifier key" : ""; - const testName = `should show "${expected}" when "${keys}" ${keys.length === 1 ? 'is' : 'are' } pressed ${withModifierMsg}`; - - it(testName, async () => { - await finputElement().clear(); - await finputElement().click(); + chainFunctions.from = (text) => { + commands.push({ + action: () => (textCut = text), + message: `from "${text}" `, + setup: true + }); - if (pressModifier) { - const mac = await isMac(); - const chrome = await isChrome(); + return chainFunctions; + }; - if (mac && chrome) { - console.warn(`Skipping test as Command key fails on Chrome/Mac. Note that this will show as a passing test. Test: '${testName}'`); - return; - } + chainFunctions.startingFrom = (start) => { + commands.push({ + action: () => (startPos = start), + message: `starting from "${start}" `, + setup: true + }); - const modifierKey = await getModifierKey(); - await finputElement().sendKeys(Key.chord(modifierKey, mapKeys(keys))); - } else { - await finputElement().sendKeys(mapKeys(keys)); - } + return chainFunctions; + }; - if (switchDelimiter) { - await finputSwitchOptionsButton().click(); - } + chainFunctions.typing = (keys) => { + commands.push({ + action: async () => { + await finputElement().clear(); + await finputElement().click(); + + if (pressModifier) { + const mac = await isMac(driver); + const chrome = await isChrome(driver); + + if (mac && chrome) { + console.warn(`Skipping test as Command key fails on Chrome/Mac. Note that this will show as a passing test. Test: '${testName}'`); + return false; + } + + const modifierKey = await getModifierKey(driver); + await finputElement().sendKeys(Key.chord(modifierKey, mapKeys(keys))); + } else { + await finputElement().sendKeys(mapKeys(keys)); + } - if (blurAfter) { - await nativeText().click(); - } + if (switchDelimiter) { + await finputSwitchOptionsButton().click(); + } - const observed = await finputElement().getAttribute('value'); - expect(observed).toBe(expected); + if (blurAfter) { + await nativeText().click(); + } + }, + message: `typing "${keys}" ` }); return chainFunctions; }; - chainFunctions.shouldHaveFocus = (expected) => { - it(`should have focus: ` + expected, async () => { - const element = await finputElement(); - const activeElement = await driver.switchTo().activeElement(); - const observed = await WebElement.equals(element, activeElement); - expect(observed).toBe(expected); + chainFunctions.thenSwitchingDelimiters = () => { + commands.push({ + action: () => (switchDelimiter = true), + message: `then switching delimiters `, + setup: true }); return chainFunctions; }; - chainFunctions.shouldHaveCaretAt = (expected) => { - it('should have caret at index: ' + expected, async () => { - const selection = await driver.executeScript(() => { - return [document.activeElement.selectionStart, document.activeElement.selectionEnd]; - }); - - expect(selection[0]).toEqual(selection[1]); // no selection, only caret cursor - expect(selection[0]).toEqual(expected); + chainFunctions.thenBlurring = () => { + commands.push({ + action: () => (blurAfter = true), + message: `then blurring `, + setup: true }); return chainFunctions; }; - return chainFunctions; - }; + chainFunctions.whileModifierPressed = () => { + commands.push({ + action: () => (pressModifier = true), + message: `with modifier key `, + setup: true + }); - const copyingAndPasting = (text) => { - const chainFunctions = {}; + return chainFunctions; + }; chainFunctions.shouldShow = (expected) => { - const testName = `should show "${expected}" when "${text}" is copied and pasted`; - it(testName, async () => { - if (await shouldSkipModifierKeyTest()) { + const testMessage = + commands + .map(command => command.message) + .join('') + .concat(`should show "${expected}" `); + + it(testMessage, async () => { + if (await shouldSkipModifierKeyTest(driver)) { console.warn(`Skipping test as Command key fails on Chrome/Mac. Note that this will show as a passing test. Test: '${testName}'`) return; } - const modifierKey = await getModifierKey(); - await nativeText().clear(); - await nativeText().click(); - await nativeText().sendKeys(text); - await nativeText().sendKeys(Key.chord(modifierKey, 'a')); - await nativeText().sendKeys(Key.chord(modifierKey, 'c')); - await nativeText().clear(); + const execCommands = []; + + for (let command of commands) + if (command.setup === true) + await command.action(); + else + execCommands.push(command); - await finputElement().clear(); - await finputElement().click(); - await finputElement().sendKeys(Key.chord(modifierKey, 'v')); + let result; + for (let command of execCommands) { + result = await command.action(); + if (result === false) + return; + } const observed = await finputElement().getAttribute('value'); expect(observed).toBe(expected); @@ -128,51 +198,41 @@ export default (finputElement) => { return chainFunctions; }; - return chainFunctions; - }; - - const cutting = (count) => { - let text, startPos; - const chainFunctions = {}; - - chainFunctions.characters = () => chainFunctions; - - chainFunctions.from = (t) => { - text = t; - return chainFunctions; - }; + chainFunctions.shouldHaveFocus = (expected) => { + it(`should have focus: ` + expected, async () => { + const element = await finputElement(); + const activeElement = await driver.switchTo().activeElement(); + const observed = await WebElement.equals(element, activeElement); + expect(observed).toBe(expected); + }); - chainFunctions.startingFrom = (start) => { - startPos = start; return chainFunctions; }; - chainFunctions.shouldShow = (expected) => { - const testName = `should show "${expected}" when "${text}" has chars cut`; - it(testName, async () => { - if (await shouldSkipModifierKeyTest()) { - console.warn(`Skipping test as Command key fails on Chrome/Mac. Note that this will show as a passing test. Test: '${testName}'`) - return; - } - const modifierKey = await getModifierKey(); - - await finputElement().clear(); - await finputElement().click(); - await finputElement().sendKeys(text); - await finputElement().sendKeys(Key.chord(modifierKey, 'a')); - await finputElement().sendKeys(mapKeys('←')); - await finputElement().sendKeys(Array(startPos + 1).join(mapKeys('→'))); - await finputElement().sendKeys(Key.chord(Key.SHIFT, Array(count + 1).join(mapKeys('→')))); - await finputElement().sendKeys(Key.chord(modifierKey, 'x')); + chainFunctions.shouldHaveCaretAt = (expected) => { + it('should have caret at index: ' + expected, async () => { + const selection = await driver.executeScript(() => { + return [document.activeElement.selectionStart, document.activeElement.selectionEnd]; + }); - const observed = await finputElement().getAttribute('value'); - expect(observed).toBe(expected); + expect(selection[0]).toEqual(selection[1]); // no selection, only caret cursor + expect(selection[0]).toEqual(expected); }); + return chainFunctions; }; return chainFunctions; }; - return {typing, copyingAndPasting, cutting}; + test.withEnvironment = (env) => { + ({ + driver, + finputElement, + finputSwitchOptionsButton, + nativeText + } = env); + }; + + return test; }; diff --git a/test/helpers.js b/test/helpers.js index 975094a..7912ee8 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -14,29 +14,29 @@ const getSeleniumURL = () => { return 'http://localhost:4444/wd/hub' }; - - -export const driver = new Builder() +const driver = new Builder() .withCapabilities(capabilities) .usingServer(getSeleniumURL()) .build(); -export const isMac = async () => { +export const getDriver = () => driver; + +export const isMac = async (driver) => { const capabilities = await driver.getCapabilities(); const os = capabilities.get(Capability.PLATFORM); return os.toUpperCase().indexOf(Platform.MAC) >= 0; }; -export const isBrowser = async (browserName) => { +const isBrowser = (driver) => async (browserName) => { const capabilities = await driver.getCapabilities(); const browser = capabilities.get(Capability.BROWSER_NAME); return browser.indexOf(browserName) >= 0; }; -export const isChrome = async () => isBrowser(Browser.CHROME); +export const isChrome = async (driver) => isBrowser(driver)(Browser.CHROME); -export const getModifierKey = async () => { - const mac = await isMac(); +export const getModifierKey = async (driver) => { + const mac = await isMac(driver); return mac ? Key.COMMAND : Key.CONTROL; }; @@ -46,7 +46,6 @@ afterAll(async () => { listener(); process.removeListener('exit', listener); } - await driver.quit(); }); export const defaultTimeout = 10e3; diff --git a/test/pageObjects/index.js b/test/pageObjects/index.js index a5206ee..822b7f6 100644 --- a/test/pageObjects/index.js +++ b/test/pageObjects/index.js @@ -8,14 +8,20 @@ const finputSwitchOptionsSelector = {css: '#finput-switch-options'}; const finputSwitchOptionsButtonSelector = {css: '#finput-switch-options-button'}; const nativeTextSelector = {css: '#native-text'}; -export const finputDefaultDelimiters = () => driver.findElement(finputDefaultSelector); -export const finputReversedDelimiters = () => driver.findElement(finputReversedDelimitersSelector); -export const finputSwitchOptions = () => driver.findElement(finputSwitchOptionsSelector); -export const finputSwitchOptionsButton = () => driver.findElement(finputSwitchOptionsButtonSelector); -export const nativeText = () => driver.findElement(nativeTextSelector); - -const root = () => driver.findElement(rootSelector); -export const load = async () => { +export const load = async (driver) => { await driver.get(`${__baseUrl__}/`); + + const root = () => driver.findElement(rootSelector); await driver.wait(until.elementLocated(root), defaultTimeout); + + return { + driver, + finputDefaultDelimiters: () => driver.findElement(finputDefaultSelector), + finputReversedDelimiters: () => driver.findElement(finputReversedDelimitersSelector), + finputSwitchOptions: () => driver.findElement(finputSwitchOptionsSelector), + finputSwitchOptionsButton: () => driver.findElement(finputSwitchOptionsButtonSelector), + nativeText: () => driver.findElement(nativeTextSelector) + }; }; + +export const unload = async (driver) => await driver.quit(); diff --git a/test/specs/copy-paste.js b/test/specs/copy-paste.js index dcdec99..1a497f3 100644 --- a/test/specs/copy-paste.js +++ b/test/specs/copy-paste.js @@ -1,24 +1,53 @@ -import {load, finputReversedDelimiters, finputDefaultDelimiters} from '../pageObjects/index'; -import customCommandsFactory from '../customCommands'; +import { load, unload } from '../pageObjects/index'; +import { getDriver } from '../helpers'; +import createCommands from '../customCommands'; describe('copy and paste', () => { - beforeAll(load); + let driver; + let finputDefaultDelimiters; + let finputReversedDelimiters; + let nativeText; + + const test = createCommands(); + + beforeAll(async () => { + driver = getDriver(); + ({ + finputDefaultDelimiters, + finputReversedDelimiters, + nativeText + } = await load(driver)); + }); + + afterAll(async () => await unload(driver)); describe('default delimiters', () => { - const {copyingAndPasting} = customCommandsFactory(finputDefaultDelimiters); + beforeAll(() => { + test.withEnvironment({ + driver, + finputElement: finputDefaultDelimiters, + nativeText + }) + }); - copyingAndPasting(`aaaaa`).shouldShow(``); - copyingAndPasting(`-12`).shouldShow(`-12.00`); - copyingAndPasting(`-.9`).shouldShow(`-0.90`); - copyingAndPasting(`7a7a.8a.`).shouldShow(`77.80`); + test().copyingAndPasting(`aaaaa`).shouldShow(``); + test().copyingAndPasting(`-12`).shouldShow(`-12.00`); + test().copyingAndPasting(`-.9`).shouldShow(`-0.90`); + test().copyingAndPasting(`7a7a.8a.`).shouldShow(`77.80`); }); describe('reversed delimiters', () => { - const {copyingAndPasting} = customCommandsFactory(finputReversedDelimiters); + beforeAll(() => { + test.withEnvironment({ + driver, + finputElement: finputReversedDelimiters, + nativeText + }) + }); - copyingAndPasting(`aaaaa`).shouldShow(``); - copyingAndPasting(`-12`).shouldShow(`-12,00`); - copyingAndPasting(`-,9`).shouldShow(`-0,90`); - copyingAndPasting(`7a7a,8a,`).shouldShow(`77,80`); + test().copyingAndPasting(`aaaaa`).shouldShow(``); + test().copyingAndPasting(`-12`).shouldShow(`-12,00`); + test().copyingAndPasting(`-,9`).shouldShow(`-0,90`); + test().copyingAndPasting(`7a7a,8a,`).shouldShow(`77,80`); }); -}); \ No newline at end of file +}); diff --git a/test/specs/cutting.js b/test/specs/cutting.js index fedf5d5..0c68f52 100644 --- a/test/specs/cutting.js +++ b/test/specs/cutting.js @@ -1,30 +1,55 @@ -import {load, finputReversedDelimiters, finputDefaultDelimiters} from '../pageObjects/index'; -import customCommandsFactory from '../customCommands'; +import { load, unload } from '../pageObjects/index'; +import { getDriver } from '../helpers'; +import createCommands from '../customCommands'; describe('cutting', () => { - beforeAll(load); + let driver; + let finputDefaultDelimiters; + let finputReversedDelimiters; + + const test = createCommands(); + + beforeAll(async () => { + driver = getDriver(); + ({ + finputDefaultDelimiters, + finputReversedDelimiters + } = await load(driver)); + }); + + afterAll(async () => await unload(driver)); describe('default delimiters', () => { - const {cutting} = customCommandsFactory(finputDefaultDelimiters); + beforeAll(() => { + test.withEnvironment({ + driver, + finputElement: finputDefaultDelimiters + }); + }); // Cutting from input (should fully format unless no characters selected) // None selected - cutting(0).characters().from(`123456`).startingFrom(0).shouldShow(`123,456`); - cutting(2).characters().from(`12`).startingFrom(2).shouldShow(`12`); + test().cutting(0).characters().from(`123456`).startingFrom(0).shouldShow(`123,456`); + test().cutting(2).characters().from(`12`).startingFrom(2).shouldShow(`12`); - cutting(4).characters().from(`123456`).startingFrom(1).shouldShow(`156.00`); - cutting(5).characters().from(`1234`).startingFrom(0).shouldShow(``); + test().cutting(4).characters().from(`123456`).startingFrom(1).shouldShow(`156.00`); + test().cutting(5).characters().from(`1234`).startingFrom(0).shouldShow(``); }); describe('reversed delimiters', () => { - const {cutting} = customCommandsFactory(finputReversedDelimiters); + beforeAll(() => { + test.withEnvironment({ + driver, + finputElement: finputReversedDelimiters + }); + }); // Cutting from input (should fully format unless no characters selected) // None selected - cutting(0).characters().from(`123456`).startingFrom(0).shouldShow(`123.456`); - cutting(2).characters().from(`12`).startingFrom(2).shouldShow(`12`); + test().cutting(0).characters().from(`123456`).startingFrom(0).shouldShow(`123.456`); + test().cutting(2).characters().from(`12`).startingFrom(2).shouldShow(`12`); - cutting(4).characters().from(`123456`).startingFrom(1).shouldShow(`156,00`); - cutting(5).characters().from(`1234`).startingFrom(0).shouldShow(``); + test().cutting(4).characters().from(`123456`).startingFrom(1).shouldShow(`156,00`); + test().cutting(5).characters().from(`1234`).startingFrom(0).shouldShow(``); }); }); \ No newline at end of file diff --git a/test/specs/deletions.js b/test/specs/deletions.js index bdeb3db..203f65a 100644 --- a/test/specs/deletions.js +++ b/test/specs/deletions.js @@ -1,65 +1,79 @@ -import {load, finputDefaultDelimiters} from '../pageObjects/index'; -import customCommandsFactory from '../customCommands'; - -const {typing} = customCommandsFactory(finputDefaultDelimiters); +import { load, unload } from '../pageObjects/index'; +import { getDriver } from '../helpers'; +import createCommands from '../customCommands'; describe('deletions', () => { - beforeAll(load); + let driver; + let finputDefaultDelimiters; + + const test = createCommands(); + + beforeAll(async () => { + driver = getDriver(); + ({ finputDefaultDelimiters } = await load(driver)); + + test.withEnvironment({ + driver, + finputElement: finputDefaultDelimiters + }); + }); + + afterAll(async () => await unload(driver)); describe('deletes digit', () => { describe('when BACKSPACE is pressed while caret is positioned directly ahead of it', () => { - typing('123456.78↚').shouldShow('123,456.7').shouldHaveCaretAt(9); - typing('123456.78↚↚').shouldShow('123,456.').shouldHaveCaretAt(8); - typing('123456.78↚↚↚').shouldShow('123,456').shouldHaveCaretAt(7); - typing('123456.78↚↚↚↚').shouldShow('12,345').shouldHaveCaretAt(6); - typing('123456.78↚↚↚↚↚').shouldShow('1,234').shouldHaveCaretAt(5); - typing('123456.78↚↚↚↚↚↚').shouldShow('123').shouldHaveCaretAt(3); - typing('123456.78↚↚↚↚↚↚↚').shouldShow('12').shouldHaveCaretAt(2); - typing('123456.78↚↚↚↚↚↚↚↚').shouldShow('1').shouldHaveCaretAt(1); + test().typing('123456.78↚').shouldShow('123,456.7').shouldHaveCaretAt(9); + test().typing('123456.78↚↚').shouldShow('123,456.').shouldHaveCaretAt(8); + test().typing('123456.78↚↚↚').shouldShow('123,456').shouldHaveCaretAt(7); + test().typing('123456.78↚↚↚↚').shouldShow('12,345').shouldHaveCaretAt(6); + test().typing('123456.78↚↚↚↚↚').shouldShow('1,234').shouldHaveCaretAt(5); + test().typing('123456.78↚↚↚↚↚↚').shouldShow('123').shouldHaveCaretAt(3); + test().typing('123456.78↚↚↚↚↚↚↚').shouldShow('12').shouldHaveCaretAt(2); + test().typing('123456.78↚↚↚↚↚↚↚↚').shouldShow('1').shouldHaveCaretAt(1); - typing('123456←↚').shouldShow('12,346').shouldHaveCaretAt(5); - typing('123456←←↚').shouldShow('12,356').shouldHaveCaretAt(4); - typing('123456←←←←↚').shouldShow('12,456').shouldHaveCaretAt(2); - typing('123456←←←←←←↚').shouldShow('23,456').shouldHaveCaretAt(0); + test().typing('123456←↚').shouldShow('12,346').shouldHaveCaretAt(5); + test().typing('123456←←↚').shouldShow('12,356').shouldHaveCaretAt(4); + test().typing('123456←←←←↚').shouldShow('12,456').shouldHaveCaretAt(2); + test().typing('123456←←←←←←↚').shouldShow('23,456').shouldHaveCaretAt(0); }); describe('when DELETE is pressed while caret is positioned directly behind of it', () => { - typing('123456.78⇤↛').shouldShow('23,456.78').shouldHaveCaretAt(0); - typing('123456.78⇤↛↛').shouldShow('3,456.78').shouldHaveCaretAt(0); - typing('123456.78⇤↛↛↛').shouldShow('456.78').shouldHaveCaretAt(0); - typing('123456.78⇤↛↛↛↛').shouldShow('56.78').shouldHaveCaretAt(0); - typing('123456.78⇤↛↛↛↛↛').shouldShow('6.78').shouldHaveCaretAt(0); - typing('123456.78⇤↛↛↛↛↛↛').shouldShow('.78').shouldHaveCaretAt(0); - typing('123456.78⇤↛↛↛↛↛↛↛').shouldShow('78').shouldHaveCaretAt(0); - typing('123456.78⇤↛↛↛↛↛↛↛↛').shouldShow('8').shouldHaveCaretAt(0); - typing('123456.78⇤↛↛↛↛↛↛↛↛↛').shouldShow('').shouldHaveCaretAt(0); + test().typing('123456.78⇤↛').shouldShow('23,456.78').shouldHaveCaretAt(0); + test().typing('123456.78⇤↛↛').shouldShow('3,456.78').shouldHaveCaretAt(0); + test().typing('123456.78⇤↛↛↛').shouldShow('456.78').shouldHaveCaretAt(0); + test().typing('123456.78⇤↛↛↛↛').shouldShow('56.78').shouldHaveCaretAt(0); + test().typing('123456.78⇤↛↛↛↛↛').shouldShow('6.78').shouldHaveCaretAt(0); + test().typing('123456.78⇤↛↛↛↛↛↛').shouldShow('.78').shouldHaveCaretAt(0); + test().typing('123456.78⇤↛↛↛↛↛↛↛').shouldShow('78').shouldHaveCaretAt(0); + test().typing('123456.78⇤↛↛↛↛↛↛↛↛').shouldShow('8').shouldHaveCaretAt(0); + test().typing('123456.78⇤↛↛↛↛↛↛↛↛↛').shouldShow('').shouldHaveCaretAt(0); - typing('123456.78←↛').shouldShow('123,456.7').shouldHaveCaretAt(9); - typing('123456.78←←↛').shouldShow('123,456.8').shouldHaveCaretAt(8); - typing('123456.78←←←←↛').shouldShow('12,345.78').shouldHaveCaretAt(6); - typing('123456.78←←←←←↛').shouldShow('12,346.78').shouldHaveCaretAt(5); + test().typing('123456.78←↛').shouldShow('123,456.7').shouldHaveCaretAt(9); + test().typing('123456.78←←↛').shouldShow('123,456.8').shouldHaveCaretAt(8); + test().typing('123456.78←←←←↛').shouldShow('12,345.78').shouldHaveCaretAt(6); + test().typing('123456.78←←←←←↛').shouldShow('12,346.78').shouldHaveCaretAt(5); }); }); describe('traverses thousands delimiter', () => { describe('backwards one place if BACKSPACE is pressed when caret is positioned directly ahead of it', () => { - typing('123456←←←↚').shouldShow('123,456').shouldHaveCaretAt(3); + test().typing('123456←←←↚').shouldShow('123,456').shouldHaveCaretAt(3); }); describe('forwards one place if DELETE is pressed when caret is positioned directly behind of it', () => { - typing('123456←←←←↛').shouldShow('123,456').shouldHaveCaretAt(4); + test().typing('123456←←←←↛').shouldShow('123,456').shouldHaveCaretAt(4); }); }); describe('deletes decimal delimiter', () => { describe('when BACKSPACE is pressed while caret is positioned directly ahead of it', () => { - typing('123456.78←←↚').shouldShow('12,345,678').shouldHaveCaretAt(8); - typing('123456.78←←↚.↚').shouldShow('12,345,678').shouldHaveCaretAt(8); + test().typing('123456.78←←↚').shouldShow('12,345,678').shouldHaveCaretAt(8); + test().typing('123456.78←←↚.↚').shouldShow('12,345,678').shouldHaveCaretAt(8); }); describe('when DELETE is pressed while caret is positioned directly behind of it', () => { - typing('123456.78←←←↛').shouldShow('12,345,678').shouldHaveCaretAt(8); - typing('123456.78←←←↛.←↛').shouldShow('12,345,678').shouldHaveCaretAt(8); + test().typing('123456.78←←←↛').shouldShow('12,345,678').shouldHaveCaretAt(8); + test().typing('123456.78←←←↛.←↛').shouldShow('12,345,678').shouldHaveCaretAt(8); }); }) }); diff --git a/test/specs/formatting-decimals.js b/test/specs/formatting-decimals.js index b9c3adc..df06f30 100644 --- a/test/specs/formatting-decimals.js +++ b/test/specs/formatting-decimals.js @@ -1,65 +1,91 @@ -import {load, finputReversedDelimiters, finputDefaultDelimiters} from '../pageObjects/index'; -import customCommandsFactory from '../customCommands'; +import { load, unload } from '../pageObjects/index'; +import { getDriver } from '../helpers'; +import createCommands from '../customCommands'; describe('formatting decimals', () => { - beforeAll(load); + let driver; + let finputDefaultDelimiters; + let finputReversedDelimiters; + let nativeText; + const test = createCommands(); + + beforeAll(async () => { + driver = getDriver(); + ({ + finputDefaultDelimiters, + finputReversedDelimiters, + nativeText + } = await load(driver)); + }); describe('default delimiters', () => { - const {typing} = customCommandsFactory(finputDefaultDelimiters); + beforeAll(async () => { + test.withEnvironment({ + driver, + finputElement: finputDefaultDelimiters, + nativeText + }); + }); describe('while focused', () => { - typing(`0`).shouldShow(`0`); - typing(`10`).shouldShow(`10`); - typing(`1←0`).shouldShow(`1`); - typing(`0.5←0`).shouldShow(`0.05`); - typing(`0.5←0`).shouldShow(`0.05`); - typing(`0.5←←0`).shouldShow(`0.5`); - typing(`1.5←←0`).shouldShow(`10.5`); - typing(`0.5←←7`).shouldShow(`7.5`); - typing(`0.5←←←0`).shouldShow(`0.5`); - typing(`.8`).shouldShow(`.8`); - typing(`.8←0`).shouldShow(`.08`); - typing(`.8←←0`).shouldShow(`0.8`); - typing(`123456←←←←←.`).shouldShow(`12.34`); - typing(`12.345`).shouldShow(`12.34`); - typing(`12.34←←↚`).shouldShow(`1,234`); - typing(`12.34←←↚`).shouldShow(`1,234`); + test().typing(`0`).shouldShow(`0`); + test().typing(`10`).shouldShow(`10`); + test().typing(`1←0`).shouldShow(`1`); + test().typing(`0.5←0`).shouldShow(`0.05`); + test().typing(`0.5←0`).shouldShow(`0.05`); + test().typing(`0.5←←0`).shouldShow(`0.5`); + test().typing(`1.5←←0`).shouldShow(`10.5`); + test().typing(`0.5←←7`).shouldShow(`7.5`); + test().typing(`0.5←←←0`).shouldShow(`0.5`); + test().typing(`.8`).shouldShow(`.8`); + test().typing(`.8←0`).shouldShow(`.08`); + test().typing(`.8←←0`).shouldShow(`0.8`); + test().typing(`123456←←←←←.`).shouldShow(`12.34`); + test().typing(`12.345`).shouldShow(`12.34`); + test().typing(`12.34←←↚`).shouldShow(`1,234`); + test().typing(`12.34←←↚`).shouldShow(`1,234`); }); describe('on blur', () => { - typing(`0.8`).thenBlurring().shouldShow(`0.80`); - typing(`.8`).thenBlurring().shouldShow(`0.80`); - typing(`8.88`).thenBlurring().shouldShow(`8.88`); + test().typing(`0.8`).thenBlurring().shouldShow(`0.80`); + test().typing(`.8`).thenBlurring().shouldShow(`0.80`); + test().typing(`8.88`).thenBlurring().shouldShow(`8.88`); }); }); describe('reversed delimiters', () => { - const {typing} = customCommandsFactory(finputReversedDelimiters); + beforeAll(async () => { + test.withEnvironment({ + driver, + finputElement: finputReversedDelimiters, + nativeText + }); + }); describe('while focused', () => { - typing(`0`).shouldShow(`0`); - typing(`10`).shouldShow(`10`); - typing(`1←0`).shouldShow(`1`); - typing(`0,5←0`).shouldShow(`0,05`); - typing(`0,5←0`).shouldShow(`0,05`); - typing(`0,5←←0`).shouldShow(`0,5`); - typing(`1,5←←0`).shouldShow(`10,5`); - typing(`0,5←←7`).shouldShow(`7,5`); - typing(`0,5←←←0`).shouldShow(`0,5`); - typing(`,8`).shouldShow(`,8`); - typing(`,8←0`).shouldShow(`,08`); - typing(`,8←←0`).shouldShow(`0,8`); - typing(`123456←←←←←,`).shouldShow(`12,34`); - typing(`12,345`).shouldShow(`12,34`); - typing(`12,34←←↚`).shouldShow(`1.234`); - typing(`12,34←←↚`).shouldShow(`1.234`); + test().typing(`0`).shouldShow(`0`); + test().typing(`10`).shouldShow(`10`); + test().typing(`1←0`).shouldShow(`1`); + test().typing(`0,5←0`).shouldShow(`0,05`); + test().typing(`0,5←0`).shouldShow(`0,05`); + test().typing(`0,5←←0`).shouldShow(`0,5`); + test().typing(`1,5←←0`).shouldShow(`10,5`); + test().typing(`0,5←←7`).shouldShow(`7,5`); + test().typing(`0,5←←←0`).shouldShow(`0,5`); + test().typing(`,8`).shouldShow(`,8`); + test().typing(`,8←0`).shouldShow(`,08`); + test().typing(`,8←←0`).shouldShow(`0,8`); + test().typing(`123456←←←←←,`).shouldShow(`12,34`); + test().typing(`12,345`).shouldShow(`12,34`); + test().typing(`12,34←←↚`).shouldShow(`1.234`); + test().typing(`12,34←←↚`).shouldShow(`1.234`); }); describe('on blur', () => { - typing(`0,8`).thenBlurring().shouldShow(`0,80`); - typing(`,8`).thenBlurring().shouldShow(`0,80`); - typing(`8,88`).thenBlurring().shouldShow(`8,88`); + test().typing(`0,8`).thenBlurring().shouldShow(`0,80`); + test().typing(`,8`).thenBlurring().shouldShow(`0,80`); + test().typing(`8,88`).thenBlurring().shouldShow(`8,88`); }) }); diff --git a/test/specs/formatting-negatives.js b/test/specs/formatting-negatives.js index d1f1758..a42d23f 100644 --- a/test/specs/formatting-negatives.js +++ b/test/specs/formatting-negatives.js @@ -1,55 +1,83 @@ -import {load, finputReversedDelimiters, finputDefaultDelimiters} from '../pageObjects/index'; -import customCommandsFactory from '../customCommands'; +import { load, unload } from '../pageObjects/index'; +import { getDriver } from '../helpers'; +import createCommands from '../customCommands'; describe('formatting negatives', () => { - beforeAll(load); + let driver; + let finputDefaultDelimiters; + let finputReversedDelimiters; + let nativeText; + const test = createCommands(); + + beforeAll(async () => { + driver = getDriver(); + ({ + finputDefaultDelimiters, + finputReversedDelimiters, + nativeText + } = await load(driver)); + }); + + afterAll(async () => await unload(driver)); describe('default delimiters', () => { - const {typing} = customCommandsFactory(finputDefaultDelimiters); + beforeAll(async () => { + test.withEnvironment({ + driver, + finputElement: finputDefaultDelimiters, + nativeText + }); + }); describe('while focused', () => { - typing(`-`).shouldShow(`-`); - typing(`-0`).shouldShow(`-0`); - typing(`--`).shouldShow(`-`); - typing(`-←0`).shouldShow(`-`); - typing(`0-`).shouldShow(`0`); - typing(`0-`).shouldShow(`0`); - typing(`-1000`).shouldShow(`-1,000`); - typing(`-1k`).shouldShow(`-1,000`); + test().typing(`-`).shouldShow(`-`); + test().typing(`-0`).shouldShow(`-0`); + test().typing(`--`).shouldShow(`-`); + test().typing(`-←0`).shouldShow(`-`); + test().typing(`0-`).shouldShow(`0`); + test().typing(`0-`).shouldShow(`0`); + test().typing(`-1000`).shouldShow(`-1,000`); + test().typing(`-1k`).shouldShow(`-1,000`); }); describe('on blur', () => { - typing(`-.`).thenBlurring().shouldShow(`-0.00`); - typing(`-`).thenBlurring().shouldShow(`-0.00`); - typing(`-0`).thenBlurring().shouldShow(`-0.00`); - typing(`-0.`).thenBlurring().shouldShow(`-0.00`); - typing(`-.66`).thenBlurring().shouldShow(`-0.66`); - typing(`-1000`).thenBlurring().shouldShow(`-1,000.00`); + test().typing(`-.`).thenBlurring().shouldShow(`-0.00`); + test().typing(`-`).thenBlurring().shouldShow(`-0.00`); + test().typing(`-0`).thenBlurring().shouldShow(`-0.00`); + test().typing(`-0.`).thenBlurring().shouldShow(`-0.00`); + test().typing(`-.66`).thenBlurring().shouldShow(`-0.66`); + test().typing(`-1000`).thenBlurring().shouldShow(`-1,000.00`); }); }); describe('reversed delimiters', () => { - const {typing} = customCommandsFactory(finputReversedDelimiters); + beforeAll(async () => { + test.withEnvironment({ + driver, + finputElement: finputReversedDelimiters, + nativeText + }); + }); describe('while focused', () => { - typing(`-`).shouldShow(`-`); - typing(`-0`).shouldShow(`-0`); - typing(`--`).shouldShow(`-`); - typing(`-←0`).shouldShow(`-`); - typing(`0-`).shouldShow(`0`); - typing(`0-`).shouldShow(`0`); - typing(`-1000`).shouldShow(`-1.000`); - typing(`-1k`).shouldShow(`-1.000`); + test().typing(`-`).shouldShow(`-`); + test().typing(`-0`).shouldShow(`-0`); + test().typing(`--`).shouldShow(`-`); + test().typing(`-←0`).shouldShow(`-`); + test().typing(`0-`).shouldShow(`0`); + test().typing(`0-`).shouldShow(`0`); + test().typing(`-1000`).shouldShow(`-1.000`); + test().typing(`-1k`).shouldShow(`-1.000`); }); describe('on blur', () => { - typing(`-,`).thenBlurring().shouldShow(`-0,00`); - typing(`-`).thenBlurring().shouldShow(`-0,00`); - typing(`-0`).thenBlurring().shouldShow(`-0,00`); - typing(`-0,`).thenBlurring().shouldShow(`-0,00`); - typing(`-,66`).thenBlurring().shouldShow(`-0,66`); - typing(`-1000`).thenBlurring().shouldShow(`-1.000,00`); + test().typing(`-,`).thenBlurring().shouldShow(`-0,00`); + test().typing(`-`).thenBlurring().shouldShow(`-0,00`); + test().typing(`-0`).thenBlurring().shouldShow(`-0,00`); + test().typing(`-0,`).thenBlurring().shouldShow(`-0,00`); + test().typing(`-,66`).thenBlurring().shouldShow(`-0,66`); + test().typing(`-1000`).thenBlurring().shouldShow(`-1.000,00`); }); }); diff --git a/test/specs/modifiers.js b/test/specs/modifiers.js index fa0cd9f..ea87894 100644 --- a/test/specs/modifiers.js +++ b/test/specs/modifiers.js @@ -1,28 +1,42 @@ -import {load, finputDefaultDelimiters} from '../pageObjects/index'; -import customCommandsFactory from '../customCommands'; - -const {typing} = customCommandsFactory(finputDefaultDelimiters); +import { load, unload } from '../pageObjects/index'; +import { getDriver } from '../helpers'; +import createCommands from '../customCommands'; describe('modifiers', () => { - beforeAll(load); + let driver; + let finputDefaultDelimiters; + + const test = createCommands(); + + beforeAll(async () => { + driver = getDriver(); + ({ finputDefaultDelimiters } = await load(driver)); + + test.withEnvironment({ + driver, + finputElement: finputDefaultDelimiters + }); + }); + + afterAll(async () => await unload(driver)); describe('are not blocked from activating keyboard shortcuts', () => { // TODO: find a way to test browser shortcuts blur the input (not currently working with chromedriver) - typing('k').whileModifierPressed().shouldShow(''); - typing('m').whileModifierPressed().shouldShow(''); - typing('b').whileModifierPressed().shouldShow(''); - typing('l').whileModifierPressed().shouldShow(''); - typing('h').whileModifierPressed().shouldShow(''); - - typing('0').whileModifierPressed().shouldShow(''); - typing('1').whileModifierPressed().shouldShow(''); - typing('2').whileModifierPressed().shouldShow(''); - typing('3').whileModifierPressed().shouldShow(''); - - typing('-').whileModifierPressed().shouldShow(''); - typing('+').whileModifierPressed().shouldShow(''); - typing('.').whileModifierPressed().shouldShow(''); - typing(',').whileModifierPressed().shouldShow(''); + test().typing('k').whileModifierPressed().shouldShow(''); + test().typing('m').whileModifierPressed().shouldShow(''); + test().typing('b').whileModifierPressed().shouldShow(''); + test().typing('l').whileModifierPressed().shouldShow(''); + test().typing('h').whileModifierPressed().shouldShow(''); + + test().typing('0').whileModifierPressed().shouldShow(''); + test().typing('1').whileModifierPressed().shouldShow(''); + test().typing('2').whileModifierPressed().shouldShow(''); + test().typing('3').whileModifierPressed().shouldShow(''); + + test().typing('-').whileModifierPressed().shouldShow(''); + test().typing('+').whileModifierPressed().shouldShow(''); + test().typing('.').whileModifierPressed().shouldShow(''); + test().typing(',').whileModifierPressed().shouldShow(''); }); }); ; \ No newline at end of file diff --git a/test/specs/shortcuts.js b/test/specs/shortcuts.js index 5d855c1..d4db7e8 100644 --- a/test/specs/shortcuts.js +++ b/test/specs/shortcuts.js @@ -1,130 +1,155 @@ -import {load, finputReversedDelimiters, finputDefaultDelimiters} from '../pageObjects/index'; -import customCommandsFactory from '../customCommands'; +import { load, unload } from '../pageObjects/index'; +import { getDriver } from '../helpers'; +import createCommands from '../customCommands'; describe('shortcuts', () => { - beforeAll(load); + let driver; + let finputDefaultDelimiters; + let finputReversedDelimiters; + + const test = createCommands(); + + beforeAll(async () => { + driver = getDriver(); + ({ + finputDefaultDelimiters, + finputReversedDelimiters + } = await load(driver)); + }); + + afterAll(async () => await unload(driver)); describe('default delimiters', () => { - const {typing} = customCommandsFactory(finputDefaultDelimiters); + beforeAll(async () => { + test.withEnvironment({ + driver, + finputElement: finputDefaultDelimiters + }); + }); describe('typed into empty field', () => { // TODO: fix bug which causes shortcuts to be capped to a limit for (let i = 1; i <= 2; i++) { - typing(`k`.padEnd(i, `k`)).shouldShow(`1` + `,000`.padEnd(i * 4, `,000`)); - typing(`m`.padEnd(i, `m`)).shouldShow(`1` + `,000`.padEnd(i * 8, `,000`)); - typing(`b`.padEnd(i, `b`)).shouldShow(`1` + `,000`.padEnd(i * 12, `,000`)); + test().typing(`k`.padEnd(i, `k`)).shouldShow(`1` + `,000`.padEnd(i * 4, `,000`)); + test().typing(`m`.padEnd(i, `m`)).shouldShow(`1` + `,000`.padEnd(i * 8, `,000`)); + test().typing(`b`.padEnd(i, `b`)).shouldShow(`1` + `,000`.padEnd(i * 12, `,000`)); } }); describe('entered onto end of integer number', () => { - typing(`1k`).shouldShow(`1,000`); - typing(`2m`).shouldShow(`2,000,000`); - typing(`3b`).shouldShow(`3,000,000,000`); + test().typing(`1k`).shouldShow(`1,000`); + test().typing(`2m`).shouldShow(`2,000,000`); + test().typing(`3b`).shouldShow(`3,000,000,000`); - typing(`1k1`).shouldShow(`10,001`); - typing(`2m2`).shouldShow(`20,000,002`); - typing(`3b3`).shouldShow(`30,000,000,003`); + test().typing(`1k1`).shouldShow(`10,001`); + test().typing(`2m2`).shouldShow(`20,000,002`); + test().typing(`3b3`).shouldShow(`30,000,000,003`); - typing(`1k1k`).shouldShow(`10,001,000`); - typing(`1m1m`).shouldShow(`10,000,001,000,000`); - typing(`1b1b`).shouldShow(`10,000,000,001,000,000,000`); + test().typing(`1k1k`).shouldShow(`10,001,000`); + test().typing(`1m1m`).shouldShow(`10,000,001,000,000`); + test().typing(`1b1b`).shouldShow(`10,000,000,001,000,000,000`); }); describe('entered onto end of decimal number', () => { - typing('.1k').shouldShow('100'); - typing('.1m').shouldShow('100,000'); - typing('.1b').shouldShow('100,000,000'); + test().typing('.1k').shouldShow('100'); + test().typing('.1m').shouldShow('100,000'); + test().typing('.1b').shouldShow('100,000,000'); - typing('1.1k').shouldShow('1,100'); - typing('1.1m').shouldShow('1,100,000'); - typing('1.1b').shouldShow('1,100,000,000'); + test().typing('1.1k').shouldShow('1,100'); + test().typing('1.1m').shouldShow('1,100,000'); + test().typing('1.1b').shouldShow('1,100,000,000'); - typing('1.01k').shouldShow('1,010'); - typing('1.01m').shouldShow('1,010,000'); - typing('1.01b').shouldShow('1,010,000,000'); + test().typing('1.01k').shouldShow('1,010'); + test().typing('1.01m').shouldShow('1,010,000'); + test().typing('1.01b').shouldShow('1,010,000,000'); }); describe('entered into middle of whole number', () => { - typing('12345←k').shouldShow('12,345,000'); - typing('12345←m').shouldShow('12,345,000,000'); - typing('12345←b').shouldShow('12,345,000,000,000'); + test().typing('12345←k').shouldShow('12,345,000'); + test().typing('12345←m').shouldShow('12,345,000,000'); + test().typing('12345←b').shouldShow('12,345,000,000,000'); - typing('12345←←k').shouldShow('12,345,000'); - typing('12345←←m').shouldShow('12,345,000,000'); - typing('12345←←b').shouldShow('12,345,000,000,000'); + test().typing('12345←←k').shouldShow('12,345,000'); + test().typing('12345←←m').shouldShow('12,345,000,000'); + test().typing('12345←←b').shouldShow('12,345,000,000,000'); }); describe('combined', () => { - typing(`kb`).shouldShow(`1,000,000,000,000`); - typing(`bk`).shouldShow(`1,000,000,000,000`); + test().typing(`kb`).shouldShow(`1,000,000,000,000`); + test().typing(`bk`).shouldShow(`1,000,000,000,000`); - typing(`km`).shouldShow(`1,000,000,000`); - typing(`mk`).shouldShow(`1,000,000,000`); + test().typing(`km`).shouldShow(`1,000,000,000`); + test().typing(`mk`).shouldShow(`1,000,000,000`); - typing(`bm`).shouldShow(`1,000,000,000,000,000`); - typing(`mb`).shouldShow(`1,000,000,000,000,000`); + test().typing(`bm`).shouldShow(`1,000,000,000,000,000`); + test().typing(`mb`).shouldShow(`1,000,000,000,000,000`); }); }); describe('reversed delimiters', () => { - const {typing} = customCommandsFactory(finputReversedDelimiters); + beforeAll(async () => { + test.withEnvironment({ + driver, + finputElement: finputReversedDelimiters + }); + }); test('typed into empty field', () => { // TODO: fix bug which causes shortcuts to be capped to a limit for (let i = 1; i <= 2; i++) { - typing(`k`.padEnd(i, `k`)).shouldShow(`1` + `.000`.padEnd(i * 4, `.000`)); - typing(`m`.padEnd(i, `m`)).shouldShow(`1` + `.000`.padEnd(i * 8, `.000`)); - typing(`b`.padEnd(i, `b`)).shouldShow(`1` + `.000`.padEnd(i * 12, `.000`)); + test().typing(`k`.padEnd(i, `k`)).shouldShow(`1` + `.000`.padEnd(i * 4, `.000`)); + test().typing(`m`.padEnd(i, `m`)).shouldShow(`1` + `.000`.padEnd(i * 8, `.000`)); + test().typing(`b`.padEnd(i, `b`)).shouldShow(`1` + `.000`.padEnd(i * 12, `.000`)); } }); describe('entered onto end of integer number', () => { - typing(`1k`).shouldShow(`1.000`); - typing(`2m`).shouldShow(`2.000.000`); - typing(`3b`).shouldShow(`3.000.000.000`); + test().typing(`1k`).shouldShow(`1.000`); + test().typing(`2m`).shouldShow(`2.000.000`); + test().typing(`3b`).shouldShow(`3.000.000.000`); - typing(`1k1`).shouldShow(`10.001`); - typing(`2m2`).shouldShow(`20.000.002`); - typing(`3b3`).shouldShow(`30.000.000.003`); + test().typing(`1k1`).shouldShow(`10.001`); + test().typing(`2m2`).shouldShow(`20.000.002`); + test().typing(`3b3`).shouldShow(`30.000.000.003`); - typing(`1k1k`).shouldShow(`10.001.000`); - typing(`1m1m`).shouldShow(`10.000.001.000.000`); - typing(`1b1b`).shouldShow(`10.000.000.001.000.000.000`); + test().typing(`1k1k`).shouldShow(`10.001.000`); + test().typing(`1m1m`).shouldShow(`10.000.001.000.000`); + test().typing(`1b1b`).shouldShow(`10.000.000.001.000.000.000`); }); describe('entered onto end of decimal number', () => { - typing(',1k').shouldShow('100'); - typing(',1m').shouldShow('100.000'); - typing(',1b').shouldShow('100.000.000'); + test().typing(',1k').shouldShow('100'); + test().typing(',1m').shouldShow('100.000'); + test().typing(',1b').shouldShow('100.000.000'); - typing('1,1k').shouldShow('1.100'); - typing('1,1m').shouldShow('1.100.000'); - typing('1,1b').shouldShow('1.100.000.000'); + test().typing('1,1k').shouldShow('1.100'); + test().typing('1,1m').shouldShow('1.100.000'); + test().typing('1,1b').shouldShow('1.100.000.000'); - typing('1,01k').shouldShow('1.010'); - typing('1,01m').shouldShow('1.010.000'); - typing('1,01b').shouldShow('1.010.000.000'); + test().typing('1,01k').shouldShow('1.010'); + test().typing('1,01m').shouldShow('1.010.000'); + test().typing('1,01b').shouldShow('1.010.000.000'); }); describe('entered into middle of whole number', () => { - typing('12345←k').shouldShow('12.345.000'); - typing('12345←m').shouldShow('12.345.000.000'); - typing('12345←b').shouldShow('12.345.000.000.000'); + test().typing('12345←k').shouldShow('12.345.000'); + test().typing('12345←m').shouldShow('12.345.000.000'); + test().typing('12345←b').shouldShow('12.345.000.000.000'); - typing('12345←←k').shouldShow('12.345.000'); - typing('12345←←m').shouldShow('12.345.000.000'); - typing('12345←←b').shouldShow('12.345.000.000.000'); + test().typing('12345←←k').shouldShow('12.345.000'); + test().typing('12345←←m').shouldShow('12.345.000.000'); + test().typing('12345←←b').shouldShow('12.345.000.000.000'); }); describe('combined', () => { - typing(`kb`).shouldShow(`1.000.000.000.000`); - typing(`bk`).shouldShow(`1.000.000.000.000`); + test().typing(`kb`).shouldShow(`1.000.000.000.000`); + test().typing(`bk`).shouldShow(`1.000.000.000.000`); - typing(`km`).shouldShow(`1.000.000.000`); - typing(`mk`).shouldShow(`1.000.000.000`); + test().typing(`km`).shouldShow(`1.000.000.000`); + test().typing(`mk`).shouldShow(`1.000.000.000`); - typing(`bm`).shouldShow(`1.000.000.000.000.000`); - typing(`mb`).shouldShow(`1.000.000.000.000.000`); + test().typing(`bm`).shouldShow(`1.000.000.000.000.000`); + test().typing(`mb`).shouldShow(`1.000.000.000.000.000`); }); }); }); diff --git a/test/specs/switching-delimiters.js b/test/specs/switching-delimiters.js index 62c038c..b057095 100644 --- a/test/specs/switching-delimiters.js +++ b/test/specs/switching-delimiters.js @@ -1,52 +1,71 @@ -import { load, finputSwitchOptions } from '../pageObjects/index'; -import customCommandsFactory from '../customCommands'; - -const { typing } = customCommandsFactory(finputSwitchOptions); +import { load, unload } from '../pageObjects/index'; +import { getDriver } from '../helpers'; +import createCommands from '../customCommands'; describe('Switching delimiters', () => { - beforeAll(load); + let driver; + let finputSwitchOptions; + let finputSwitchOptionsButton; + + const test = createCommands(); + + beforeAll(async () => { + driver = getDriver(); + ({ + finputSwitchOptions, + finputSwitchOptionsButton + } = await load(driver)); + + test.withEnvironment({ + driver, + finputElement: finputSwitchOptions, + finputSwitchOptionsButton + }); + }); + + afterAll(async () => await unload(driver)); // only decimal - typing('.99').thenSwitchingDelimiters().shouldShow('0,99'); - typing(',99').thenSwitchingDelimiters().shouldShow('0.99'); - typing('.99').thenSwitchingDelimiters().shouldShow('0,99'); - typing(',99').thenSwitchingDelimiters().shouldShow('0.99'); + test().typing('.99').thenSwitchingDelimiters().shouldShow('0,99'); + test().typing(',99').thenSwitchingDelimiters().shouldShow('0.99'); + test().typing('.99').thenSwitchingDelimiters().shouldShow('0,99'); + test().typing(',99').thenSwitchingDelimiters().shouldShow('0.99'); - typing('-.99').thenSwitchingDelimiters().shouldShow('-0,99'); - typing('-,99').thenSwitchingDelimiters().shouldShow('-0.99'); - typing('-.99').thenSwitchingDelimiters().shouldShow('-0,99'); - typing('-,99').thenSwitchingDelimiters().shouldShow('-0.99'); + test().typing('-.99').thenSwitchingDelimiters().shouldShow('-0,99'); + test().typing('-,99').thenSwitchingDelimiters().shouldShow('-0.99'); + test().typing('-.99').thenSwitchingDelimiters().shouldShow('-0,99'); + test().typing('-,99').thenSwitchingDelimiters().shouldShow('-0.99'); // only thousands - typing('1k').thenSwitchingDelimiters().shouldShow('1.000,00'); - typing('1k').thenSwitchingDelimiters().shouldShow('1,000.00'); - typing('1k').thenSwitchingDelimiters().shouldShow('1.000,00'); - typing('1k').thenSwitchingDelimiters().shouldShow('1,000.00'); + test().typing('1k').thenSwitchingDelimiters().shouldShow('1.000,00'); + test().typing('1k').thenSwitchingDelimiters().shouldShow('1,000.00'); + test().typing('1k').thenSwitchingDelimiters().shouldShow('1.000,00'); + test().typing('1k').thenSwitchingDelimiters().shouldShow('1,000.00'); - typing('-1k').thenSwitchingDelimiters().shouldShow('-1.000,00'); - typing('-1k').thenSwitchingDelimiters().shouldShow('-1,000.00'); - typing('-1k').thenSwitchingDelimiters().shouldShow('-1.000,00'); - typing('-1k').thenSwitchingDelimiters().shouldShow('-1,000.00'); + test().typing('-1k').thenSwitchingDelimiters().shouldShow('-1.000,00'); + test().typing('-1k').thenSwitchingDelimiters().shouldShow('-1,000.00'); + test().typing('-1k').thenSwitchingDelimiters().shouldShow('-1.000,00'); + test().typing('-1k').thenSwitchingDelimiters().shouldShow('-1,000.00'); // thousands and decimals - typing('123456.78').thenSwitchingDelimiters().shouldShow('123.456,78'); - typing('123456,78').thenSwitchingDelimiters().shouldShow('123,456.78'); - typing('123456.78').thenSwitchingDelimiters().shouldShow('123.456,78'); - typing('123456,78').thenSwitchingDelimiters().shouldShow('123,456.78'); + test().typing('123456.78').thenSwitchingDelimiters().shouldShow('123.456,78'); + test().typing('123456,78').thenSwitchingDelimiters().shouldShow('123,456.78'); + test().typing('123456.78').thenSwitchingDelimiters().shouldShow('123.456,78'); + test().typing('123456,78').thenSwitchingDelimiters().shouldShow('123,456.78'); - typing('-123456.78').thenSwitchingDelimiters().shouldShow('-123.456,78'); - typing('-123456,78').thenSwitchingDelimiters().shouldShow('-123,456.78'); - typing('-123456.78').thenSwitchingDelimiters().shouldShow('-123.456,78'); - typing('-123456,78').thenSwitchingDelimiters().shouldShow('-123,456.78'); + test().typing('-123456.78').thenSwitchingDelimiters().shouldShow('-123.456,78'); + test().typing('-123456,78').thenSwitchingDelimiters().shouldShow('-123,456.78'); + test().typing('-123456.78').thenSwitchingDelimiters().shouldShow('-123.456,78'); + test().typing('-123456,78').thenSwitchingDelimiters().shouldShow('-123,456.78'); // many thousands - typing('1b.99').thenSwitchingDelimiters().shouldShow('1.000.000.000,99'); - typing('1b,99').thenSwitchingDelimiters().shouldShow('1,000,000,000.99'); - typing('1b.99').thenSwitchingDelimiters().shouldShow('1.000.000.000,99'); - typing('1b,99').thenSwitchingDelimiters().shouldShow('1,000,000,000.99'); - - typing('-1b.99').thenSwitchingDelimiters().shouldShow('-1.000.000.000,99'); - typing('-1b,99').thenSwitchingDelimiters().shouldShow('-1,000,000,000.99'); - typing('-1b.99').thenSwitchingDelimiters().shouldShow('-1.000.000.000,99'); - typing('-1b,99').thenSwitchingDelimiters().shouldShow('-1,000,000,000.99'); + test().typing('1b.99').thenSwitchingDelimiters().shouldShow('1.000.000.000,99'); + test().typing('1b,99').thenSwitchingDelimiters().shouldShow('1,000,000,000.99'); + test().typing('1b.99').thenSwitchingDelimiters().shouldShow('1.000.000.000,99'); + test().typing('1b,99').thenSwitchingDelimiters().shouldShow('1,000,000,000.99'); + + test().typing('-1b.99').thenSwitchingDelimiters().shouldShow('-1.000.000.000,99'); + test().typing('-1b,99').thenSwitchingDelimiters().shouldShow('-1,000,000,000.99'); + test().typing('-1b.99').thenSwitchingDelimiters().shouldShow('-1.000.000.000,99'); + test().typing('-1b,99').thenSwitchingDelimiters().shouldShow('-1,000,000,000.99'); }); \ No newline at end of file diff --git a/test/specs/traversals.js b/test/specs/traversals.js index c4a3e46..58b4071 100644 --- a/test/specs/traversals.js +++ b/test/specs/traversals.js @@ -1,28 +1,42 @@ -import {load, finputDefaultDelimiters} from '../pageObjects/index'; -import customCommandsFactory from '../customCommands'; - -const {typing} = customCommandsFactory(finputDefaultDelimiters); +import { load, unload } from '../pageObjects/index'; +import { getDriver } from '../helpers'; +import createCommands from '../customCommands'; describe('traversals', () => { - beforeAll(load); + let driver; + let finputDefaultDelimiters; + + const test = createCommands(); + + beforeAll(async () => { + driver = getDriver(); + ({ finputDefaultDelimiters } = await load(driver)); + + test.withEnvironment({ + driver, + finputElement: finputDefaultDelimiters + }); + }); + + afterAll(async () => await unload(driver)); describe('supports HOME and END keys sending caret to start / end of field', () => { - typing(`12⇤3`).shouldShow(`312`).shouldHaveFocus(true).shouldHaveCaretAt(1); - typing(`123⇤⇤4`).shouldShow(`4,123`).shouldHaveCaretAt(1); - typing(`123⇤⇥4`).shouldShow(`1,234`).shouldHaveCaretAt(5); - typing(`123⇤⇥4⇤5`).shouldShow(`51,234`).shouldHaveCaretAt(1); + test().typing(`12⇤3`).shouldShow(`312`).shouldHaveFocus(true).shouldHaveCaretAt(1); + test().typing(`123⇤⇤4`).shouldShow(`4,123`).shouldHaveCaretAt(1); + test().typing(`123⇤⇥4`).shouldShow(`1,234`).shouldHaveCaretAt(5); + test().typing(`123⇤⇥4⇤5`).shouldShow(`51,234`).shouldHaveCaretAt(1); }); describe('supports left and right ARROW keys shifting caret left / right one caret', () => { - typing(`123456←8`).shouldShow(`1,234,586`); - typing(`123456←←8`).shouldShow(`1,234,856`); - typing(`123456←←←8`).shouldShow(`1,238,456`); + test().typing(`123456←8`).shouldShow(`1,234,586`); + test().typing(`123456←←8`).shouldShow(`1,234,856`); + test().typing(`123456←←←8`).shouldShow(`1,238,456`); }); describe('supports up and down ARROW keys sending caret to start / end of field', () => { - typing(`12↑3`).shouldShow(`312`).shouldHaveFocus(true).shouldHaveCaretAt(1); - typing(`123↑↑4`).shouldShow(`4,123`).shouldHaveCaretAt(1); - typing(`123↑↓4`).shouldShow(`1,234`).shouldHaveCaretAt(5); - typing(`123↑↓4↑5`).shouldShow(`51,234`).shouldHaveCaretAt(1); + test().typing(`12↑3`).shouldShow(`312`).shouldHaveFocus(true).shouldHaveCaretAt(1); + test().typing(`123↑↑4`).shouldShow(`4,123`).shouldHaveCaretAt(1); + test().typing(`123↑↓4`).shouldShow(`1,234`).shouldHaveCaretAt(5); + test().typing(`123↑↓4↑5`).shouldShow(`51,234`).shouldHaveCaretAt(1); }); });