Completed
Push — master ( e9cdde...e60414 )
by Ajeh
33s
created

test/unit/utilities/initializers.js   A

Complexity

Total Complexity 10
Complexity/F 2.5

Size

Lines of Code 46
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 0
wmc 10
c 3
b 0
f 0
nc 1
mnd 4
bc 9
fnc 4
dl 0
loc 46
rs 10
bpm 2.25
cpm 2.5
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
B initializers.js ➔ clickDialogBtn 0 19 7
A initializers.js ➔ setupVmWithLocalVue 0 21 1
1
/**
2
 * Created by Emmy on 10/11/2017.
3
 */
4
5
import Plugin from '../../../src/plugin/js/index'
6
import {clickNode} from '../../../src/plugin/js/utilities'
7
import {getElem} from './helpers'
8
import {createLocalVue} from 'vue-test-utils'
9
10
export function setupVmWithLocalVue() {
11
    let LocalVue = createLocalVue()
12
    LocalVue.config.productionTip = false
13
    LocalVue.use(Plugin)
14
15
    let node = document.createElement("div")
16
    node.id = 'app'
17
    document.querySelector('body').appendChild(node)
18
19
    return (new LocalVue({
20
        methods: {
21
            triggerAlert(){
22
                return this.$dialog.alert('Simple Alert')
23
            },
24
            triggerConfirm(){
25
                return this.$dialog.confirm('Please confirm')
26
            },
27
            clickDialogBtn
28
        }
29
    })).$mount(node)
30
}
31
32
function clickDialogBtn(dgBtn = 'ok', idx = null) {
33
    let selector = (dgBtn === 'ok') ? '.dg-btn--ok' : '.dg-btn--cancel'
34
    let node, nodes =  getElem(selector, true)
35
36
    if (nodes.length > 0) {
37
        if (idx === null) {
38
            // click the last
39
            clickNode(nodes[nodes.length - 1])
40
        } else if (idx === true) {
41
            // click all
42
            for (let i = 0; i < nodes.length; i++) {
43
                clickNode(nodes[i])
44
            }
45
        } else if (node = nodes[parseInt(idx)]) {
46
            // click at index
47
            clickNode(node)
48
        }
49
    }
50
}
51