@@ -8,6 +8,8 @@ import FloatButton from '../../lib/FloatButton';
88import Header from '../../lib/Header' ;
99import HeaderIcon from '../../lib/HeaderIcon' ;
1010import { 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
1315const 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