From 2590c7464734b6a4eac7aa57765dfca01debcfdf Mon Sep 17 00:00:00 2001 From: Aalekh Patel Date: Sat, 7 Dec 2024 12:32:57 -0600 Subject: [PATCH 1/4] Show similarity scores for points when available. Signed-off-by: Aalekh Patel --- src/components/Points/PointCard.jsx | 1 + src/components/Points/PointsTabs.jsx | 1 + 2 files changed, 2 insertions(+) diff --git a/src/components/Points/PointCard.jsx b/src/components/Points/PointCard.jsx index ff6fb9c56..f10957ff2 100644 --- a/src/components/Points/PointCard.jsx +++ b/src/components/Points/PointCard.jsx @@ -65,6 +65,7 @@ const PointCard = (props) => { )} {Object.keys(point.payload).length === 0 && ( diff --git a/src/components/Points/PointsTabs.jsx b/src/components/Points/PointsTabs.jsx index 763b380a1..2e38dc85b 100644 --- a/src/components/Points/PointsTabs.jsx +++ b/src/components/Points/PointsTabs.jsx @@ -170,6 +170,7 @@ const PointsTabs = ({ collectionName, client }) => { Date: Sat, 7 Dec 2024 13:35:58 -0600 Subject: [PATCH 2/4] Add a test to assert point card shows score if and only if it exists Signed-off-by: Aalekh Patel --- src/components/Points/pointCard.test.jsx | 64 ++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/components/Points/pointCard.test.jsx diff --git a/src/components/Points/pointCard.test.jsx b/src/components/Points/pointCard.test.jsx new file mode 100644 index 000000000..5c429560a --- /dev/null +++ b/src/components/Points/pointCard.test.jsx @@ -0,0 +1,64 @@ +import { render, screen } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import PointCard from './PointCard'; +import { describe, it, expect } from 'vitest'; +import qdrantClient from '../../common/client'; + +function noop(...args) { + // do nothing. +} + +const client = qdrantClient({}); + +const SCORED_POINT = { + id: 10, + version: 3, + score: 0.9621345, + payload: {}, + vector: [0.325, 0.112, 0.2], +}; + +const UNSCORED_POINT = { + id: 11, + version: 3, + payload: {}, + vector: [0.325, 0.112, 0.2], +}; + +describe('PointCard', () => { + it('should render score when it is present', () => { + render( + + + + ); + expect(screen.getByText('Point 10')).toBeInTheDocument(); + expect(screen.getByText('Score: 0.9621345')).toBeInTheDocument(); + }); + + it('should not render score when it is not available', async () => { + render( + + + + ); + expect(screen.getByText('Point 11')).toBeInTheDocument(); + expect(screen.queryByText('Score') === null); + }); +}); From f59c00e92cf3f4e163595b5d48021530efe34532 Mon Sep 17 00:00:00 2001 From: Aalekh Patel Date: Sat, 7 Dec 2024 13:39:35 -0600 Subject: [PATCH 3/4] Fix monaco-editor broken in tests following https://github.com/vitest-dev/vitest/discussions/1806#discussioncomment-3570047 Signed-off-by: Aalekh Patel --- vite.config.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vite.config.js b/vite.config.js index bd0d8d83e..aae734d3f 100644 --- a/vite.config.js +++ b/vite.config.js @@ -41,6 +41,12 @@ export default defineConfig(async () => { globals: true, environment: 'jsdom', setupFiles: ['./src/setupTests.js'], + alias: [ + { + find: /^monaco-editor$/, + replacement: __dirname + '/node_modules/monaco-editor/esm/vs/editor/editor.api', + }, + ], }, - } + }; }); From eb6fd4e8970168957358c27133a277e53011e741 Mon Sep 17 00:00:00 2001 From: Aalekh Patel Date: Sat, 7 Dec 2024 13:41:18 -0600 Subject: [PATCH 4/4] Assert undefined is also not shown Signed-off-by: Aalekh Patel --- src/components/Points/pointCard.test.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Points/pointCard.test.jsx b/src/components/Points/pointCard.test.jsx index 5c429560a..962c38fac 100644 --- a/src/components/Points/pointCard.test.jsx +++ b/src/components/Points/pointCard.test.jsx @@ -60,5 +60,6 @@ describe('PointCard', () => { ); expect(screen.getByText('Point 11')).toBeInTheDocument(); expect(screen.queryByText('Score') === null); + expect(screen.queryByText('Score: undefined') === null); }); });