| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /* eslint-env jest */
- import Vue from 'vue'
- import ElementUI from 'element-ui'
- import path from 'path'
- import { toThousandFilter } from '@/filters'
- import { load } from '@/ui-refactor/views/purchase/__tests__/loadComponent'
- jest.mock('@/utils/usersInfo', () => ({}))
- jest.mock('@/api/user', () => ({}))
- jest.mock('@/utils/request', () => jest.fn())
- Vue.use(ElementUI)
- Vue.filter('toThousandFilter', toThousandFilter)
- const Products = load(path.resolve('src/ui-refactor/views/signup/components/SignupProducts.vue'))
- const SignupPage = load(path.resolve('src/ui-refactor/views/welcome-pack/welcomePackModes.js')).default.guest
- it.each([
- [undefined, 27000, 32400, 'NGN 27,000'],
- [false, 27000, 32400, 'NGN 27,000'],
- [true, 27000, 32400, 'NGN 32,400'],
- [true, 27000, '32400', 'NGN 32,400'],
- [true, 27000, 0, 'NGN 0']
- ])('uses market price only when requested (%s)', (useMarketPrice, sellPrice, marketPrice, expected) => {
- const vm = new Vue({
- ...Products,
- propsData: {
- items: [{ ID: 'sample', CODE: 'NGN', SELL_PRICE: sellPrice, MARKET_PRICE: marketPrice }],
- quantities: [1], selectedIds: [], subtotal: 0, bv: 0, tax: 0, useMarketPrice
- }
- }).$mount()
- try {
- expect(vm.$el.querySelector('.ng-signup-product-price strong').textContent).toBe(expected)
- } finally { vm.$destroy() }
- })
- it('keeps registration cards, totals and product details on market price', async() => {
- const vm = new Vue({
- ...SignupPage,
- components: { ...SignupPage.components, RouterLink: { render: h => h('a') }},
- beforeCreate() { this.$route = { query: {}} }
- }).$mount()
- document.body.appendChild(vm.$el)
- try {
- vm.checkedReferrer = vm.form.recUserName = 'VERIFIED-REFERRER'
- vm.referrerCountryId = vm.form.countryId = '620699181539139625'
- 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 }]
- vm.storeNums = [1]
- vm.currencyUnitCode = 'NGN'
- await Vue.nextTick()
- expect(vm.$el.querySelector('.ng-signup-product-price strong').textContent).toBe('NGN 32,400')
- vm.$el.querySelector('.ng-signup-product-add').click()
- await Vue.nextTick()
- expect(vm.sellPriceSum).toBe('32400.00')
- vm.$el.querySelector('.ng-signup-product-view').click()
- await Vue.nextTick()
- const details = document.body.querySelector('.ng-product-details-dialog')
- expect(details.textContent).toContain('NGN 32,400')
- expect(details.textContent).not.toContain('Sales Price')
- expect(details.textContent).not.toContain('NGN 27,000')
- } finally { vm.$destroy(); vm.$el.remove() }
- })
- it.each([
- [0, '0', true],
- ['0', '0', true],
- [22, '22', false],
- ['3', '3', false],
- [undefined, '—', false],
- [null, '—', false]
- ])('displays STORE_NUMS=%s above View product without treating missing stock as zero', (quantity, text, empty) => {
- const vm = new Vue({
- ...Products,
- propsData: {
- items: [{ ID: 'sample', GOODS_NAME: 'Sample product', STORE_NUMS: quantity }],
- quantities: [1], selectedIds: [], subtotal: 0, bv: 0, tax: 0
- }
- }).$mount()
- try {
- const stock = vm.$el.querySelector('.ng-signup-product-stock')
- expect(stock).not.toBeNull()
- expect(stock.textContent.trim()).toBe('Stock: ' + text)
- expect(stock.classList.contains('is-out-of-stock')).toBe(empty)
- expect(stock.nextElementSibling.textContent).toContain('View product')
- expect(vm.$el.querySelector('.ng-signup-product-add').disabled).toBe(false)
- } finally {
- vm.$destroy()
- }
- })
|