From 3452f9472d0a1d5282a5f08765b6467ef79d1896 Mon Sep 17 00:00:00 2001 From: Jaskaran Sarkaria Date: Wed, 24 Nov 2021 20:14:25 +0000 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20fix=20broken=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .routify/config.js | 2 +- .routify/routes.js | 4 +- public/index.html | 4 +- src/components/ProductView/ProductView.svelte | 50 +++++++---- .../VariantProducts/VariantProducts.svelte | 79 ----------------- .../VariantProducts/VariantProducts.test.ts | 84 ------------------- 6 files changed, 38 insertions(+), 185 deletions(-) delete mode 100644 src/components/VariantProducts/VariantProducts.svelte delete mode 100644 src/components/VariantProducts/VariantProducts.test.ts diff --git a/.routify/config.js b/.routify/config.js index 325ba25b..495df9dd 100644 --- a/.routify/config.js +++ b/.routify/config.js @@ -8,5 +8,5 @@ module.exports = { noHashScroll: false, distDir: 'dist', extensions: ['svelte', 'html', 'svx', 'md'], - started: '2021-11-23T18:50:22.587Z', + started: '2021-11-24T19:14:39.743Z', }; diff --git a/.routify/routes.js b/.routify/routes.js index afbad3ac..4d534235 100644 --- a/.routify/routes.js +++ b/.routify/routes.js @@ -1,10 +1,10 @@ /** * @roxi/routify 2.7.3 - * File generated Tue Nov 23 2021 18:50:25 GMT+0000 (Greenwich Mean Time) + * File generated Wed Nov 24 2021 19:14:42 GMT+0000 (Greenwich Mean Time) */ export const __version = '2.7.3'; -export const __timestamp = '2021-11-23T18:50:25.549Z'; +export const __timestamp = '2021-11-24T19:14:42.752Z'; //buildRoutes import { buildClientTree } from '@roxi/routify/runtime/buildRoutes'; diff --git a/public/index.html b/public/index.html index 00d9e132..16abb051 100644 --- a/public/index.html +++ b/public/index.html @@ -9,9 +9,9 @@ - + - + diff --git a/src/components/ProductView/ProductView.svelte b/src/components/ProductView/ProductView.svelte index 94cae733..5c04a7be 100644 --- a/src/components/ProductView/ProductView.svelte +++ b/src/components/ProductView/ProductView.svelte @@ -1,8 +1,7 @@ -
- {#if nonVariantArr.length} - {#each nonVariantArr as product} - - {/each} - {/if} - {#if variantArr.length} - - {/if} -
+{#if variantArr.length} + {#each groupedVariantProducts as variants (variants)} +
+ {#each variants as variant (variant)} + + {/each} +
+ {/each} +{:else} +
+ {#if nonVariantArr.length} + {#each nonVariantArr as product} + + {/each} + {/if} +
+{/if} diff --git a/src/components/VariantProducts/VariantProducts.test.ts b/src/components/VariantProducts/VariantProducts.test.ts deleted file mode 100644 index f842d835..00000000 --- a/src/components/VariantProducts/VariantProducts.test.ts +++ /dev/null @@ -1,84 +0,0 @@ -import type { Product } from '@/types/product'; -import '@testing-library/jest-dom'; -import { render, screen } from '@testing-library/svelte'; -import userEvent from '@testing-library/user-event'; -import VariantProducts from './VariantProducts.svelte'; - -const variantProductsArr: Product[] = [ - { - Id: 1, - Name: 'Red book', - CategoryId: 8, - Description: 'We love red', - ProductImages: [], - ProductTags: [], - SalePrice: 1, - CurrentStock: 1, - VariantGroupId: 9, - }, - { - Id: 2, - Name: 'Blue book', - CategoryId: 8, - Description: 'Blue Velvet', - ProductImages: [], - ProductTags: [], - SalePrice: 1, - CurrentStock: 1, - VariantGroupId: 9, - }, -]; - -describe('GIVEN VariantProducts', () => { - describe('WHEN rendered with no props', () => { - it('THEN show no product or product related actions', () => { - const { container } = render(VariantProducts); - expect(container.children).toHaveLength(1); - }); - }); - - describe('WHEN rendered with props', () => { - it('THEN show the product', () => { - render(VariantProducts, { - variantProducts: [...variantProductsArr], - }); - expect( - screen.getByRole('option', { name: /red book/i }) - ).toHaveTextContent('Red book'); - expect( - (screen.getByRole('option', { name: 'Red book' }) as HTMLOptionElement) - .selected - ).toBe(true); - expect( - (screen.getByRole('option', { name: 'Blue book' }) as HTMLOptionElement) - .selected - ).toBe(false); - }); - - it('THEN show the selected product', async () => { - render(VariantProducts, { - variantProducts: [...variantProductsArr], - }); - expect( - screen.getByRole('heading', { name: /red book/i }) - ).toHaveTextContent('Red book'); - expect( - (screen.getByRole('option', { name: 'Red book' }) as HTMLOptionElement) - .selected - ).toBe(true); - expect( - (screen.getByRole('option', { name: 'Blue book' }) as HTMLOptionElement) - .selected - ).toBe(false); - userEvent.selectOptions(screen.getByRole('combobox'), ['Blue book']); - expect( - (screen.getByRole('option', { name: 'Blue book' }) as HTMLOptionElement) - .selected - ).toBe(true); - expect( - (screen.getByRole('option', { name: 'Red book' }) as HTMLOptionElement) - .selected - ).toBe(false); - }); - }); -});