From a7132b041feaee71529d7bdd0f21f156956256ad Mon Sep 17 00:00:00 2001 From: Ingrid Martinsheimen Egge <ingrimeg@stud.ntnu.no> Date: Mon, 1 May 2023 10:25:57 +0200 Subject: [PATCH] la inn tester for itemsearch --- src/components/__tests__/ItemSearch.spec.js | 68 +++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/components/__tests__/ItemSearch.spec.js diff --git a/src/components/__tests__/ItemSearch.spec.js b/src/components/__tests__/ItemSearch.spec.js new file mode 100644 index 0000000..12d1120 --- /dev/null +++ b/src/components/__tests__/ItemSearch.spec.js @@ -0,0 +1,68 @@ +import { describe, it, expect } from 'vitest' +import { mount } from '@vue/test-utils' +import ItemSearch from "@/components/ItemSearch.vue"; + +const SearchReturn = [ + { + "id": "1", + "ean": "7040512550214", + "name":"eplekake", + "amount": {"quantity": "4","unit": "stk"}, + "image_url": "https://bilder.ngdata.no/7040512550818/meny/large.jpg" + }, + { + "id": "2", + "ean": "7040512550254", + "name":"eple", + "amount": {"quantity": "4","unit": "stk"}, + "image_url": "https://bilder.ngdata.no/7040512550818/meny/large.jpg" + }]; + +describe('Behaves as expected', () => { + it('shows correct number of results', async () => { + const wrapper = mount(ItemSearch, { + data() { + return { + searchResult: SearchReturn, + selectedItem: SearchReturn[0], + numOfItemsToAdd:3, + }; + }, + }); + + expect(wrapper.text()).toContain('Resultater: ') + expect(wrapper.text()).toContain('(2)') + }); + + it('When adding more items, the total ingredient amount is shown', async () => { + const wrapper = mount(ItemSearch, { + data() { + return { + searchResult: SearchReturn, + selectedItem: SearchReturn[0], + numOfItemsToAdd:3, + }; + }, + }); + + // total = 3*4 + const totalItemCount = wrapper.find('span') + expect(totalItemCount.text()).toContain('12') + expect(totalItemCount.text()).toContain('stk') + }); + + it('Selected contains all items ', async () => { + const wrapper = mount(ItemSearch, { + data() { + return { + searchResult: SearchReturn, + selectedItem: SearchReturn[0], + numOfItemsToAdd:3, + }; + }, + }); + const itemSelect = wrapper.find('select') + expect(itemSelect.text()).toContain('eple') + expect(itemSelect.text()).toContain('eplekake') + }); +}) -- GitLab