From c6393a942550dfc66be11171aaf0ba9b808a7491 Mon Sep 17 00:00:00 2001 From: Frederic Beaudoin Date: Wed, 25 Sep 2024 12:05:49 -0400 Subject: [PATCH] chore: eliminate network calls in npm test (#4453) https://coveord.atlassian.net/browse/KIT-3485 --- .../src/ssr/search-engine.test.tsx | 36 ++++++++++++++++++- packages/headless/package.json | 6 ++-- .../search-engine/search-engine.ssr.test.ts | 31 +++++++--------- packages/headless/src/ssr.index.ts | 1 + .../headless-commerce-react/package.json | 2 +- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/packages/headless-react/src/ssr/search-engine.test.tsx b/packages/headless-react/src/ssr/search-engine.test.tsx index 39e849c2f24..df3b30de4ca 100644 --- a/packages/headless-react/src/ssr/search-engine.test.tsx +++ b/packages/headless-react/src/ssr/search-engine.test.tsx @@ -1,13 +1,16 @@ -import {NavigatorContextProvider} from '@coveo/headless/dist/definitions/app/navigatorContextProvider.js'; import { getSampleSearchEngineConfiguration, InferStaticState, InferHydratedState, defineResultList, defineSearchBox, + Result, + NavigatorContextProvider, } from '@coveo/headless/ssr'; import {act, render, renderHook, screen} from '@testing-library/react'; +import {randomUUID} from 'crypto'; import {PropsWithChildren} from 'react'; +import React from 'react'; import { vi, expect, @@ -106,7 +109,38 @@ describe('Headless react SSR utils', () => { } = engineDefinition; function TestResultList() { + const generateMockResult: () => Result = () => { + return { + absentTerms: [], + clickUri: '', + excerpt: '', + excerptHighlights: [], + firstSentences: '', + firstSentencesHighlights: [], + flags: '', + hasHtmlVersion: false, + isRecommendation: false, + isTopResult: false, + isUserActionView: false, + percentScore: 0, + printableUri: '', + printableUriHighlights: [], + rankingInfo: null, + raw: {urihash: ''}, + score: 0, + searchUid: '', + summary: null, + summaryHighlights: [], + title: '', + titleHighlights: [], + uniqueId: randomUUID(), + uri: '', + }; + }; + const {state} = controllers.useResultList(); + + state.results = Array.from({length: numResults}, generateMockResult); return (