1
|
|
|
/** |
2
|
|
|
* Created by Emmy on 10/8/2017. |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
import * as HOOKS from '../../utilities/hooks' |
6
|
|
|
import {getElem, nodeLength} from '../../utilities/helpers' |
|
|
|
|
7
|
|
|
import { assert, expect } from 'chai' |
8
|
|
|
import Vue from 'vue' |
9
|
|
|
import Promise from 'promise-polyfill' |
10
|
|
|
|
11
|
|
|
Vue.config.productionTip = false |
12
|
|
|
|
13
|
|
|
describe('Calling "confirm()"', function () { |
14
|
|
|
let dg |
15
|
|
|
|
16
|
|
|
before(HOOKS.sanitizeAndPrepareWindow) |
17
|
|
|
before(function (done) { |
18
|
|
|
dg = window.vm.triggerConfirm() |
19
|
|
|
Vue.nextTick(done) // be sure done has updated before proceeding |
20
|
|
|
}) |
21
|
|
|
|
22
|
|
|
it('Should return a promise', function () { |
23
|
|
|
expect(dg).to.be.instanceOf(Promise) |
24
|
|
|
}) |
25
|
|
|
|
26
|
|
|
it('Should make the dialog visible', function () { |
27
|
|
|
assert.strictEqual(nodeLength('.dg-container'), 1) |
28
|
|
|
}) |
29
|
|
|
|
30
|
|
|
it('Should make the ok button visible', function () { |
31
|
|
|
assert.strictEqual(nodeLength('.dg-btn--ok'), 1) |
32
|
|
|
}) |
33
|
|
|
|
34
|
|
|
it('Should make the cancel button visible', function () { |
35
|
|
|
assert.strictEqual(nodeLength('.dg-btn--cancel'), 1) |
36
|
|
|
}) |
37
|
|
|
}) |
38
|
|
|
|
39
|
|
|
describe('Clicking \'ok\' on #confirm()', function () { |
40
|
|
|
beforeEach(HOOKS.sanitizeAndPrepareWindow) |
41
|
|
|
|
42
|
|
|
it('Should resolve the promise', function (done) { |
43
|
|
|
window.vm.triggerConfirm().then(() => {done()}) // expected |
44
|
|
|
Vue.nextTick(() => window.vm.clickDialogBtn('ok')) |
45
|
|
|
}) |
46
|
|
|
}) |
47
|
|
|
|
48
|
|
|
describe('Clicking \'cancel\' on #confirm()', function () { |
49
|
|
|
beforeEach(HOOKS.sanitizeAndPrepareWindow) |
50
|
|
|
|
51
|
|
|
it('Should reject the promise', function (done) { |
52
|
|
|
window.vm.triggerConfirm() |
53
|
|
|
.then(() => {done(new Error('Cancel button should Reject promise'))}) |
54
|
|
|
.catch(() => {done()}) // expected |
55
|
|
|
Vue.nextTick(() => window.vm.clickDialogBtn('cancel')) |
56
|
|
|
}) |
57
|
|
|
}) |