From c81ba56922de55147e406bcc3612212d26cfeca2 Mon Sep 17 00:00:00 2001 From: Mingkun Ma Date: Wed, 2 Nov 2022 10:00:43 -0700 Subject: [PATCH 1/7] feat: Change results number to displayed number Signed-off-by: Mingkun Ma --- .../search_result/result_components/result_panel.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/public/components/query_compare/search_result/result_components/result_panel.tsx b/public/components/query_compare/search_result/result_components/result_panel.tsx index f6d2091..49260da 100644 --- a/public/components/query_compare/search_result/result_components/result_panel.tsx +++ b/public/components/query_compare/search_result/result_components/result_panel.tsx @@ -42,9 +42,7 @@ export const ResultPanel = ({ resultNumber, queryResult }: ResultPanelProps) =>

- {typeof queryResult?.hits?.total?.value === 'number' - ? `${queryResult?.hits?.total?.value} results` - : '0 results'} + {queryResult?.hits?.hits?.length > 0 ? queryResult?.hits?.hits?.length : 0} results

From 1531dfc747b47379bb6e36dab74a2f744a819d7b Mon Sep 17 00:00:00 2001 From: Mingkun Ma Date: Mon, 7 Nov 2022 10:56:24 -0800 Subject: [PATCH 2/7] Add babelrc config Signed-off-by: Mingkun Ma --- .babelrc | 18 ++++++++++++++++++ .../common_utils/__tests__/utils.test.ts | 5 +---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..e26ee76 --- /dev/null +++ b/.babelrc @@ -0,0 +1,18 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "targets": { "node": "10" } + } + ], + "@babel/preset-react", + "@babel/preset-typescript" + ], + "plugins": [ + "@babel/plugin-transform-modules-commonjs", + ["@babel/plugin-transform-runtime", { "regenerator": true }], + "@babel/plugin-proposal-class-properties", + "@babel/plugin-proposal-object-rest-spread" + ] +} diff --git a/public/components/common_utils/__tests__/utils.test.ts b/public/components/common_utils/__tests__/utils.test.ts index fea29f3..38eebf5 100644 --- a/public/components/common_utils/__tests__/utils.test.ts +++ b/public/components/common_utils/__tests__/utils.test.ts @@ -3,10 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -// TODO: Update unit test -const isNameValid = (name) => { - return name.length >= 50 || name.length === 0 ? false : true; -}; +import { isNameValid } from '../utils'; describe('Utils helper functions', () => { it('validates isNameValid function', () => { From 89deb9aa893f72b209addc97265e0fcfa0fbfafb Mon Sep 17 00:00:00 2001 From: Mingkun Ma Date: Tue, 8 Nov 2022 11:39:11 -0800 Subject: [PATCH 3/7] Add unit test for search bar Signed-off-by: Mingkun Ma --- package.json | 1 + .../__snapshots__/search_bar.test.tsx.snap | 227 ++++++++++++++++++ .../__tests__/search_bar.test.tsx | 30 +++ yarn.lock | 48 +++- 4 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 public/components/query_compare/search_result/search_components/__tests__/__snapshots__/search_bar.test.tsx.snap create mode 100644 public/components/query_compare/search_result/search_components/__tests__/search_bar.test.tsx diff --git a/package.json b/package.json index 11d4227..d19b4f6 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ }, "dependencies": {}, "devDependencies": { + "@types/enzyme-adapter-react-16": "^1.0.6", "cypress": "9.5.4", "eslint": "^6.8.0" } diff --git a/public/components/query_compare/search_result/search_components/__tests__/__snapshots__/search_bar.test.tsx.snap b/public/components/query_compare/search_result/search_components/__tests__/__snapshots__/search_bar.test.tsx.snap new file mode 100644 index 0000000..1554d71 --- /dev/null +++ b/public/components/query_compare/search_result/search_components/__tests__/__snapshots__/search_bar.test.tsx.snap @@ -0,0 +1,227 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Search bar component Renders search bar component 1`] = ` + + +
+ + +
+ +
+ + +
+
+ + + + +
+ + + + + +
+
+ + + + + +
+
+
+
+
+
+
+
+ +
+ + + + + +
+
+
+
+ +`; diff --git a/public/components/query_compare/search_result/search_components/__tests__/search_bar.test.tsx b/public/components/query_compare/search_result/search_components/__tests__/search_bar.test.tsx new file mode 100644 index 0000000..07cbd1d --- /dev/null +++ b/public/components/query_compare/search_result/search_components/__tests__/search_bar.test.tsx @@ -0,0 +1,30 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { configure, mount } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +import React from 'react'; +import { waitFor } from '@testing-library/react'; +import { SearchInputBar } from '../search_bar'; + +describe('Search bar component', () => { + configure({ adapter: new Adapter() }); + + it('Renders search bar component', async () => { + const wrapper = mount( + {}} + onClickSearch={() => {}} + /> + ); + + wrapper.update(); + + await waitFor(() => { + expect(wrapper).toMatchSnapshot(); + }); + }); +}); diff --git a/yarn.lock b/yarn.lock index a3f6ae4..5f3dd57 100644 --- a/yarn.lock +++ b/yarn.lock @@ -60,6 +60,28 @@ debug "^3.1.0" lodash.once "^4.1.1" +"@types/cheerio@*": + version "0.22.31" + resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.31.tgz#b8538100653d6bb1b08a1e46dec75b4f2a5d5eb6" + integrity sha512-Kt7Cdjjdi2XWSfrZ53v4Of0wG3ZcmaegFXjMmz9tfNrZSkzzo36G0AL1YqSdcIA78Etjt6E609pt5h1xnQkPUw== + dependencies: + "@types/node" "*" + +"@types/enzyme-adapter-react-16@^1.0.6": + version "1.0.6" + resolved "https://registry.yarnpkg.com/@types/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.0.6.tgz#8aca7ae2fd6c7137d869b6616e696d21bb8b0cec" + integrity sha512-VonDkZ15jzqDWL8mPFIQnnLtjwebuL9YnDkqeCDYnB4IVgwUm0mwKkqhrxLL6mb05xm7qqa3IE95m8CZE9imCg== + dependencies: + "@types/enzyme" "*" + +"@types/enzyme@*": + version "3.10.12" + resolved "https://registry.yarnpkg.com/@types/enzyme/-/enzyme-3.10.12.tgz#ac4494801b38188935580642f772ad18f72c132f" + integrity sha512-xryQlOEIe1TduDWAOphR0ihfebKFSWOXpIsk+70JskCfRfW+xALdnJ0r1ZOTo85F9Qsjk6vtlU7edTYHbls9tA== + dependencies: + "@types/cheerio" "*" + "@types/react" "*" + "@types/node@*": version "18.11.8" resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.8.tgz#16d222a58d4363a2a359656dd20b28414de5d265" @@ -70,6 +92,25 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.33.tgz#8c29a0036771569662e4635790ffa9e057db379b" integrity sha512-qelS/Ra6sacc4loe/3MSjXNL1dNQ/GjxNHVzuChwMfmk7HuycRLVQN2qNY3XahK+fZc5E2szqQSKUyAF0E+2bg== +"@types/prop-types@*": + version "15.7.5" + resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf" + integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w== + +"@types/react@*": + version "18.0.25" + resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.25.tgz#8b1dcd7e56fe7315535a4af25435e0bb55c8ae44" + integrity sha512-xD6c0KDT4m7n9uD4ZHi02lzskaiqcBxf4zi+tXZY98a04wvc0hi/TcCPC2FOESZi51Nd7tlUeOJY8RofL799/g== + dependencies: + "@types/prop-types" "*" + "@types/scheduler" "*" + csstype "^3.0.2" + +"@types/scheduler@*": + version "0.16.2" + resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39" + integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew== + "@types/sinonjs__fake-timers@8.1.1": version "8.1.1" resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.1.tgz#b49c2c70150141a15e0fa7e79cf1f92a72934ce3" @@ -415,6 +456,11 @@ cross-spawn@^7.0.0: shebang-command "^2.0.0" which "^2.0.1" +csstype@^3.0.2: + version "3.1.1" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.1.tgz#841b532c45c758ee546a11d5bd7b7b473c8c30b9" + integrity sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw== + cypress@9.5.4: version "9.5.4" resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.5.4.tgz#49d9272f62eba12f2314faf29c2a865610e87550" @@ -1743,4 +1789,4 @@ yauzl@^2.10.0: integrity sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g== dependencies: buffer-crc32 "~0.2.3" - fd-slicer "~1.1.0" \ No newline at end of file + fd-slicer "~1.1.0" From 94c1bff70739fcf39ec401c4dd6d53211d683025 Mon Sep 17 00:00:00 2001 From: Mingkun Ma Date: Tue, 8 Nov 2022 11:53:05 -0800 Subject: [PATCH 4/7] Add unit test constants Signed-off-by: Mingkun Ma --- .../search_components/__tests__/search_bar.test.tsx | 3 ++- test/constants.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/constants.ts diff --git a/public/components/query_compare/search_result/search_components/__tests__/search_bar.test.tsx b/public/components/query_compare/search_result/search_components/__tests__/search_bar.test.tsx index 07cbd1d..c75477d 100644 --- a/public/components/query_compare/search_result/search_components/__tests__/search_bar.test.tsx +++ b/public/components/query_compare/search_result/search_components/__tests__/search_bar.test.tsx @@ -8,6 +8,7 @@ import Adapter from 'enzyme-adapter-react-16'; import React from 'react'; import { waitFor } from '@testing-library/react'; import { SearchInputBar } from '../search_bar'; +import { TEST_SEARCH_TEXT } from '../../../../../../test/constants'; describe('Search bar component', () => { configure({ adapter: new Adapter() }); @@ -15,7 +16,7 @@ describe('Search bar component', () => { it('Renders search bar component', async () => { const wrapper = mount( {}} onClickSearch={() => {}} /> diff --git a/test/constants.ts b/test/constants.ts new file mode 100644 index 0000000..8e13fd8 --- /dev/null +++ b/test/constants.ts @@ -0,0 +1,6 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export const TEST_SEARCH_TEXT = 'basic'; From a8541cf7de0f663be02e356e15374e20e5a4fa26 Mon Sep 17 00:00:00 2001 From: Mingkun Ma Date: Tue, 8 Nov 2022 12:18:28 -0800 Subject: [PATCH 5/7] Add unit test for result component Signed-off-by: Mingkun Ma --- .../result_component.test.tsx.snap | 7372 +++++++++++++++++ .../__test__/result_component.test.tsx | 29 + test/__mocks__/styleMock.js | 6 + test/constants.ts | 187 + 4 files changed, 7594 insertions(+) create mode 100644 public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap create mode 100644 public/components/query_compare/search_result/result_components/__test__/result_component.test.tsx create mode 100644 test/__mocks__/styleMock.js diff --git a/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap b/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap new file mode 100644 index 0000000..90d88ba --- /dev/null +++ b/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap @@ -0,0 +1,7372 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Result component Renders result component 1`] = ` + + + + <_EuiSplitPanelOuter + direction="row" + hasBorder={false} + hasShadow={false} + > + +
+ + <_EuiSplitPanelInner + className="search-relevance-result-panel" + > + +
+ +
+ +
+ +

+ Result 1 +

+
+
+
+ +
+ +

+ 10 + results +

+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +

+ 1 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ arr + : +
+
+ + ["el1","el2","el3"] + +
+
+ +
+ id + : +
+
+ + 3920564 + +
+
+ +
+ name + : +
+
+ + 006R90321 + +
+
+ +
+ title + : +
+
+ + Xerox 006R90321 toner cartridge Original Black 6 pc(s) + +
+
+ +
+ short_description + : +
+
+ + Toner (6 Per Box) for CopyCentre C65 Digital Copier + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_3920564_medium_1472618727_1445_7091.jpg + +
+
+ +
+ date_released + : +
+
+ + 2009-12-10T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + Xerox + +
+
+ +
+ price + : +
+
+ + 4995 + +
+
+
+
+
+
+ +
+ +
+ +

+ 2 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ nestObj + : +
+
+ + {"key1":[1,true,null],"key2":{"key21":"element"}} + +
+
+ +
+ id + : +
+
+ + 2101957 + +
+
+ +
+ name + : +
+
+ + dv7-1211ea + +
+
+ +
+ title + : +
+
+ + HP Pavilion dv7-1211ea Notebook Silver 43.2 cm (17") 1440 x 900 pixels Intel® Core™2 Duo 4 GB DDR2-SDRAM 250 GB HDD NVIDIA® GeForce® 9200M GS Windows Vista Home Premium + +
+
+ +
+ short_description + : +
+
+ + Intel Core 2 Duo Processor P7450 (3M Cache, 2.13 GHz, 1066 MHz FSB), 4GB DDR2, 250GB SATA HDD, 17" WXGA+ HD BrightView 1440 x 900, nVidia GeForce 9200M GS, DVD Super Multi DL, Gigabit Ethernet, WLAN 802.11 b/g, WebCam, Windows Vista Home Premium 32-bit + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/2101957_8011415648.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-12-19T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + HP + +
+
+ +
+ price + : +
+
+ + 10995 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + Silver + +
+
+
+
+
+
+ +
+ +
+ +

+ 3 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1128895 + +
+
+ +
+ name + : +
+
+ + DB9 RS232 Serial Null Modem Adapter - M/F + +
+
+ +
+ title + : +
+
+ + StarTech.com DB9 RS232 Serial Null Modem Adapter - M/F + +
+
+ +
+ short_description + : +
+
+ + StarTech.com DB9 RS232 Serial Null Modem Adapter - M/F + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/1128895_4034494654.jpg + +
+
+ +
+ date_released + : +
+
+ + 2007-08-09T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + StarTech.com + +
+
+ +
+ price + : +
+
+ + 595 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + Grey + +
+
+
+
+
+
+ +
+ +
+ +

+ 4 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1449722 + +
+
+ +
+ name + : +
+
+ + ProCurve 420 Wireless Access Point + +
+
+ +
+ title + : +
+
+ + HP ProCurve 420 Wireless Access Point + +
+
+ +
+ short_description + : +
+
+ + Refurbished A FULL-FEATURED IEEE 802.11G SINGLE-RADIO ACCESS POINT IDEALLY + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_1449722_medium_1480997766_6498_5955.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-03-07T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + HP + +
+
+ +
+ price + : +
+
+ + 9495 + +
+
+
+
+
+
+ +
+ +
+ +

+ 5 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1625640 + +
+
+ +
+ name + : +
+
+ + 2GB SD Card + +
+
+ +
+ title + : +
+
+ + Integral 2GB SD Card memory card + +
+
+ +
+ short_description + : +
+
+ + 2GB SD Card + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_1625640_medium_1480990774_7102_6217.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-06-23T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + Integral + +
+
+ +
+ price + : +
+
+ + 1195 + +
+
+
+
+
+
+ +
+ +
+ +

+ 6 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 2067378 + +
+
+ +
+ name + : +
+
+ + LC51C + +
+
+ +
+ title + : +
+
+ + Brother LC51C Original Cyan + +
+
+ +
+ short_description + : +
+
+ + LC51C + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_2067378_medium_1481020819_0464_12184.jpg + +
+
+ +
+ date_released + : +
+
+ + 2009-04-08T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + Brother + +
+
+ +
+ price + : +
+
+ + 1795 + +
+
+
+
+
+
+ +
+ +
+ +

+ 7 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 636678 + +
+
+ +
+ name + : +
+
+ + Emergency Power Off (EPO) + +
+
+ +
+ title + : +
+
+ + APC Emergency Power Off (EPO) + +
+
+ +
+ short_description + : +
+
+ + Emergency Power Off (EPO) + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_636678_medium_1480944064_4778_26509.jpg + +
+
+ +
+ date_released + : +
+
+ + 2006-11-15T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + APC + +
+
+ +
+ price + : +
+
+ + 69195 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + Black + +
+
+
+
+
+
+ +
+ +
+ +

+ 8 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1570809 + +
+
+ +
+ name + : +
+
+ + IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm + +
+
+ +
+ title + : +
+
+ + APC IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm power distribution unit (PDU) + +
+
+ +
+ short_description + : +
+
+ + IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_1570809_medium_1480983343_7059_6217.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-04-11T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + APC + +
+
+ +
+ price + : +
+
+ + 53895 + +
+
+
+
+
+
+ +
+ +
+ +

+ 9 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 148843 + +
+
+ +
+ name + : +
+
+ + Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs. + +
+
+ +
+ title + : +
+
+ + HERMA Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs. + +
+
+ +
+ short_description + : +
+
+ + Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs. + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/148843_2449.jpg + +
+
+ +
+ date_released + : +
+
+ + 2005-07-15T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + HERMA + +
+
+ +
+ price + : +
+
+ + 3795 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + White + +
+
+
+
+
+
+ +
+ +
+ +

+ 10 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 968447 + +
+
+ +
+ name + : +
+
+ + Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4' + +
+
+ +
+ title + : +
+
+ + OKI Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4' Original + +
+
+ +
+ short_description + : +
+
+ + Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4' + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_968447_medium_1480985748_8727_5647.jpg + +
+
+ +
+ date_released + : +
+
+ + 2007-08-09T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + OKI + +
+
+ +
+ price + : +
+
+ + 20395 + +
+
+
+
+
+
+
+
+
+
+ +
+ + <_EuiSplitPanelInner + className="search-relevance-result-panel" + > + +
+ +
+ +
+ +

+ Result 2 +

+
+
+
+ +
+ +

+ 10 + results +

+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +

+ 1 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 1 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 1 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ arr + : +
+
+ + ["el1","el2","el3"] + +
+
+ +
+ id + : +
+
+ + 3920564 + +
+
+ +
+ name + : +
+
+ + 006R90321 + +
+
+ +
+ title + : +
+
+ + Xerox 006R90321 toner cartridge Original Black 6 pc(s) + +
+
+ +
+ short_description + : +
+
+ + Toner (6 Per Box) for CopyCentre C65 Digital Copier + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_3920564_medium_1472618727_1445_7091.jpg + +
+
+ +
+ date_released + : +
+
+ + 2009-12-10T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + Xerox + +
+
+ +
+ price + : +
+
+ + 4995 + +
+
+
+
+
+
+ +
+ +
+ +

+ 2 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 1 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 1 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ nestObj + : +
+
+ + {"key1":[1,true,null],"key2":{"key21":"element"}} + +
+
+ +
+ id + : +
+
+ + 2101957 + +
+
+ +
+ name + : +
+
+ + dv7-1211ea + +
+
+ +
+ title + : +
+
+ + HP Pavilion dv7-1211ea Notebook Silver 43.2 cm (17") 1440 x 900 pixels Intel® Core™2 Duo 4 GB DDR2-SDRAM 250 GB HDD NVIDIA® GeForce® 9200M GS Windows Vista Home Premium + +
+
+ +
+ short_description + : +
+
+ + Intel Core 2 Duo Processor P7450 (3M Cache, 2.13 GHz, 1066 MHz FSB), 4GB DDR2, 250GB SATA HDD, 17" WXGA+ HD BrightView 1440 x 900, nVidia GeForce 9200M GS, DVD Super Multi DL, Gigabit Ethernet, WLAN 802.11 b/g, WebCam, Windows Vista Home Premium 32-bit + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/2101957_8011415648.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-12-19T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + HP + +
+
+ +
+ price + : +
+
+ + 10995 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + Silver + +
+
+
+
+
+
+ +
+ +
+ +

+ 3 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 1 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 1 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1128895 + +
+
+ +
+ name + : +
+
+ + DB9 RS232 Serial Null Modem Adapter - M/F + +
+
+ +
+ title + : +
+
+ + StarTech.com DB9 RS232 Serial Null Modem Adapter - M/F + +
+
+ +
+ short_description + : +
+
+ + StarTech.com DB9 RS232 Serial Null Modem Adapter - M/F + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/1128895_4034494654.jpg + +
+
+ +
+ date_released + : +
+
+ + 2007-08-09T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + StarTech.com + +
+
+ +
+ price + : +
+
+ + 595 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + Grey + +
+
+
+
+
+
+ +
+ +
+ +

+ 4 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 1 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 1 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1449722 + +
+
+ +
+ name + : +
+
+ + ProCurve 420 Wireless Access Point + +
+
+ +
+ title + : +
+
+ + HP ProCurve 420 Wireless Access Point + +
+
+ +
+ short_description + : +
+
+ + Refurbished A FULL-FEATURED IEEE 802.11G SINGLE-RADIO ACCESS POINT IDEALLY + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_1449722_medium_1480997766_6498_5955.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-03-07T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + HP + +
+
+ +
+ price + : +
+
+ + 9495 + +
+
+
+
+
+
+ +
+ +
+ +

+ 5 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 1 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 1 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1625640 + +
+
+ +
+ name + : +
+
+ + 2GB SD Card + +
+
+ +
+ title + : +
+
+ + Integral 2GB SD Card memory card + +
+
+ +
+ short_description + : +
+
+ + 2GB SD Card + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_1625640_medium_1480990774_7102_6217.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-06-23T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + Integral + +
+
+ +
+ price + : +
+
+ + 1195 + +
+
+
+
+
+
+ +
+ +
+ +

+ 6 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 1 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 1 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 2067378 + +
+
+ +
+ name + : +
+
+ + LC51C + +
+
+ +
+ title + : +
+
+ + Brother LC51C Original Cyan + +
+
+ +
+ short_description + : +
+
+ + LC51C + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_2067378_medium_1481020819_0464_12184.jpg + +
+
+ +
+ date_released + : +
+
+ + 2009-04-08T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + Brother + +
+
+ +
+ price + : +
+
+ + 1795 + +
+
+
+
+
+
+ +
+ +
+ +

+ 7 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 1 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 1 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 636678 + +
+
+ +
+ name + : +
+
+ + Emergency Power Off (EPO) + +
+
+ +
+ title + : +
+
+ + APC Emergency Power Off (EPO) + +
+
+ +
+ short_description + : +
+
+ + Emergency Power Off (EPO) + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_636678_medium_1480944064_4778_26509.jpg + +
+
+ +
+ date_released + : +
+
+ + 2006-11-15T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + APC + +
+
+ +
+ price + : +
+
+ + 69195 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + Black + +
+
+
+
+
+
+ +
+ +
+ +

+ 8 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 1 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 1 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1570809 + +
+
+ +
+ name + : +
+
+ + IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm + +
+
+ +
+ title + : +
+
+ + APC IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm power distribution unit (PDU) + +
+
+ +
+ short_description + : +
+
+ + IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_1570809_medium_1480983343_7059_6217.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-04-11T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + APC + +
+
+ +
+ price + : +
+
+ + 53895 + +
+
+
+
+
+
+ +
+ +
+ +

+ 9 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 1 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 1 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 148843 + +
+
+ +
+ name + : +
+
+ + Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs. + +
+
+ +
+ title + : +
+
+ + HERMA Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs. + +
+
+ +
+ short_description + : +
+
+ + Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs. + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/148843_2449.jpg + +
+
+ +
+ date_released + : +
+
+ + 2005-07-15T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + HERMA + +
+
+ +
+ price + : +
+
+ + 3795 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + White + +
+
+
+
+
+
+ +
+ +
+ +

+ 10 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 1 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 1 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 968447 + +
+
+ +
+ name + : +
+
+ + Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4' + +
+
+ +
+ title + : +
+
+ + OKI Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4' Original + +
+
+ +
+ short_description + : +
+
+ + Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4' + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_968447_medium_1480985748_8727_5647.jpg + +
+
+ +
+ date_released + : +
+
+ + 2007-08-09T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + OKI + +
+
+ +
+ price + : +
+
+ + 20395 + +
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +
+
+
+`; diff --git a/public/components/query_compare/search_result/result_components/__test__/result_component.test.tsx b/public/components/query_compare/search_result/result_components/__test__/result_component.test.tsx new file mode 100644 index 0000000..85ac1aa --- /dev/null +++ b/public/components/query_compare/search_result/result_components/__test__/result_component.test.tsx @@ -0,0 +1,29 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { configure, mount } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +import React from 'react'; +import { waitFor } from '@testing-library/react'; +import { ResultComponents } from '../result_components'; +import { TEST_QUERY_RESPONSE } from '../../../../../../test/constants'; +import { SearchRelevanceContextProvider } from '../../../../../contexts'; + +describe('Result component', () => { + configure({ adapter: new Adapter() }); + it('Renders result component', async () => { + const wrapper = mount( + + + + ); + + wrapper.update(); + + await waitFor(() => { + expect(wrapper).toMatchSnapshot(); + }); + }); +}); diff --git a/test/__mocks__/styleMock.js b/test/__mocks__/styleMock.js new file mode 100644 index 0000000..28de3c8 --- /dev/null +++ b/test/__mocks__/styleMock.js @@ -0,0 +1,6 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +module.exports = {}; diff --git a/test/constants.ts b/test/constants.ts index 8e13fd8..a2324ac 100644 --- a/test/constants.ts +++ b/test/constants.ts @@ -4,3 +4,190 @@ */ export const TEST_SEARCH_TEXT = 'basic'; + +export const TEST_QUERY_RESPONSE = { + took: 8, + timed_out: false, + _shards: { + total: 1, + successful: 1, + skipped: 0, + failed: 0, + }, + hits: { + total: { + value: 10000, + relation: 'gte', + }, + max_score: 1, + hits: [ + { + _index: 'chorus-ecommerce-data', + _id: 'WwLJC4QBuER5vZIv1tvg', + _score: 1, + _source: { + arr: ['el1', 'el2', 'el3'], + id: '3920564', + name: '006R90321', + title: 'Xerox 006R90321 toner cartridge Original Black 6 pc(s)', + short_description: 'Toner (6 Per Box) for CopyCentre C65 Digital Copier', + img_500x500: + 'http://images.icecat.biz/img/gallery_mediums/img_3920564_medium_1472618727_1445_7091.jpg', + date_released: '2009-12-10T00:00:00Z', + supplier: 'Xerox', + price: 4995, + }, + }, + { + _index: 'chorus-ecommerce-data', + _id: 'XALJC4QBuER5vZIv1tvh', + _score: 1, + _source: { + nestObj: { key1: [1, true, null], key2: { key21: 'element' } }, + id: '2101957', + name: 'dv7-1211ea', + title: + 'HP Pavilion dv7-1211ea Notebook Silver 43.2 cm (17") 1440 x 900 pixels Intel® Core™2 Duo 4 GB DDR2-SDRAM 250 GB HDD NVIDIA® GeForce® 9200M GS Windows Vista Home Premium', + short_description: + 'Intel Core 2 Duo Processor P7450 (3M Cache, 2.13 GHz, 1066 MHz FSB), 4GB DDR2, 250GB SATA HDD, 17" WXGA+ HD BrightView 1440 x 900, nVidia GeForce 9200M GS, DVD Super Multi DL, Gigabit Ethernet, WLAN 802.11 b/g, WebCam, Windows Vista Home Premium 32-bit', + img_500x500: 'http://images.icecat.biz/img/gallery_mediums/2101957_8011415648.jpg', + date_released: '2008-12-19T00:00:00Z', + supplier: 'HP', + price: 10995, + attr_t_product_colour: 'Silver', + }, + }, + { + _index: 'chorus-ecommerce-data', + _id: 'XQLJC4QBuER5vZIv1tvh', + _score: 1, + _source: { + id: '1128895', + name: 'DB9 RS232 Serial Null Modem Adapter - M/F', + title: 'StarTech.com DB9 RS232 Serial Null Modem Adapter - M/F', + short_description: 'StarTech.com DB9 RS232 Serial Null Modem Adapter - M/F', + img_500x500: 'http://images.icecat.biz/img/gallery_mediums/1128895_4034494654.jpg', + date_released: '2007-08-09T00:00:00Z', + supplier: 'StarTech.com', + price: 595, + attr_t_product_colour: 'Grey', + }, + }, + { + _index: 'chorus-ecommerce-data', + _id: 'XgLJC4QBuER5vZIv1tvh', + _score: 1, + _source: { + id: '1449722', + name: 'ProCurve 420 Wireless Access Point', + title: 'HP ProCurve 420 Wireless Access Point', + short_description: + 'Refurbished A FULL-FEATURED IEEE 802.11G SINGLE-RADIO ACCESS POINT IDEALLY', + img_500x500: + 'http://images.icecat.biz/img/gallery_mediums/img_1449722_medium_1480997766_6498_5955.jpg', + date_released: '2008-03-07T00:00:00Z', + supplier: 'HP', + price: 9495, + }, + }, + { + _index: 'chorus-ecommerce-data', + _id: 'XwLJC4QBuER5vZIv1tvh', + _score: 1, + _source: { + id: '1625640', + name: '2GB SD Card', + title: 'Integral 2GB SD Card memory card', + short_description: '2GB SD Card', + img_500x500: + 'http://images.icecat.biz/img/gallery_mediums/img_1625640_medium_1480990774_7102_6217.jpg', + date_released: '2008-06-23T00:00:00Z', + supplier: 'Integral', + price: 1195, + }, + }, + { + _index: 'chorus-ecommerce-data', + _id: 'YALJC4QBuER5vZIv1tvh', + _score: 1, + _source: { + id: '2067378', + name: 'LC51C', + title: 'Brother LC51C Original Cyan', + short_description: 'LC51C', + img_500x500: + 'http://images.icecat.biz/img/gallery_mediums/img_2067378_medium_1481020819_0464_12184.jpg', + date_released: '2009-04-08T00:00:00Z', + supplier: 'Brother', + price: 1795, + }, + }, + { + _index: 'chorus-ecommerce-data', + _id: 'YQLJC4QBuER5vZIv1tvh', + _score: 1, + _source: { + id: '636678', + name: 'Emergency Power Off (EPO)', + title: 'APC Emergency Power Off (EPO)', + short_description: 'Emergency Power Off (EPO)', + img_500x500: + 'http://images.icecat.biz/img/gallery_mediums/img_636678_medium_1480944064_4778_26509.jpg', + date_released: '2006-11-15T00:00:00Z', + supplier: 'APC', + price: 69195, + attr_t_product_colour: 'Black', + }, + }, + { + _index: 'chorus-ecommerce-data', + _id: 'YgLJC4QBuER5vZIv1tvh', + _score: 1, + _source: { + id: '1570809', + name: 'IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm', + title: + 'APC IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm power distribution unit (PDU)', + short_description: 'IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm', + img_500x500: + 'http://images.icecat.biz/img/gallery_mediums/img_1570809_medium_1480983343_7059_6217.jpg', + date_released: '2008-04-11T00:00:00Z', + supplier: 'APC', + price: 53895, + }, + }, + { + _index: 'chorus-ecommerce-data', + _id: 'YwLJC4QBuER5vZIv1tvh', + _score: 1, + _source: { + id: '148843', + name: 'Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs.', + title: 'HERMA Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs.', + short_description: 'Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs.', + img_500x500: 'http://images.icecat.biz/img/gallery_mediums/148843_2449.jpg', + date_released: '2005-07-15T00:00:00Z', + supplier: 'HERMA', + price: 3795, + attr_t_product_colour: 'White', + }, + }, + { + _index: 'chorus-ecommerce-data', + _id: 'ZALJC4QBuER5vZIv1tvh', + _score: 1, + _source: { + id: '968447', + name: "Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4'", + title: "OKI Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4' Original", + short_description: "Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4'", + img_500x500: + 'http://images.icecat.biz/img/gallery_mediums/img_968447_medium_1480985748_8727_5647.jpg', + date_released: '2007-08-09T00:00:00Z', + supplier: 'OKI', + price: 20395, + }, + }, + ], + }, +}; From 46b6e696fbd58968f94305a04d1f86afc9ccd969 Mon Sep 17 00:00:00 2001 From: Mingkun Ma Date: Tue, 8 Nov 2022 12:51:10 -0800 Subject: [PATCH 6/7] Add unit test for result grid Signed-off-by: Mingkun Ma --- .../result_component.test.tsx.snap | 80 +- .../__snapshots__/result_grid.test.tsx.snap | 2813 +++++++++++++++++ .../__test__/result_grid.test.tsx | 36 + .../result_components/result_grid.tsx | 2 +- test/constants.ts | 7 + 5 files changed, 2917 insertions(+), 21 deletions(-) create mode 100644 public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_grid.test.tsx.snap create mode 100644 public/components/query_compare/search_result/result_components/__test__/result_grid.test.tsx diff --git a/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap b/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap index 90d88ba..d7fdf8b 100644 --- a/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap +++ b/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap @@ -1250,7 +1250,9 @@ exports[`Result component Renders result component 1`] = ` className="osdDocTable__row" key="WwLJC4QBuER5vZIv1tvg" > - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +

+ 1 +

+
+
+
+ +
+ +
+ + + + + + + Up + 1 + +
+
+
+
+
+
+
+
+ +
+ +
+ arr + : +
+
+ + ["el1","el2","el3"] + +
+
+ +
+ id + : +
+
+ + 3920564 + +
+
+ +
+ name + : +
+
+ + 006R90321 + +
+
+ +
+ title + : +
+
+ + Xerox 006R90321 toner cartridge Original Black 6 pc(s) + +
+
+ +
+ short_description + : +
+
+ + Toner (6 Per Box) for CopyCentre C65 Digital Copier + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_3920564_medium_1472618727_1445_7091.jpg + +
+
+ +
+ date_released + : +
+
+ + 2009-12-10T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + Xerox + +
+
+ +
+ price + : +
+
+ + 4995 + +
+
+
+
+
+
+ +
+ +
+ +

+ 2 +

+
+
+
+ +
+ +
+ + + + + + + Down + 1 + +
+
+
+
+
+
+
+
+ +
+ +
+ nestObj + : +
+
+ + {"key1":[1,true,null],"key2":{"key21":"element"}} + +
+
+ +
+ id + : +
+
+ + 2101957 + +
+
+ +
+ name + : +
+
+ + dv7-1211ea + +
+
+ +
+ title + : +
+
+ + HP Pavilion dv7-1211ea Notebook Silver 43.2 cm (17") 1440 x 900 pixels Intel® Core™2 Duo 4 GB DDR2-SDRAM 250 GB HDD NVIDIA® GeForce® 9200M GS Windows Vista Home Premium + +
+
+ +
+ short_description + : +
+
+ + Intel Core 2 Duo Processor P7450 (3M Cache, 2.13 GHz, 1066 MHz FSB), 4GB DDR2, 250GB SATA HDD, 17" WXGA+ HD BrightView 1440 x 900, nVidia GeForce 9200M GS, DVD Super Multi DL, Gigabit Ethernet, WLAN 802.11 b/g, WebCam, Windows Vista Home Premium 32-bit + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/2101957_8011415648.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-12-19T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + HP + +
+
+ +
+ price + : +
+
+ + 10995 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + Silver + +
+
+
+
+
+
+ +
+ +
+ +

+ 3 +

+
+
+
+ +
+ +
+ + + + + + + Up + 7 + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1128895 + +
+
+ +
+ name + : +
+
+ + DB9 RS232 Serial Null Modem Adapter - M/F + +
+
+ +
+ title + : +
+
+ + StarTech.com DB9 RS232 Serial Null Modem Adapter - M/F + +
+
+ +
+ short_description + : +
+
+ + StarTech.com DB9 RS232 Serial Null Modem Adapter - M/F + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/1128895_4034494654.jpg + +
+
+ +
+ date_released + : +
+
+ + 2007-08-09T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + StarTech.com + +
+
+ +
+ price + : +
+
+ + 595 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + Grey + +
+
+
+
+
+
+ +
+ +
+ +

+ 4 +

+
+
+
+ +
+ +
+ + + + + + + Up + 96 + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1449722 + +
+
+ +
+ name + : +
+
+ + ProCurve 420 Wireless Access Point + +
+
+ +
+ title + : +
+
+ + HP ProCurve 420 Wireless Access Point + +
+
+ +
+ short_description + : +
+
+ + Refurbished A FULL-FEATURED IEEE 802.11G SINGLE-RADIO ACCESS POINT IDEALLY + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_1449722_medium_1480997766_6498_5955.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-03-07T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + HP + +
+
+ +
+ price + : +
+
+ + 9495 + +
+
+
+
+
+
+ +
+ +
+ +

+ 5 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1625640 + +
+
+ +
+ name + : +
+
+ + 2GB SD Card + +
+
+ +
+ title + : +
+
+ + Integral 2GB SD Card memory card + +
+
+ +
+ short_description + : +
+
+ + 2GB SD Card + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_1625640_medium_1480990774_7102_6217.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-06-23T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + Integral + +
+
+ +
+ price + : +
+
+ + 1195 + +
+
+
+
+
+
+ +
+ +
+ +

+ 6 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 2067378 + +
+
+ +
+ name + : +
+
+ + LC51C + +
+
+ +
+ title + : +
+
+ + Brother LC51C Original Cyan + +
+
+ +
+ short_description + : +
+
+ + LC51C + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_2067378_medium_1481020819_0464_12184.jpg + +
+
+ +
+ date_released + : +
+
+ + 2009-04-08T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + Brother + +
+
+ +
+ price + : +
+
+ + 1795 + +
+
+
+
+
+
+ +
+ +
+ +

+ 7 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 636678 + +
+
+ +
+ name + : +
+
+ + Emergency Power Off (EPO) + +
+
+ +
+ title + : +
+
+ + APC Emergency Power Off (EPO) + +
+
+ +
+ short_description + : +
+
+ + Emergency Power Off (EPO) + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_636678_medium_1480944064_4778_26509.jpg + +
+
+ +
+ date_released + : +
+
+ + 2006-11-15T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + APC + +
+
+ +
+ price + : +
+
+ + 69195 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + Black + +
+
+
+
+
+
+ +
+ +
+ +

+ 8 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 1570809 + +
+
+ +
+ name + : +
+
+ + IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm + +
+
+ +
+ title + : +
+
+ + APC IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm power distribution unit (PDU) + +
+
+ +
+ short_description + : +
+
+ + IT Power Distribution Module 3 Pole 5 Wire 32A IEC309 620cm + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_1570809_medium_1480983343_7059_6217.jpg + +
+
+ +
+ date_released + : +
+
+ + 2008-04-11T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + APC + +
+
+ +
+ price + : +
+
+ + 53895 + +
+
+
+
+
+
+ +
+ +
+ +

+ 9 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 148843 + +
+
+ +
+ name + : +
+
+ + Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs. + +
+
+ +
+ title + : +
+
+ + HERMA Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs. + +
+
+ +
+ short_description + : +
+
+ + Labels Premium A4 64.6x33.8 mm white paper matt 2400 pcs. + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/148843_2449.jpg + +
+
+ +
+ date_released + : +
+
+ + 2005-07-15T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + HERMA + +
+
+ +
+ price + : +
+
+ + 3795 + +
+
+ +
+ attr_t_product_colour + : +
+
+ + White + +
+
+
+
+
+
+ +
+ +
+ +

+ 10 +

+
+
+
+ +
+ +
+ + Not applicable + + + + Not in + + Results + 2 + + + } + size="m" + type="questionInCircle" + > + + Not in + + Results + 2 + + + } + delay="regular" + position="top" + > + + + + + + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ id + : +
+
+ + 968447 + +
+
+ +
+ name + : +
+
+ + Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4' + +
+
+ +
+ title + : +
+
+ + OKI Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4' Original + +
+
+ +
+ short_description + : +
+
+ + Cyan Toner Cartridge for C7100/C7300/C7500 Series 'Type C4' + +
+
+ +
+ img_500x500 + : +
+
+ + http://images.icecat.biz/img/gallery_mediums/img_968447_medium_1480985748_8727_5647.jpg + +
+
+ +
+ date_released + : +
+
+ + 2007-08-09T00:00:00Z + +
+
+ +
+ supplier + : +
+
+ + OKI + +
+
+ +
+ price + : +
+
+ + 20395 + +
+
+
+
+
+
+
+
+ +`; diff --git a/public/components/query_compare/search_result/result_components/__test__/result_grid.test.tsx b/public/components/query_compare/search_result/result_components/__test__/result_grid.test.tsx new file mode 100644 index 0000000..4a8b689 --- /dev/null +++ b/public/components/query_compare/search_result/result_components/__test__/result_grid.test.tsx @@ -0,0 +1,36 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { configure, mount } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +import React from 'react'; +import { waitFor } from '@testing-library/react'; +import { ResultGridComponent } from '../result_grid'; +import { + TEST_QUERY_RESPONSE, + TEST_COMPARED_DOCUMENTS_RANK, +} from '../../../../../../test/constants'; +import { SearchRelevanceContextProvider } from '../../../../../contexts'; + +describe('Result grid component', () => { + configure({ adapter: new Adapter() }); + it('Renders result grid component', async () => { + const wrapper = mount( + + + + ); + + wrapper.update(); + + await waitFor(() => { + expect(wrapper).toMatchSnapshot(); + }); + }); +}); diff --git a/public/components/query_compare/search_result/result_components/result_grid.tsx b/public/components/query_compare/search_result/result_components/result_grid.tsx index f7222a9..f0cfb11 100644 --- a/public/components/query_compare/search_result/result_components/result_grid.tsx +++ b/public/components/query_compare/search_result/result_components/result_grid.tsx @@ -135,7 +135,7 @@ export const ResultGridComponent = ({ const getRankColumn = (documentId: string, documentRank: number) => { return ( - + diff --git a/test/constants.ts b/test/constants.ts index a2324ac..3480723 100644 --- a/test/constants.ts +++ b/test/constants.ts @@ -191,3 +191,10 @@ export const TEST_QUERY_RESPONSE = { ], }, }; + +export const TEST_COMPARED_DOCUMENTS_RANK = { + WwLJC4QBuER5vZIv1tvg: 2, + XALJC4QBuER5vZIv1tvh: 1, + XQLJC4QBuER5vZIv1tvh: 10, + XgLJC4QBuER5vZIv1tvh: 100, +}; From 0b3646d5eba8b47573876ae19d2b37a2531e4442 Mon Sep 17 00:00:00 2001 From: Mingkun Ma Date: Tue, 8 Nov 2022 12:56:08 -0800 Subject: [PATCH 7/7] Add unit test for common components Signed-off-by: Mingkun Ma --- .../__snapshots__/flyout.test.tsx.snap | 4640 +++++++++++++++++ .../__snapshots__/header.test.tsx.snap | 261 + .../common/__test__/flyout.test.tsx | 29 + .../common/__test__/header.test.tsx | 24 + 4 files changed, 4954 insertions(+) create mode 100644 public/components/common/__test__/__snapshots__/flyout.test.tsx.snap create mode 100644 public/components/common/__test__/__snapshots__/header.test.tsx.snap create mode 100644 public/components/common/__test__/flyout.test.tsx create mode 100644 public/components/common/__test__/header.test.tsx diff --git a/public/components/common/__test__/__snapshots__/flyout.test.tsx.snap b/public/components/common/__test__/__snapshots__/flyout.test.tsx.snap new file mode 100644 index 0000000..733aed3 --- /dev/null +++ b/public/components/common/__test__/__snapshots__/flyout.test.tsx.snap @@ -0,0 +1,4640 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Flyout component Renders flyout component 1`] = ` + + + + + + + + } + onActivation={[Function]} + onDeactivation={[Function]} + persistentFocus={false} + returnFocus={[Function]} + shards={Array []} + sideCar={ + Object { + "assignMedium": [Function], + "assignSyncMedium": [Function], + "options": Object { + "async": true, + "ssr": false, + }, + "read": [Function], + "useMedium": [Function], + } + } + > + + +
+ } + onActivation={[Function]} + onDeactivation={[Function]} + persistentFocus={false} + returnFocus={[Function]} + shards={Array []} + > + + + + } + onActivation={[Function]} + onDeactivation={[Function]} + persistentFocus={false} + returnFocus={[Function]} + shards={Array []} + /> + + + + +
+ +
+ + + + + + +
+ +

+ Help +

+
+
+
+ +
+
+
+ +
+

+ Query format +

+

+ Enter a query in + + + + OpenSearch Query DSL + + + + + + + + + (opens in a new tab or window) + + + + + + . Use the + + + + + %SearchText% + + + + + variable to refer to the text in the search bar. When you enter + + Search + + , the queries are sent to the search engine using the + + + + + GET + + + + + HTTP method and the + + + + + _search + + + + + + endpoint. +

+

+ Example +

+
+

+ 1. Enter the search text in the search bar. +

+

+ 2. Select an index for + + Query 1 + + and enter a query. +

+

+ The following example searches the + + + + + speaker + + + + + and + + + + + + text_entry + + + + + fields of the + + + + + shakespeare + + + + + index for the search text: +

+ + +
+
+                                              
+                                                
+                                                  
+
+                                                
+                                                
+                                                  
+                                                    {
+                                                  
+                                                  
+
+                                                
+                                                
+                                                    
+                                                  
+                                                    "query"
+                                                  
+                                                  
+                                                    :
+                                                  
+                                                   
+                                                  
+                                                    {
+                                                  
+                                                  
+
+                                                
+                                                
+                                                      
+                                                  
+                                                    "multi_match"
+                                                  
+                                                  
+                                                    :
+                                                  
+                                                   
+                                                  
+                                                    {
+                                                  
+                                                  
+
+                                                
+                                                
+                                                        
+                                                  
+                                                    "query"
+                                                  
+                                                  
+                                                    :
+                                                  
+                                                   
+                                                  
+                                                    "%SearchText%"
+                                                  
+                                                  
+                                                    ,
+                                                  
+                                                  
+
+                                                
+                                                
+                                                        
+                                                  
+                                                    "fields"
+                                                  
+                                                  
+                                                    :
+                                                  
+                                                   
+                                                  
+                                                    [
+                                                  
+                                                  
+                                                    "speaker"
+                                                  
+                                                  
+                                                    ,
+                                                  
+                                                   
+                                                  
+                                                    "text_entry"
+                                                  
+                                                  
+                                                    ]
+                                                  
+                                                  
+
+                                                
+                                                
+                                                      
+                                                  
+                                                    }
+                                                  
+                                                  
+
+                                                
+                                                
+                                                    
+                                                  
+                                                    }
+                                                  
+                                                  
+
+                                                
+                                                
+                                                  
+                                                    }
+                                                  
+                                                  
+
+                                                
+                                                
+                                              
+                                            
+
+
+ + + + + + + + + + + +
+
+
+
+
+

+ 3. Select an index for + + Query 2 + + and enter a query. +

+

+ You can see how boosting a field affects the results. The following query boosts the + + + + + speaker + + + + + field: +

+ + +
+
+                                              
+                                                
+                                                  
+
+                                                
+                                                
+                                                  
+                                                    {
+                                                  
+                                                  
+
+                                                
+                                                
+                                                    
+                                                  
+                                                    "query"
+                                                  
+                                                  
+                                                    :
+                                                  
+                                                   
+                                                  
+                                                    {
+                                                  
+                                                  
+
+                                                
+                                                
+                                                      
+                                                  
+                                                    "multi_match"
+                                                  
+                                                  
+                                                    :
+                                                  
+                                                   
+                                                  
+                                                    {
+                                                  
+                                                  
+
+                                                
+                                                
+                                                        
+                                                  
+                                                    "query"
+                                                  
+                                                  
+                                                    :
+                                                  
+                                                   
+                                                  
+                                                    "%SearchText%"
+                                                  
+                                                  
+                                                    ,
+                                                  
+                                                  
+
+                                                
+                                                
+                                                        
+                                                  
+                                                    "fields"
+                                                  
+                                                  
+                                                    :
+                                                  
+                                                   
+                                                  
+                                                    [
+                                                  
+                                                  
+                                                    "speaker^3"
+                                                  
+                                                  
+                                                    ,
+                                                  
+                                                   
+                                                  
+                                                    "text_entry"
+                                                  
+                                                  
+                                                    ]
+                                                  
+                                                  
+
+                                                
+                                                
+                                                      
+                                                  
+                                                    }
+                                                  
+                                                  
+
+                                                
+                                                
+                                                    
+                                                  
+                                                    }
+                                                  
+                                                  
+
+                                                
+                                                
+                                                  
+                                                    }
+                                                  
+                                                  
+
+                                                
+                                                
+                                              
+                                            
+
+
+ + + + + + + + + + + +
+
+
+
+
+

+ To learn more about boosts, see the + + + + Multi-match Query Documentation + + + + + + + + + (opens in a new tab or window) + + + + + + . +

+

+ 4. Compare results +

+

+ Select + + Search + + and compare the results in Results 1 and Results 2. +

+
+
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + +`; diff --git a/public/components/common/__test__/__snapshots__/header.test.tsx.snap b/public/components/common/__test__/__snapshots__/header.test.tsx.snap new file mode 100644 index 0000000..dda8e87 --- /dev/null +++ b/public/components/common/__test__/__snapshots__/header.test.tsx.snap @@ -0,0 +1,261 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Header component Renders header component 1`] = ` +
+ +
+ +
+ +
+ +
+ +
+ +

+ Compare search results +

+
+
+
+
+
+
+ +
+ + +
+
+ + + Experimental Feature + +
+ +
+ +
+ +
+

+ Compare results using the same search text with different queries. For more information, see the + + + + Compare Search Results Documentation + + + + + + + + + (opens in a new tab or window) + + + + + + . To leave feedback, visit + + + + forums.opensearch.com + + + + + + + + + (opens in a new tab or window) + + + + + + . +

+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+`; diff --git a/public/components/common/__test__/flyout.test.tsx b/public/components/common/__test__/flyout.test.tsx new file mode 100644 index 0000000..b5c9170 --- /dev/null +++ b/public/components/common/__test__/flyout.test.tsx @@ -0,0 +1,29 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { configure, mount } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +import React from 'react'; +import { waitFor } from '@testing-library/react'; +import { Flyout } from '../flyout'; +import { SearchRelevanceContextProvider } from '../../../contexts'; + +describe('Flyout component', () => { + configure({ adapter: new Adapter() }); + + it('Renders flyout component', async () => { + const wrapper = mount( + + + + ); + + wrapper.update(); + + await waitFor(() => { + expect(wrapper).toMatchSnapshot(); + }); + }); +}); diff --git a/public/components/common/__test__/header.test.tsx b/public/components/common/__test__/header.test.tsx new file mode 100644 index 0000000..6e963eb --- /dev/null +++ b/public/components/common/__test__/header.test.tsx @@ -0,0 +1,24 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { configure, mount } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +import React from 'react'; +import { waitFor } from '@testing-library/react'; +import { Header } from '../header'; + +describe('Header component', () => { + configure({ adapter: new Adapter() }); + + it('Renders header component', async () => { + const wrapper = mount(
); + + wrapper.update(); + + await waitFor(() => { + expect(wrapper).toMatchSnapshot(); + }); + }); +});