Skip to content

Commit

Permalink
Merge pull request #104 from NitinRamnani/component-testcases-nr
Browse files Browse the repository at this point in the history
Added testcases for multiple components
  • Loading branch information
itsalb3rt authored Sep 30, 2023
2 parents a844b7b + 3fb7e17 commit 7b9db15
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
9 changes: 8 additions & 1 deletion tests/components/Products/Filter.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest'
import { describe, it, expect, vi } from 'vitest'
import { mount, config } from '@vue/test-utils'
import vuetify from 'src/plugins/vuetify'
import addElemWithDataAppToBody from 'tests/mocks/DataAppElement';
Expand Down Expand Up @@ -31,4 +31,11 @@ describe('Filter Component', () => {
expect(wrapper.props().show).toBe(true)
})

it('should test handleSort method', ()=>{
const handleSortSpy = vi.spyOn(wrapper.vm, "handleSort");
wrapper.vm.handleSort()
expect(handleSortSpy).toHaveBeenCalled()
expect(wrapper.emitted('filter')).toBeTruthy();
expect(wrapper.vm.localShow).toBe(false);
})
})
19 changes: 18 additions & 1 deletion tests/components/Products/PurchaseProduct.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest'
import { describe, it, expect, vi } from 'vitest'
import { mount, config, createLocalVue } from '@vue/test-utils'
import vuetify from 'src/plugins/vuetify'
import addElemWithDataAppToBody from 'tests/mocks/DataAppElement';
Expand Down Expand Up @@ -73,4 +73,21 @@ describe('Purchase Product Component', () => {
expect(wrapper.props().currency.symbol).toBe('R$')
})

it("should test increment method",()=>{
wrapper.vm.localQuantity = 0
const incrementSpy = vi.spyOn(wrapper.vm, "increment");
wrapper.vm.increment()
expect(incrementSpy).toHaveBeenCalled()
expect(wrapper.vm.localQuantity).toEqual(1)
});

it("should test decrement method", async() => {
wrapper.vm.localQuantity = 2;
const decrementSpy = vi.spyOn(wrapper.vm, "decrement");
wrapper.vm.decrement();
await wrapper.vm.$nextTick()
expect(decrementSpy).toHaveBeenCalled();
expect(wrapper.vm.localQuantity).toEqual(1);
});

})
32 changes: 31 additions & 1 deletion tests/components/Shop/ShopResume.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect, vi } from 'vitest';
import { mount, config } from '@vue/test-utils';
import vuetify from 'src/plugins/vuetify';
import addElemWithDataAppToBody from 'tests/mocks/DataAppElement';
Expand Down Expand Up @@ -44,4 +44,34 @@ describe('Shop Resume Component', () => {
expect(wrapper.find('.go-to-resume').text()).toBe('call_action_buttons.go_to_resume');
})

it("should test getTotalInNumberFormat",()=>{
const getTotalInNumberFormatSpy = vi.spyOn(
wrapper.vm,
"getTotalInNumberFormat"
);
const result = wrapper.vm.getTotalInNumberFormat()
expect(getTotalInNumberFormatSpy).toHaveBeenCalled();
expect(result).toEqual("1,018");
});

it("should test getTotalTaxInNumberFormat", () => {
const getTotalTaxInNumberFormatSpy = vi.spyOn(
wrapper.vm,
"getTotalTaxInNumberFormat"
);
const result = wrapper.vm.getTotalTaxInNumberFormat();
expect(getTotalTaxInNumberFormatSpy).toHaveBeenCalled();
expect(result).toEqual("18");
});

it("should test getSubTotalInNumberFormat", () => {
const getSubTotalInNumberFormatSpy = vi.spyOn(
wrapper.vm,
"getSubTotalInNumberFormat"
);
const result = wrapper.vm.getSubTotalInNumberFormat();
expect(getSubTotalInNumberFormatSpy).toHaveBeenCalled();
expect(result).toEqual("1,000");
});

})

0 comments on commit 7b9db15

Please sign in to comment.