File size: 1,927 Bytes
f2bee8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react';
import {mountWithIntl} from '../../helpers/intl-helpers.jsx';

// Mock this utility because it uses dynamic imports that do not work with jest
jest.mock('../../../src/lib/libraries/decks/translate-image.js', () => {});

import Cards, {ImageStep, VideoStep} from '../../../src/components/cards/cards.jsx';

describe('Cards component', () => {
    const defaultProps = () => ({
        activeDeckId: 'id1',
        content: {
            id1: {
                name: 'id1 - name',
                img: 'id1 - img',
                steps: [{video: 'videoUrl'}]
            }
        },
        dragging: false,
        expanded: true,
        isRtl: false,
        locale: 'en',
        onActivateDeckFactory: jest.fn(),
        onCloseCards: jest.fn(),
        onDrag: jest.fn(),
        onEndDrag: jest.fn(),
        onNextStep: jest.fn(),
        onPrevStep: jest.fn(),
        onShowAll: jest.fn(),
        onShrinkExpandCards: jest.fn(),
        onStartDrag: jest.fn(),
        showVideos: true,
        step: 0,
        x: 0,
        y: 0
    });

    test('showVideos=true shows the video step', () => {
        const component = mountWithIntl(
            <Cards
                {...defaultProps()}
                showVideos
            />
        );
        expect(component.find(ImageStep).exists()).toEqual(false);
        expect(component.find(VideoStep).exists()).toEqual(true);
    });

    test('showVideos=false shows the title image/name instead of video step', () => {
        const component = mountWithIntl(
            <Cards
                {...defaultProps()}
                showVideos={false}
            />
        );
        expect(component.find(VideoStep).exists()).toEqual(false);

        const imageStep = component.find(ImageStep);
        expect(imageStep.props().image).toEqual('id1 - img');
        expect(imageStep.props().title).toEqual('id1 - name');
    });
});