blessing-skin-server/resources/assets/tests/js/notify.test.js

45 lines
1018 B
JavaScript
Raw Normal View History

2019-03-15 11:42:41 +08:00
import $ from 'jquery'
import Swal from 'sweetalert2'
import * as notify from '@/js/notify'
2018-09-07 23:58:00 +08:00
2019-02-19 16:37:29 +08:00
jest.mock('sweetalert2', () => ({
2019-03-15 11:42:41 +08:00
mixin() {
return this
},
fire() {},
}))
2019-02-19 16:37:29 +08:00
2018-09-07 23:58:00 +08:00
test('show message', () => {
2019-03-15 11:42:41 +08:00
document.body.innerHTML = '<div id=msg class="callout-x"></div>'
notify.showMsg('hi')
const element = $('#msg')
expect(element.hasClass('callout')).toBeTrue()
expect(element.hasClass('callout-info')).toBeTrue()
expect(element.html()).toBe('hi')
})
2019-03-17 10:21:18 +08:00
2018-09-07 23:58:00 +08:00
test('show AJAX error', () => {
2019-03-15 11:42:41 +08:00
$.fn.modal = function () {
document.body.innerHTML = this.html()
}
notify.showAjaxError(new Error('an-error'))
expect(document.body.innerHTML).toContain('an-error')
})
2019-03-17 10:21:18 +08:00
2018-09-07 23:58:00 +08:00
test('show modal', () => {
2019-03-15 11:42:41 +08:00
notify.showModal('message')
expect($('.modal-title').html()).toBe('Message')
notify.showModal('message', '', 'default', {
callback: () => undefined,
destroyOnClose: false,
})
})
2019-03-17 10:21:18 +08:00
2019-02-19 16:37:29 +08:00
test('show sweetalert', () => {
2019-03-15 11:42:41 +08:00
jest.spyOn(Swal, 'fire')
notify.swal({})
expect(Swal.fire).toBeCalled()
})