Skip to content

Commit

Permalink
Merge pull request #106 from rafieltq/rafiel/tests
Browse files Browse the repository at this point in the history
Rafiel/tests
  • Loading branch information
itsalb3rt authored Oct 21, 2023
2 parents 7b9db15 + 40e4ae7 commit 73eb603
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/Products/ListProduct.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
depressed
outlined
@click="$emit('on-edit', product)"
class="edit"
>
<v-icon class="mr-1">fa-edit</v-icon>
{{ $t('call_action_buttons.edit') }}
Expand Down
13 changes: 12 additions & 1 deletion tests/components/Products/ListProduct.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const wrapperFactory = () => mount(ListProduct, {
},
loadingFavorite: false,
currency: {
symbol: 'R$',
symbol: 'R$',
}
}
})
Expand Down Expand Up @@ -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()
})


})
81 changes: 81 additions & 0 deletions tests/mixins/miscellany/currencies.test.js
Original file line number Diff line number Diff line change
@@ -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: "<div></div> " }

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);
});
})
14 changes: 14 additions & 0 deletions tests/mocks/component.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<div class="test"></div>
</template>

<script>
/**
* Return a component to be used as dummy in order
* to mock things like mixins.
*/
export default {
name: "MockComponent"
};
</script>

0 comments on commit 73eb603

Please sign in to comment.