From 7c12636b99a782d87e28cfbc742edf8e379bffd5 Mon Sep 17 00:00:00 2001 From: rafieltq Date: Fri, 20 Oct 2023 07:27:47 -0400 Subject: [PATCH 1/4] A mock component added for mixins tests --- tests/mocks/component.vue | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/mocks/component.vue diff --git a/tests/mocks/component.vue b/tests/mocks/component.vue new file mode 100644 index 0000000..2b99cbc --- /dev/null +++ b/tests/mocks/component.vue @@ -0,0 +1,14 @@ + + + + \ No newline at end of file From 0512881bc9db9a42cbe09b28ee181758ef01ec81 Mon Sep 17 00:00:00 2001 From: rafieltq Date: Fri, 20 Oct 2023 07:28:16 -0400 Subject: [PATCH 2/4] Class edit to wrap the element on the tests --- src/components/Products/ListProduct.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Products/ListProduct.vue b/src/components/Products/ListProduct.vue index e0d46f3..a13f261 100644 --- a/src/components/Products/ListProduct.vue +++ b/src/components/Products/ListProduct.vue @@ -40,6 +40,7 @@ depressed outlined @click="$emit('on-edit', product)" + class="edit" > fa-edit {{ $t('call_action_buttons.edit') }} From ea5f13163da224def322082ed49710b9f7599d64 Mon Sep 17 00:00:00 2001 From: rafieltq Date: Fri, 20 Oct 2023 07:28:30 -0400 Subject: [PATCH 3/4] listProduct edit button tests --- tests/components/Products/ListProduct.test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/components/Products/ListProduct.test.js b/tests/components/Products/ListProduct.test.js index ff0aa21..50868c9 100644 --- a/tests/components/Products/ListProduct.test.js +++ b/tests/components/Products/ListProduct.test.js @@ -40,7 +40,7 @@ const wrapperFactory = () => mount(ListProduct, { }, loadingFavorite: false, currency: { - symbol: 'R$', + symbol: 'R$', } } }) @@ -72,5 +72,16 @@ describe('List Product Component', () => { expect(wrapper.props().currency).toBeTruthy() expect(wrapper.props().currency.symbol).toBe('R$') }) + + it('should be emit on-edit event', async () => { + await wrapper.find('.edit').trigger('click') + expect(wrapper.emitted('on-edit')).toBeTruthy() + }) + + it('should be emit view-details event', async () => { + await wrapper.find('span').trigger('click') + expect(wrapper.emitted('view-details')).toBeTruthy() + }) + }) \ No newline at end of file From 40e4ae73d5920201eed069328d024a27d1af8c7a Mon Sep 17 00:00:00 2001 From: rafieltq Date: Fri, 20 Oct 2023 07:28:37 -0400 Subject: [PATCH 4/4] currencies test --- tests/mixins/miscellany/currencies.test.js | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/mixins/miscellany/currencies.test.js diff --git a/tests/mixins/miscellany/currencies.test.js b/tests/mixins/miscellany/currencies.test.js new file mode 100644 index 0000000..fba4f96 --- /dev/null +++ b/tests/mixins/miscellany/currencies.test.js @@ -0,0 +1,81 @@ +import { describe, it, expect } from 'vitest' +import { mount, config, createLocalVue } from '@vue/test-utils' +import addElemWithDataAppToBody from 'tests/mocks/DataAppElement'; +import currencies from '../../../src/mixins/miscellany/currencies.js'; +import mockComponent from '../../mocks/component.vue'; + +addElemWithDataAppToBody(); +config.stubs['font-awesome-icon'] = { template: "
" } + +const localVue = createLocalVue() + +const wrapperFactory = () => mount(mockComponent, { + mixins: [currencies], +}) + +const wrapper = wrapperFactory(); + +describe('Currencies Mixin', () => { + it('should save currencies in indexedDb', async () => { + await wrapper.vm.saveInIndexedDbCurrencies(); + }); + + it('should return an object when calling getCurrencies', () => { + expect(wrapper.vm.getCurrencies()).toBeInstanceOf(Object); + }); + + it('Should return USD currency when calling getPreferredcurrency and preferredCurrency is null', async () => { + expect(await wrapper.vm.getPreferredCurrency()).toEqual({ + code: "USD", + decimal_digits: 2, + name: "US Dollar", + name_plural: "US dollars", + rounding: 0, + symbol: "$", + symbol_native: "$", + }); + }); + + it('Should return the specified currency when calling getPreferredcurrency and preferredCurrency is not null', async () => { + await wrapper.vm.setPreferredCurrency({ + code: "DOP", + decimal_digits: 2, + name: "Dominican Peso", + name_plural: "Dominican pesos", + rounding: 0, + symbol: "RD$", + symbol_native: "RD$", + }); + expect(await wrapper.vm.getPreferredCurrency()).toEqual({ + code: "DOP", + decimal_digits: 2, + name: "Dominican Peso", + name_plural: "Dominican pesos", + rounding: 0, + symbol: "RD$", + symbol_native: "RD$", + }); + }); + + it('Should return an instance of localForage when calling getInstanceDb', () => { + expect(wrapper.vm.getInstanceDb()).toBeInstanceOf(Object); + }); + + it('Should return true when calling IsPreferredCurrencyNull and preferredCurrency is null', async () => { + await wrapper.vm.setPreferredCurrency(null); + expect(await wrapper.vm.IsPreferredCurrencyNull()).toBe(true); + }); + + it('Should return false when calling IsPreferredCurrencyNull and preferredCurrency is not null', async () => { + await wrapper.vm.setPreferredCurrency({ + code: "DOP", + decimal_digits: 2, + name: "Dominican Peso", + name_plural: "Dominican pesos", + rounding: 0, + symbol: "RD$", + symbol_native: "RD$", + }); + expect(await wrapper.vm.IsPreferredCurrencyNull()).toBe(false); + }); +}) \ No newline at end of file