Skip to content

Commit 8a9e3da

Browse files
committed
test(Copilot): Test for the step active flags
1 parent 5b4b8f2 commit 8a9e3da

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

src/hocs/copilot.test.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
import React from 'react';
23
import { View, Modal } from 'react-native';
34
import renderer from 'react-test-renderer';
@@ -8,12 +9,16 @@ import SvgMask from '../components/SvgMask';
89

910
const WalkthroughableView = walkthroughable(View);
1011

11-
const SampleComponent = () => (
12+
type SampleComponentProps = {
13+
secondStepActive?: boolean
14+
};
15+
16+
const SampleComponent = ({ secondStepActive }: SampleComponentProps) => (
1217
<View>
1318
<CopilotStep order={0} name="step-1" text="This is the description for the first step">
1419
<WalkthroughableView />
1520
</CopilotStep>
16-
<CopilotStep order={1} name="step-2" text="This is the description for the second step">
21+
<CopilotStep order={1} name="step-2" active={secondStepActive} text="This is the description for the second step">
1722
<WalkthroughableView />
1823
</CopilotStep>
1924
<CopilotStep order={3} name="step-3" text="This is the description for the third step">
@@ -22,6 +27,10 @@ const SampleComponent = () => (
2227
</View>
2328
);
2429

30+
SampleComponent.defaultProps = {
31+
secondStepActive: true,
32+
};
33+
2534
it('only renders the component within a wrapper as long as tutorial has not been started', () => {
2635
const CopilotComponent = copilot()(SampleComponent);
2736

@@ -134,3 +143,25 @@ it('shows the custom tooltip component if specified', async () => {
134143
expect(tooltip.props.currentStep).toHaveProperty('order');
135144
expect(tooltip.props.currentStep).toHaveProperty('text');
136145
});
146+
147+
it('skips a step if disabled', async () => {
148+
const CopilotComponent = copilot()(SampleComponent);
149+
150+
const tree = renderer.create(<CopilotComponent secondStepActive={false} />);
151+
await tree.root.findByType(SampleComponent).props.start();
152+
153+
const textComponent = tree.root.findByProps({
154+
testID: 'stepDescription',
155+
});
156+
157+
expect(textComponent.props.children).toBe('This is the description for the first step');
158+
159+
await tree.root.instance.next();
160+
161+
expect(textComponent.props.children).not.toBe('This is the description for the second step');
162+
expect(textComponent.props.children).toBe('This is the description for the third step');
163+
164+
await tree.root.instance.prev();
165+
166+
expect(textComponent.props.children).toBe('This is the description for the first step');
167+
});

0 commit comments

Comments
 (0)