aboutsummaryrefslogtreecommitdiff
path: root/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
commitde98e0b232509d5f40c135d540a70e415272ff85 (patch)
treea79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test
parente0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff)
node_modules
Diffstat (limited to 'node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test')
-rw-r--r--node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/App.tests.tsx32
-rw-r--r--node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/Greeting.tests.tsx45
-rw-r--r--node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/WhoToGreet.tests.tsx68
-rw-r--r--node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/main.js5
4 files changed, 150 insertions, 0 deletions
diff --git a/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/App.tests.tsx b/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/App.tests.tsx
new file mode 100644
index 000000000..aa9612416
--- /dev/null
+++ b/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/App.tests.tsx
@@ -0,0 +1,32 @@
+import React from 'react';
+import TestUtils from 'react-addons-test-utils';
+
+import App from '../../src/components/App';
+import WhoToGreet from '../../src/components/WhoToGreet';
+import Greeting from '../../src/components/Greeting';
+import GreetingStore from '../../src/stores/GreetingStore';
+
+describe('App', () => {
+ it('renders expected HTML', () => {
+ const app = render({ greetings: ['James'], newGreeting: 'Benjamin' });
+ expect(app).toEqual(
+ <div className="container-fluid">
+ <h1>Hello People!</h1>
+
+ <WhoToGreet newGreeting={ 'Benjamin' } />
+
+ { [
+ <Greeting key={ 0 } targetOfGreeting="James" />
+ ] }
+ </div>
+ );
+ });
+
+ function render(state: any) {
+ const shallowRenderer = TestUtils.createRenderer();
+ spyOn(GreetingStore, 'getState').and.returnValue(state);
+
+ shallowRenderer.render(<App />);
+ return shallowRenderer.getRenderOutput();
+ }
+});
diff --git a/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/Greeting.tests.tsx b/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/Greeting.tests.tsx
new file mode 100644
index 000000000..911a6cba2
--- /dev/null
+++ b/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/Greeting.tests.tsx
@@ -0,0 +1,45 @@
+import React from 'react';
+import TestUtils from 'react-addons-test-utils';
+
+import Greeting from '../../src/components/Greeting';
+import * as GreetingActions from '../../src/actions/GreetingActions';
+
+describe('Greeting', () => {
+ let handleSelectionChangeSpy: jasmine.Spy;
+ beforeEach(() => {
+ handleSelectionChangeSpy = jasmine.createSpy('handleSelectionChange');
+ });
+
+ it('given a targetOfGreeting of \'James\' it renders a p containing a greeting and a remove button', () => {
+ const targetOfGreeting = 'James';
+
+ const p = render({ targetOfGreeting });
+ expect(p.type).toBe('p');
+ expect(p.props.children[0]).toBe('Hello ');
+ expect(p.props.children[1]).toBe('James');
+ expect(p.props.children[2]).toBe('!');
+
+ const [ , , , button ] = p.props.children;
+
+ expect(button.type).toBe('button');
+ expect(button.props.className).toBe('btn btn-default btn-danger');
+ expect(button.props.children).toBe('Remove');
+ });
+
+ it('button onClick triggers an removeGreeting action', () => {
+ const targetOfGreeting = 'Benjamin';
+ const p = render({ targetOfGreeting });
+ const [ , , , button ] = p.props.children;
+ spyOn(GreetingActions, 'removeGreeting');
+
+ button.props.onClick();
+
+ expect(GreetingActions.removeGreeting).toHaveBeenCalledWith(targetOfGreeting);
+ });
+
+ function render({ targetOfGreeting }: { targetOfGreeting: string; }) {
+ const shallowRenderer = TestUtils.createRenderer();
+ shallowRenderer.render(<Greeting key={ 0 } targetOfGreeting={ targetOfGreeting } />);
+ return shallowRenderer.getRenderOutput();
+ }
+});
diff --git a/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/WhoToGreet.tests.tsx b/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/WhoToGreet.tests.tsx
new file mode 100644
index 000000000..01398952e
--- /dev/null
+++ b/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/components/WhoToGreet.tests.tsx
@@ -0,0 +1,68 @@
+import React from 'react';
+import TestUtils from 'react-addons-test-utils';
+
+import WhoToGreet from '../../src/components/WhoToGreet';
+import * as GreetingActions from '../../src/actions/GreetingActions';
+
+describe('WhoToGreet', () => {
+ let handleSelectionChangeSpy: jasmine.Spy;
+ beforeEach(() => {
+ handleSelectionChangeSpy = jasmine.createSpy('handleSelectionChange');
+ });
+
+ it('given a newGreeting then it renders a form containing an input containing that text and an add button', () => {
+ const newGreeting = 'James';
+
+ const form = render({ newGreeting });
+ expect(form.type).toBe('form');
+ expect(form.props.role).toBe('form');
+
+ const formGroup = form.props.children;
+ expect(formGroup.type).toBe('div');
+ expect(formGroup.props.className).toBe('form-group');
+
+ const [ input, button ] = formGroup.props.children;
+
+ expect(input.type).toBe('input');
+ expect(input.props.type).toBe('text');
+ expect(input.props.className).toBe('form-control');
+ expect(input.props.placeholder).toBe('Who would you like to greet?');
+ expect(input.props.value).toBe(newGreeting);
+
+ expect(button.type).toBe('button');
+ expect(button.props.type).toBe('submit');
+ expect(button.props.className).toBe('btn btn-default btn-primary');
+ expect(button.props.disabled).toBe(false);
+ expect(button.props.children).toBe('Add greeting');
+ });
+
+ it('input onChange triggers a newGreetingChanged action', () => {
+ const newGreeting = 'Benjamin';
+ const form = render({ newGreeting });
+ const formGroup = form.props.children;
+ const [ input ] = formGroup.props.children;
+ spyOn(GreetingActions, 'newGreetingChanged');
+
+ input.props.onChange({ target: { value: newGreeting }});
+
+ expect(GreetingActions.newGreetingChanged).toHaveBeenCalledWith(newGreeting);
+ });
+
+ it('button onClick triggers an addGreeting action', () => {
+ const newGreeting = 'Benjamin';
+ const form = render({ newGreeting });
+ const formGroup = form.props.children;
+ const [ , button ] = formGroup.props.children;
+ spyOn(GreetingActions, 'addGreeting');
+
+ button.props.onClick({ preventDefault: () => {} });
+
+ expect(GreetingActions.addGreeting).toHaveBeenCalledWith(newGreeting);
+ });
+
+ function render({ newGreeting }: { newGreeting: string }) {
+ const shallowRenderer = TestUtils.createRenderer();
+ shallowRenderer.render(<WhoToGreet newGreeting={ newGreeting } />);
+ return shallowRenderer.getRenderOutput();
+ }
+});
diff --git a/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/main.js b/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/main.js
new file mode 100644
index 000000000..1b332a7c0
--- /dev/null
+++ b/node_modules/ts-loader/examples/webpack2-gulp-react-flux-babel-karma/test/main.js
@@ -0,0 +1,5 @@
+/* eslint-disable */
+import 'babel-polyfill';
+
+const testsContext = require.context('./', true, /\.tests\.ts(x?)$/);
+testsContext.keys().forEach(testsContext); \ No newline at end of file