signupProducts.spec.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* eslint-env jest */
  2. import Vue from 'vue'
  3. import ElementUI from 'element-ui'
  4. import path from 'path'
  5. import { toThousandFilter } from '@/filters'
  6. import { load } from '@/ui-refactor/views/purchase/__tests__/loadComponent'
  7. jest.mock('@/utils/usersInfo', () => ({}))
  8. jest.mock('@/api/user', () => ({}))
  9. jest.mock('@/utils/request', () => jest.fn())
  10. Vue.use(ElementUI)
  11. Vue.filter('toThousandFilter', toThousandFilter)
  12. const Products = load(path.resolve('src/ui-refactor/views/signup/components/SignupProducts.vue'))
  13. const SignupPage = load(path.resolve('src/ui-refactor/views/welcome-pack/welcomePackModes.js')).default.guest
  14. it.each([
  15. [undefined, 27000, 32400, 'NGN 27,000'],
  16. [false, 27000, 32400, 'NGN 27,000'],
  17. [true, 27000, 32400, 'NGN 32,400'],
  18. [true, 27000, '32400', 'NGN 32,400'],
  19. [true, 27000, 0, 'NGN 0']
  20. ])('uses market price only when requested (%s)', (useMarketPrice, sellPrice, marketPrice, expected) => {
  21. const vm = new Vue({
  22. ...Products,
  23. propsData: {
  24. items: [{ ID: 'sample', CODE: 'NGN', SELL_PRICE: sellPrice, MARKET_PRICE: marketPrice }],
  25. quantities: [1], selectedIds: [], subtotal: 0, bv: 0, tax: 0, useMarketPrice
  26. }
  27. }).$mount()
  28. try {
  29. expect(vm.$el.querySelector('.ng-signup-product-price strong').textContent).toBe(expected)
  30. } finally { vm.$destroy() }
  31. })
  32. it('keeps registration cards, totals and product details on market price', async() => {
  33. const vm = new Vue({
  34. ...SignupPage,
  35. components: { ...SignupPage.components, RouterLink: { render: h => h('a') }},
  36. beforeCreate() { this.$route = { query: {}} }
  37. }).$mount()
  38. document.body.appendChild(vm.$el)
  39. try {
  40. vm.checkedReferrer = vm.form.recUserName = 'VERIFIED-REFERRER'
  41. vm.referrerCountryId = vm.form.countryId = '620699181539139625'
  42. vm.tableData = [{ ID: 'sample', GOODS_NAME: 'Sample product', GOODS_NO: 'SKU1', CODE: 'NGN', SELL_PRICE: 27000, MARKET_PRICE: 32400, TAX_RATE: 7.5, PRICE_PV: 10, STORE_NUMS: 5 }]
  43. vm.storeNums = [1]
  44. vm.currencyUnitCode = 'NGN'
  45. await Vue.nextTick()
  46. expect(vm.$el.querySelector('.ng-signup-product-price strong').textContent).toBe('NGN 32,400')
  47. vm.$el.querySelector('.ng-signup-product-add').click()
  48. await Vue.nextTick()
  49. expect(vm.sellPriceSum).toBe('32400.00')
  50. vm.$el.querySelector('.ng-signup-product-view').click()
  51. await Vue.nextTick()
  52. const details = document.body.querySelector('.ng-product-details-dialog')
  53. expect(details.textContent).toContain('NGN 32,400')
  54. expect(details.textContent).not.toContain('Sales Price')
  55. expect(details.textContent).not.toContain('NGN 27,000')
  56. } finally { vm.$destroy(); vm.$el.remove() }
  57. })
  58. it.each([
  59. [0, '0', true],
  60. ['0', '0', true],
  61. [22, '22', false],
  62. ['3', '3', false],
  63. [undefined, '—', false],
  64. [null, '—', false]
  65. ])('displays STORE_NUMS=%s above View product without treating missing stock as zero', (quantity, text, empty) => {
  66. const vm = new Vue({
  67. ...Products,
  68. propsData: {
  69. items: [{ ID: 'sample', GOODS_NAME: 'Sample product', STORE_NUMS: quantity }],
  70. quantities: [1], selectedIds: [], subtotal: 0, bv: 0, tax: 0
  71. }
  72. }).$mount()
  73. try {
  74. const stock = vm.$el.querySelector('.ng-signup-product-stock')
  75. expect(stock).not.toBeNull()
  76. expect(stock.textContent.trim()).toBe('Stock: ' + text)
  77. expect(stock.classList.contains('is-out-of-stock')).toBe(empty)
  78. expect(stock.nextElementSibling.textContent).toContain('View product')
  79. expect(vm.$el.querySelector('.ng-signup-product-add').disabled).toBe(false)
  80. } finally {
  81. vm.$destroy()
  82. }
  83. })