paystackPaymentDialog.spec.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* eslint-env jest */
  2. import Vue from 'vue'
  3. import ElementUI from 'element-ui'
  4. import path from 'path'
  5. import { load } from '@/ui-refactor/views/purchase/__tests__/loadComponent'
  6. jest.mock('@/utils/usersInfo', () => ({}))
  7. Vue.use(ElementUI)
  8. const PaymentDialog = load(path.resolve('src/ui-refactor/components/PaystackPaymentDialog.vue'))
  9. const instances = []
  10. async function settle() { await Vue.nextTick(); jest.advanceTimersByTime(350); await Vue.nextTick() }
  11. beforeEach(() => jest.useFakeTimers())
  12. afterEach(() => {
  13. instances.splice(0).forEach(vm => { vm.$destroy(); vm.$el.remove() })
  14. jest.clearAllTimers()
  15. jest.useRealTimers()
  16. })
  17. it('shows payment details without email input and delegates payment and cancellation', async() => {
  18. const continued = jest.fn()
  19. const cancelled = jest.fn()
  20. const vm = new Vue({
  21. data: () => ({ visible: true, loading: false }),
  22. render(h) {
  23. return h(PaymentDialog, {
  24. props: { visible: this.visible, amount: 104000, currency: 'NGN', loading: this.loading },
  25. attrs: { 'before-close': cancelled, 'close-on-press-escape': false },
  26. on: { continue: continued }
  27. })
  28. }
  29. }).$mount()
  30. document.body.appendChild(vm.$el)
  31. instances.push(vm)
  32. await settle()
  33. expect(vm.$el.querySelector('input')).toBeNull()
  34. expect(vm.$el.querySelector('.ng-paystack-payment-note').textContent).toBe('Continue to the Paystack secure checkout.')
  35. expect(vm.$el.querySelector('.ng-paystack-payment-amount').textContent).toContain('NGN 104,000')
  36. const button = vm.$el.querySelector('.ng-paystack-payment-continue')
  37. button.click()
  38. expect(continued).toHaveBeenCalledTimes(1)
  39. vm.loading = true
  40. await settle()
  41. expect(button.disabled).toBe(true)
  42. expect(vm.$el.querySelector('.el-dialog__headerbtn')).toBeNull()
  43. button.click()
  44. expect(continued).toHaveBeenCalledTimes(1)
  45. vm.loading = false
  46. await settle()
  47. vm.$el.querySelector('.el-dialog__headerbtn').click()
  48. expect(cancelled).toHaveBeenCalledTimes(1)
  49. expect(vm.visible).toBe(true)
  50. vm.visible = false
  51. await Vue.nextTick()
  52. button.click()
  53. expect(continued).toHaveBeenCalledTimes(1)
  54. })