Skip to content

Commit c2eb687

Browse files
committed
Wrote some tests for the metadata access
1 parent 3c22ae8 commit c2eb687

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/lib/ChatBot.spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import FloatButton from '../../lib/FloatButton';
88
import Header from '../../lib/Header';
99
import HeaderIcon from '../../lib/HeaderIcon';
1010
import { CloseIcon } from '../../lib/icons';
11+
import Bubble from '../../lib/steps/text/Bubble';
12+
import { TextStep } from '../../lib/steps';
1113
// import { TextStep, OptionsStep, CustomStep } from '../../lib/steps';
1214

1315
const CustomComponent = () => (
@@ -289,4 +291,50 @@ describe('ChatBot', () => {
289291
expect(wrapper.find('input.rsc-input')).to.have.length(0);
290292
});
291293
});
294+
295+
describe('Metadata', () => {
296+
const wrapper = mount(
297+
<ChatBot
298+
botDelay={0}
299+
steps={[
300+
{
301+
id: '1',
302+
message: 'Set metadata!',
303+
metadata: {
304+
custom: 'Hello World',
305+
},
306+
trigger: '2',
307+
},
308+
{
309+
id: '2',
310+
message: params => (params.steps[1].metadata.custom),
311+
end: true,
312+
},
313+
]}
314+
/>,
315+
);
316+
317+
before(() => {
318+
// Somehow it needs something like this, to wait for the application to be rendered.
319+
// TODO: improve this...
320+
wrapper.simulate('keyPress', { key: 'Enter' });
321+
});
322+
323+
after(() => {
324+
wrapper.unmount();
325+
});
326+
327+
it('should be accessible in "steps" and "previousStep"', () => {
328+
const bubbles = wrapper.find(TextStep);
329+
const step2Bubble = bubbles.at(1);
330+
expect(step2Bubble.props().previousStep.metadata.custom).to.be.equal('Hello World');
331+
expect(step2Bubble.props().steps[1].metadata.custom).to.be.equal('Hello World');
332+
});
333+
334+
it('should render in second bubble', () => {
335+
const bubbles = wrapper.find(TextStep);
336+
const step2Bubble = bubbles.at(1);
337+
expect(step2Bubble.text()).to.be.equal('Hello World');
338+
});
339+
});
292340
});

0 commit comments

Comments
 (0)