|
1 | 1 | import React from "react"
|
2 | 2 | import "@app/fetchMock"
|
3 | 3 | import { mount, shallow } from "enzyme"
|
| 4 | +import { render, fireEvent } from '@testing-library/react' |
4 | 5 | import { DataList, DataListItem, DataListItemCells, DataListItemRow, FormGroup, TextInput } from "@patternfly/react-core"
|
5 | 6 | import ProductListing from "./productListing"
|
6 | 7 | import { ProductContext, IProduct } from "./contexts/ProductContext"
|
@@ -79,36 +80,19 @@ describe("ProductListing tests", () => {
|
79 | 80 |
|
80 | 81 |
|
81 | 82 | it("should update input and list of products on text change", () => {
|
82 |
| - const container = mount(<ProductContext.Provider value={allProducts}><ProductListing /></ProductContext.Provider>) |
83 |
| - const searchInput = container.find('#search.pf-c-form-control') |
84 |
| - searchInput.simulate('change', { |
85 |
| - target: { |
86 |
| - value: 'product', |
87 |
| - }, |
88 |
| - }); |
89 |
| - setTimeout(() => { |
90 |
| - expect(container.prop('input')).toEqual( |
91 |
| - 'product', |
92 |
| - ); |
93 |
| - expect(container.state('input')).toEqual( |
94 |
| - 'product', |
95 |
| - ); |
96 |
| - expect(container.state('filteredProducts')).toHaveLength(1) |
97 |
| - expect(container.state('filteredProducts')).toMatchObject(allProducts[0]) |
98 |
| - }, 2000) |
99 |
| - searchInput.simulate('change', { |
100 |
| - target: { |
101 |
| - value: '', |
102 |
| - }, |
103 |
| - }); |
104 |
| - setTimeout(() => { |
105 |
| - expect(container.prop('input')).toEqual( |
106 |
| - '', |
107 |
| - ); |
108 |
| - expect(container.state('input')).toEqual( |
109 |
| - '', |
110 |
| - ); |
111 |
| - expect(container.state('filteredProducts')).toHaveLength(2) |
112 |
| - }, 2000) |
| 83 | + const { getByPlaceholderText } = render(<ProductContext.Provider value={allProducts}><ProductListing /></ProductContext.Provider>) |
| 84 | + let productInput = getByPlaceholderText('Type product name to search') as HTMLInputElement |
| 85 | + expect(productInput.value).toBe('') |
| 86 | + fireEvent.change(productInput, { target: { value: 'test_name' } }) |
| 87 | + expect(productInput.value).toBe('test_name') |
| 88 | + }) |
| 89 | + |
| 90 | + it("should test toggling caret to display product details dropdown option", () => { |
| 91 | + const { getByTestId, getByText } = render(<ProductContext.Provider value={allProducts}><ProductListing /></ProductContext.Provider>) |
| 92 | + const caret = getByTestId('product-5df8d913-79b9-42fd-a17b-ffc917add446-button') |
| 93 | + fireEvent.click(caret) |
| 94 | + expect(getByText('Product Details')).toBeTruthy() |
| 95 | + const productDetailButton = getByText('Product Details') |
| 96 | + fireEvent.click(productDetailButton) |
113 | 97 | })
|
114 | 98 | })
|
0 commit comments