Simon Egersand
2018-02-11 a392b22565203e69feb2c36bd556d039bd5640a2
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import React from 'react'; // eslint-disable-line no-unused-vars
import { mount, shallow } from 'enzyme';
import Datetime from '../DateTime'; // eslint-disable-line no-unused-vars
 
const _simulateClickOnElement = (element) => {
    if (element.length === 0) {
        // eslint-disable-next-line no-console
        console.warn('Element not clicked since it doesn\'t exist');
        return;
    }
    return element.simulate('click');
};
 
module.exports = {
    createDatetime: (props) => {
        return mount(<Datetime {...props} />);
    },
 
    createDatetimeShallow: (props) => {
        return shallow(<Datetime {...props} />);
    },
 
    /*
     * Click Simulations
     */
    openDatepicker: (datetime) => {
        datetime.find('.form-control').simulate('focus');
    },
 
    clickOnElement: (element) => {
        return _simulateClickOnElement(element);
    },
 
    clickNthDay: (datetime, n) => {
        return _simulateClickOnElement(datetime.find('.rdtDay').at(n));
    },
 
    clickNthMonth: (datetime, n) => {
        return _simulateClickOnElement(datetime.find('.rdtMonth').at(n));
    },
 
    clickNthYear: (datetime, n) => {
        return _simulateClickOnElement(datetime.find('.rdtYear').at(n));
    },
 
    /*
     * Boolean Checks
     */
    isOpen: (datetime) => {
        return datetime.find('.rdt.rdtOpen').length === 1;
    },
 
    isDayView: (datetime) => {
        return datetime.find('.rdtPicker .rdtDays').length === 1;
    },
 
    isMonthView: (datetime) => {
        return datetime.find('.rdtPicker .rdtMonths').length === 1;
    },
 
    isYearView: (datetime) => {
        return datetime.find('.rdtPicker .rdtYears').length === 1;
    },
 
    isTimeView: (datetime) => {
        return datetime.find('.rdtPicker .rdtTime').length === 1;
    },
 
    /*
     * Change Time Values
     *
     * These functions only work when the time view is open
     */
    increaseHour: (datetime) => {
        datetime.find('.rdtCounter .rdtBtn').at(0).simulate('mouseDown');
    },
 
    decreaseHour: (datetime) => {
        datetime.find('.rdtCounter .rdtBtn').at(1).simulate('mouseDown');
    },
 
    increaseMinute: (datetime) => {
        datetime.find('.rdtCounter .rdtBtn').at(2).simulate('mouseDown');
    },
 
    decreaseMinute: (datetime) => {
        datetime.find('.rdtCounter .rdtBtn').at(3).simulate('mouseDown');
    },
 
    increaseSecond: (datetime) => {
        datetime.find('.rdtCounter .rdtBtn').at(4).simulate('mouseDown');
    },
 
    decreaseSecond: (datetime) => {
        datetime.find('.rdtCounter .rdtBtn').at(5).simulate('mouseDown');
    },
 
    /*
     * Get Values
     */
    getNthDay: (datetime, n) => {
        return datetime.find('.rdtDay').at(n);
    },
 
    getNthMonth: (datetime, n) => {
        return datetime.find('.rdtMonth').at(n);
    },
 
    getNthYear: (datetime, n) => {
        return datetime.find('.rdtYear').at(n);
    },
 
    getHours: (datetime) => {
        return datetime.find('.rdtCount').at(0).text();
    },
 
    getMinutes: (datetime) => {
        return datetime.find('.rdtCount').at(1).text();
    },
 
    getSeconds: (datetime) => {
        return datetime.find('.rdtCount').at(2).text();
    },
 
    getInputValue: (datetime) => {
        return datetime.find('.rdt > .form-control').getDOMNode().value;
    },
 
    getViewDateValue: (datetime) => {
        return datetime.find('.rdtSwitch').getDOMNode().innerHTML;
    }
};