Skip to content

Commit efd890f

Browse files
authored
Merge pull request #2 from americanexpress/feature/docs-update
Internal refactor and docs clarification
2 parents 15f2c6a + 9b82bb9 commit efd890f

File tree

9 files changed

+133
-82
lines changed

9 files changed

+133
-82
lines changed

README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,27 @@ const Simple = () =>
2020
<Steps>
2121
<Step path="firstStep">
2222
<h1>First Step</h1>
23-
<Navigation render={({ next }) => <button onClick={next}>Next</button>} />
23+
<Navigation
24+
render={({ next }) =>
25+
<button onClick={next}>Next</button>}
26+
/>
2427
</Step>
2528
<Step path="secondStep">
2629
<h1>Second Step</h1>
27-
<Navigation render={({ next }) => <button onClick={next}>Next</button>} />
28-
<Navigation render={({ previous }) => <button onClick={previous}>Previous</button>} />
30+
<Navigation
31+
render={({ next, previous }) =>
32+
<div>
33+
<button onClick={next}>Next</button>
34+
<button onClick={previous}>Previous</button>
35+
</div>}
36+
/>
2937
</Step>
3038
<Step path="thirdStep">
3139
<h1>Third Step</h1>
32-
<Navigation render={({ previous }) => <button onClick={previous}>Previous</button>} />
40+
<Navigation
41+
render={({ previous }) =>
42+
<button onClick={previous}>Previous</button>}
43+
/>
3344
</Step>
3445
</Steps>
3546
</Wizard>;
@@ -77,9 +88,9 @@ Wraps all the content that will be conditionally shown when the step is active.
7788

7889
#### Props
7990
##### `path`: string
80-
Unique string for each component, if `routed`, this will be used as the path in the URL.
91+
Unique key for each step.
8192
##### `name`: string *(optional)*
82-
A name for the step that can be used in the `<Progress>` component in order to display step titles.
93+
A name for the step that can later be accessed on [`context.wizard`](#contextwizard).
8394
##### `className`: string *(optional)*
8495
CSS classes to be added to the `<div>` created by `<Step>`.
8596

@@ -95,7 +106,7 @@ An object describing the current step with the signature: `{ path: string, name:
95106
---
96107

97108
### `<Navigation>`
98-
Wrapper component for the Navigation of your `<Step>`. Extends its child's props with [`context.wizard`](#contextwizard) and passes [`context.wizard`](#contextwizard) to its render prop.
109+
Exposes the Wizard navigation functionality for your components to use. Extends its child's props with [`context.wizard`](#contextwizard) and passes [`context.wizard`](#contextwizard) to its render prop.
99110
#### Props
100111
##### `render(wizard)`: function *(optional)*
101112
A function that will be used as the render function of `<Navigation>`.
@@ -130,11 +141,11 @@ import React from 'react';
130141
import { Route } from 'react-router-dom';
131142
import { Wizard } from 'react-albus';
132143

133-
const RoutedWizard = () =>
144+
const RoutedWizard = ({ children }) =>
134145
<Route
135-
render={({ match: { url }, history }) =>
146+
render={({ history, match: { url } }) =>
136147
<Wizard history={history} basename={url}>
137-
...
148+
{children}
138149
</Wizard>}
139150
/>;
140151

__tests__/components/Steps.spec.jsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import { Steps } from '../../src';
2020
const FakeStep = () => <div />;
2121

2222
describe('Steps', () => {
23-
it('should call _setSteps', () => {
23+
it('should call _init', () => {
2424
const context = {
2525
wizard: {
26-
_setSteps: jest.fn(),
2726
steps: [],
2827
},
28+
wizardInit: jest.fn(),
2929
};
3030

3131
shallow(
@@ -34,20 +34,19 @@ describe('Steps', () => {
3434
</Steps>,
3535
{ context },
3636
);
37-
// eslint-disable-next-line no-underscore-dangle
38-
expect(context.wizard._setSteps).toHaveBeenCalled();
37+
expect(context.wizardInit).toHaveBeenCalled();
3938
});
4039

41-
it('should not call _setSteps if wizard already has steps', () => {
40+
it('should not call _init if wizard already has steps', () => {
4241
const context = {
4342
wizard: {
44-
_setSteps: jest.fn(),
4543
steps: [
4644
'we',
4745
'have',
4846
'steps',
4947
],
5048
},
49+
wizardInit: jest.fn(),
5150
};
5251

5352
shallow(
@@ -56,8 +55,7 @@ describe('Steps', () => {
5655
</Steps>,
5756
{ context },
5857
);
59-
// eslint-disable-next-line no-underscore-dangle
60-
expect(context.wizard._setSteps).not.toHaveBeenCalled();
58+
expect(context.wizardInit).not.toHaveBeenCalled();
6159
});
6260

6361
it('should render correct child if controlled', () => {

__tests__/components/Wizard.spec.jsx

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,39 @@
1212
* the License.
1313
*/
1414

15-
import React from 'react';
15+
import React, { PropTypes } from 'react';
1616
import { mount } from 'enzyme';
1717

1818
import { Wizard } from '../../src';
1919

20+
const ExposeWizard = ({ children }, context) => children(context);
21+
ExposeWizard.contextTypes = {
22+
wizard: PropTypes.object,
23+
wizardInit: PropTypes.func,
24+
};
25+
2026
describe('Wizard', () => {
2127
let mounted;
22-
let setSteps;
28+
let init;
2329
let step;
2430
let next;
2531
let previous;
2632
let push;
2733
let go;
2834

29-
describe('without render prop', () => {
35+
describe('with render prop', () => {
3036
beforeEach(() => {
3137
const history = {
3238
replace: () => null,
3339
listen: () => () => null,
3440
};
3541

3642
mounted = mount(
37-
<Wizard history={history} />,
43+
<Wizard history={history} render={() => null} />,
3844
);
3945
});
4046

41-
it('should render without steps', () => {
47+
it('should render', () => {
4248
expect(mounted).toMatchSnapshot();
4349
});
4450

@@ -50,27 +56,31 @@ describe('Wizard', () => {
5056
describe('with no other props', () => {
5157
beforeEach(() => {
5258
mounted = mount(
53-
<Wizard
54-
render={({
55-
_setSteps,
56-
step: wizardStep,
57-
next: wizardNext,
58-
previous: wizardPrevious,
59-
push: wizardPush,
60-
go: wizardGo,
61-
}) => {
62-
setSteps = _setSteps;
63-
step = wizardStep;
64-
next = wizardNext;
65-
previous = wizardPrevious;
66-
push = wizardPush;
67-
go = wizardGo;
68-
return <noscript />;
69-
}}
70-
/>,
59+
<Wizard>
60+
<ExposeWizard>
61+
{({
62+
wizard: {
63+
step: wizardStep,
64+
next: wizardNext,
65+
previous: wizardPrevious,
66+
push: wizardPush,
67+
go: wizardGo,
68+
},
69+
wizardInit,
70+
}) => {
71+
step = wizardStep;
72+
next = wizardNext;
73+
previous = wizardPrevious;
74+
push = wizardPush;
75+
go = wizardGo;
76+
init = wizardInit;
77+
return null;
78+
}}
79+
</ExposeWizard>
80+
</Wizard>,
7181
);
7282

73-
setSteps([
83+
init([
7484
{ path: 'gryffindor' },
7585
{ path: 'slytherin' },
7686
]);
@@ -119,20 +129,23 @@ describe('Wizard', () => {
119129

120130
beforeEach(() => {
121131
mounted = mount(
122-
<Wizard
123-
onNext={onNext}
124-
render={({
125-
_setSteps,
126-
next: wizardNext,
127-
}) => {
128-
setSteps = _setSteps;
129-
next = wizardNext;
130-
return <noscript />;
131-
}}
132-
/>,
132+
<Wizard onNext={onNext}>
133+
<ExposeWizard>
134+
{({
135+
wizard: {
136+
next: wizardNext,
137+
},
138+
wizardInit,
139+
}) => {
140+
next = wizardNext;
141+
init = wizardInit;
142+
return null;
143+
}}
144+
</ExposeWizard>
145+
</Wizard>,
133146
);
134147

135-
setSteps([
148+
init([
136149
{ path: 'gryffindor' },
137150
{ path: 'slytherin' },
138151
]);
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Wizard without render prop should render without steps 1`] = `
3+
exports[`Wizard with render prop should render 1`] = `
44
<Wizard
55
basename=""
66
className=""
@@ -11,10 +11,6 @@ exports[`Wizard without render prop should render without steps 1`] = `
1111
}
1212
}
1313
onNext={null}
14-
render={null}
15-
>
16-
<div
17-
className=""
18-
/>
19-
</Wizard>
14+
render={[Function]}
15+
/>
2016
`;

__tests__/utils/index.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2017 American Express Travel Related Services Company, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
import fixPath from '../../src/utils';
16+
17+
describe('fixPath', () => {
18+
it('should remove duplicate forward slashes', () => {
19+
const path = 'path//to/something';
20+
const fixedPath = fixPath(path);
21+
expect(fixedPath).toBe('path/to/something');
22+
});
23+
});

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
"posttest": "npm run lint",
1717
"prepublish": "npm run build"
1818
},
19-
"repository": {
20-
"type": "git",
21-
"url": "https://github.com/americanexpress/react-albus.git"
22-
},
19+
"repository": "americanexpress/react-albus",
2320
"keywords": [
2421
"react",
2522
"react-component",

src/components/Steps.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import React, { Component, PropTypes } from 'react';
1616

1717
class Steps extends Component {
1818
componentWillMount() {
19-
const { wizard } = this.context;
19+
const { wizard, wizardInit } = this.context;
2020

2121
// Register steps with Wizard if they're not already registered
2222
if (wizard && !wizard.steps.length) {
2323
const steps = React.Children.map(this.props.children, child => ({
2424
path: child.props.path,
2525
name: child.props.name,
2626
}));
27-
this.context.wizard._setSteps(steps); // eslint-disable-line no-underscore-dangle
27+
wizardInit(steps);
2828
}
2929
}
3030

@@ -50,6 +50,7 @@ Steps.defaultProps = {
5050

5151
Steps.contextTypes = {
5252
wizard: PropTypes.object,
53+
wizardInit: PropTypes.func,
5354
};
5455

5556
export default Steps;

0 commit comments

Comments
 (0)