summaryrefslogtreecommitdiffhomepage
path: root/test/components/AccountInput.spec.js
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2018-07-18 15:07:37 +0200
committerAndrej Mihajlov <and@mullvad.net>2018-08-15 17:39:38 +0200
commit71592249b2dd669b6f24f37bfb7b0f4e43b74998 (patch)
treea6097dc7e5d94d06e99c65fdfe160e824395f50c /test/components/AccountInput.spec.js
parente84e87f4ce5a8c242f756566cdc6fb59a45f7bea (diff)
downloadmullvadvpn-71592249b2dd669b6f24f37bfb7b0f4e43b74998.tar.xz
mullvadvpn-71592249b2dd669b6f24f37bfb7b0f4e43b74998.zip
Add workspaces
Diffstat (limited to 'test/components/AccountInput.spec.js')
-rw-r--r--test/components/AccountInput.spec.js183
1 files changed, 0 insertions, 183 deletions
diff --git a/test/components/AccountInput.spec.js b/test/components/AccountInput.spec.js
deleted file mode 100644
index 2f6ead1b45..0000000000
--- a/test/components/AccountInput.spec.js
+++ /dev/null
@@ -1,183 +0,0 @@
-// @flow
-
-import { createKeyEvent } from '../helpers/dom-events';
-import * as React from 'react';
-import { shallow } from 'enzyme';
-import AccountInput from '../../app/components/AccountInput';
-import type { AccountInputProps } from '../../app/components/AccountInput';
-
-describe('components/AccountInput', () => {
- const getInputRef = (component) => {
- const node = getComponent(component, 'AccountInput');
- return node;
- };
-
- const render = (mergeProps: $Shape<AccountInputProps>) => {
- const defaultProps: AccountInputProps = {
- value: '',
- onEnter: null,
- onChange: null,
- };
- const props = Object.assign({}, defaultProps, mergeProps);
- return shallow(<AccountInput {...props} />);
- };
-
- it('should call onEnter', (done) => {
- const component = render({
- onEnter: () => done(),
- });
- keyPress(getInputRef(component), createKeyEvent('Enter'));
- });
-
- it('should call onChange', (done) => {
- const component = render({
- onChange: (val) => {
- expect(val).to.be.equal('1');
- done();
- },
- });
- keyPress(getInputRef(component), createKeyEvent('1'));
- });
-
- it('should format input properly', () => {
- const cases = [
- '1111111111111',
- '1111 1111 1111',
- '1111 1111 111',
- '1111 1111 11',
- '1111 1111 1',
- '1111 1111',
- '1111 111',
- '1111 11',
- '1111 1',
- '1111',
- '111',
- '11',
- '1',
- '',
- ];
-
- for (const value of cases) {
- const component = render({ value });
- expect(getInputRef(component).prop('value')).to.be.equal(value);
- }
- });
-
- it('should remove last character', (done) => {
- const component = render({
- value: '1234',
- onChange: (val) => {
- expect(val).to.be.equal('123');
- done();
- },
- });
- keyPress(getInputRef(component), createKeyEvent('Backspace'));
- });
-
- it('should remove first character', (done) => {
- const component = render({
- value: '1234',
- onChange: (val) => {
- expect(val).to.be.equal('234');
- done();
- },
- });
- component.setState({ selectionRange: [1, 1] }, () => {
- keyPress(getInputRef(component), createKeyEvent('Backspace'));
- });
- });
-
- it('should remove all characters', (done) => {
- const component = render({
- value: '12345678',
- onChange: (val) => {
- expect(val).to.be.empty;
- done();
- },
- });
- component.setState({ selectionRange: [0, 8] }, () => {
- keyPress(getInputRef(component), createKeyEvent('Backspace'));
- });
- });
-
- it('should remove selection', (done) => {
- const component = render({
- value: '1234 5678 9999',
- onChange: (val) => {
- expect(val).to.be.equal('12349999');
- done();
- },
- });
- component.setState({ selectionRange: [4, 8] }, () => {
- keyPress(getInputRef(component), createKeyEvent('Backspace'));
- });
- });
-
- it('should replace selection', (done) => {
- const component = render({
- value: '0000',
- });
-
- component.setState({ selectionRange: [1, 3] }, () => {
- keyPress(getInputRef(component), createKeyEvent('1'));
-
- component.setState({}, () => {
- expect(component.state().value).to.be.equal('010');
- expect(component.state().selectionRange).to.deep.equal([2, 2]);
- done();
- });
- });
- });
-
- it('should keep selection in the back', (done) => {
- const component = render({ value: '' });
-
- for (let i = 0; i < 12; i++) {
- keyPress(getInputRef(component), createKeyEvent('1'));
- }
-
- component.setState({}, () => {
- expect(component.state().value).to.be.equal('111111111111');
- expect(component.state().selectionRange).to.deep.equal([12, 12]);
- done();
- });
- });
-
- it('should advance selection on insertion', (done) => {
- const component = render({
- value: '0000',
- });
- component.setState({ selectionRange: [1, 1] }, () => {
- keyPress(getInputRef(component), createKeyEvent('1'));
-
- component.setState({}, () => {
- expect(component.state().value).to.be.equal('01000');
- expect(component.state().selectionRange).to.deep.equal([2, 2]);
- done();
- });
- });
- });
-
- it('should not do anything when nothing to remove', (done) => {
- const component = render({
- value: '0000',
- });
- component.setState({ selectionRange: [0, 0] }, () => {
- keyPress(getInputRef(component), createKeyEvent('Backspace'));
-
- component.setState({}, () => {
- expect(component.state().value).to.be.equal('0000');
- expect(component.state().selectionRange).to.deep.equal([0, 0]);
- done();
- });
- });
- });
-});
-
-function getComponent(container, testName) {
- return container.findWhere((n) => n.prop('testName') === testName);
-}
-
-function keyPress(component, key) {
- component.prop('onKeyPress')(key);
-}