From 471c99ce032ecd6e059733cb1d1ec3d6052986d6 Mon Sep 17 00:00:00 2001 From: Sydney Grant Date: Wed, 17 Feb 2021 11:20:39 -0500 Subject: [PATCH] CCS-4128: product listing unit tests (#514) --- .../frontend/src/app/productListing.test.tsx | 46 ++++++------------- .../frontend/src/app/productListing.tsx | 2 +- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/pantheon-bundle/frontend/src/app/productListing.test.tsx b/pantheon-bundle/frontend/src/app/productListing.test.tsx index bc37b072d..1d1655beb 100644 --- a/pantheon-bundle/frontend/src/app/productListing.test.tsx +++ b/pantheon-bundle/frontend/src/app/productListing.test.tsx @@ -1,6 +1,7 @@ import React from "react" import "@app/fetchMock" import { mount, shallow } from "enzyme" +import { render, fireEvent } from '@testing-library/react' import { DataList, DataListItem, DataListItemCells, DataListItemRow, FormGroup, TextInput } from "@patternfly/react-core" import ProductListing from "./productListing" import { ProductContext, IProduct } from "./contexts/ProductContext" @@ -79,36 +80,19 @@ describe("ProductListing tests", () => { it("should update input and list of products on text change", () => { - const container = mount() - const searchInput = container.find('#search.pf-c-form-control') - searchInput.simulate('change', { - target: { - value: 'product', - }, - }); - setTimeout(() => { - expect(container.prop('input')).toEqual( - 'product', - ); - expect(container.state('input')).toEqual( - 'product', - ); - expect(container.state('filteredProducts')).toHaveLength(1) - expect(container.state('filteredProducts')).toMatchObject(allProducts[0]) - }, 2000) - searchInput.simulate('change', { - target: { - value: '', - }, - }); - setTimeout(() => { - expect(container.prop('input')).toEqual( - '', - ); - expect(container.state('input')).toEqual( - '', - ); - expect(container.state('filteredProducts')).toHaveLength(2) - }, 2000) + const { getByPlaceholderText } = render() + let productInput = getByPlaceholderText('Type product name to search') as HTMLInputElement + expect(productInput.value).toBe('') + fireEvent.change(productInput, { target: { value: 'test_name' } }) + expect(productInput.value).toBe('test_name') + }) + + it("should test toggling caret to display product details dropdown option", () => { + const { getByTestId, getByText } = render() + const caret = getByTestId('product-5df8d913-79b9-42fd-a17b-ffc917add446-button') + fireEvent.click(caret) + expect(getByText('Product Details')).toBeTruthy() + const productDetailButton = getByText('Product Details') + fireEvent.click(productDetailButton) }) }) diff --git a/pantheon-bundle/frontend/src/app/productListing.tsx b/pantheon-bundle/frontend/src/app/productListing.tsx index 6c8397520..fed40873b 100644 --- a/pantheon-bundle/frontend/src/app/productListing.tsx +++ b/pantheon-bundle/frontend/src/app/productListing.tsx @@ -111,7 +111,7 @@ export default function ProductListing(props: any) { menuItems={[ onSelect(product["jcr:uuid"])} key="dropdown">Product Details]} isOpen={product.isOpen} - toggle={ onToggle(product["jcr:uuid"])} toggleTemplate={