Skip to content

Commit

Permalink
chore(headless)!: Remove TestUtils export (#4329)
Browse files Browse the repository at this point in the history
https://coveord.atlassian.net/browse/KIT-2425

---------

Co-authored-by: Louis Bompart <[email protected]>
Co-authored-by: GitHub Actions Bot <>
  • Loading branch information
fbeaudoincoveo and louis-bompart authored Sep 5, 2024
1 parent e7b5682 commit 310cf53
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 47 deletions.
9 changes: 1 addition & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/atomic-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@angular/cli": "17.3.9",
"@angular/compiler-cli": "17.3.12",
"@coveo/headless": "2.80.0",
"@types/jasmine": "5.1.4",
"@types/node": "20.14.12",
"jasmine-core": "5.2.0",
"karma": "6.4.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {buildInteractiveResult, TestUtils} from '@coveo/headless';
import {
buildInteractiveResult,
buildSearchEngine,
Result,
} from '@coveo/headless';
import {h} from '@stencil/core';
import {newSpecPage, SpecPage} from '@stencil/core/testing';
import {MissingParentError} from '../../common/item-list/item-decorators';
Expand Down Expand Up @@ -54,18 +58,21 @@ describe('resultContext method', () => {
});

it("revolves the bindings when it's a child of an atomic-result element", async () => {
const mockEngine = TestUtils.buildMockSearchEngine(
TestUtils.createMockState()
);
const mockResult = TestUtils.buildMockResult();
const engine = buildSearchEngine({
configuration: {
accessToken: 'accessToken',
organizationId: 'organizationId',
},
});
const mockResult = jest.mocked({} as Result);

const page = await newSpecPage({
components: [AtomicResult],
template: () => (
<atomic-result
content={document.createElement('div')}
result={TestUtils.buildMockResult()}
interactiveResult={buildInteractiveResult(mockEngine, {
result={mockResult}
interactiveResult={buildInteractiveResult(engine, {
options: {result: mockResult},
})}
store={createAtomicStore()}
Expand Down
16 changes: 13 additions & 3 deletions packages/atomic/src/utils/initialization-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {buildSearchBox, Controller, TestUtils} from '@coveo/headless';
import {buildSearchBox, buildSearchEngine, Controller} from '@coveo/headless';
import {newSpecPage, SpecPage} from '@stencil/core/testing';
import i18next from 'i18next';
import {AtomicSearchBox} from '../components/search/atomic-search-box/atomic-search-box';
Expand Down Expand Up @@ -105,7 +105,12 @@ describe('InitializeBindings decorator', () => {
it(`when "engine" is defined
should render the content `, () => {
component['bindings'] = {
engine: TestUtils.buildMockSearchEngine(TestUtils.createMockState()),
engine: buildSearchEngine({
configuration: {
accessToken: 'accessToken',
organizationId: 'organizationId',
},
}),
i18n: i18next,
store: createAtomicStore(),
interfaceElement: document.createElement('atomic-search-interface'),
Expand All @@ -127,7 +132,12 @@ describe('BindStateToController decorator', () => {
console.error = jest.fn();
component = {
bindings: {
engine: TestUtils.buildMockSearchEngine(TestUtils.createMockState()),
engine: buildSearchEngine({
configuration: {
accessToken: 'accessToken',
organizationId: 'organizationId',
},
}),
i18n: i18next,
store: createAtomicStore(),
interfaceElement: document.createElement('atomic-search-interface'),
Expand Down
25 changes: 12 additions & 13 deletions packages/atomic/src/utils/result-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import {
buildSearchEngine,
getSampleSearchEngineConfiguration,
Raw,
Result,
} from '@coveo/headless';
import {TestUtils} from '@coveo/headless';
import {Bindings} from '../components/search/atomic-search-interface/atomic-search-interface';
import {buildStringTemplateFromResult} from './result-utils';

describe('buildStringTemplateFromResult', () => {
const mockRaw = jest.mocked({source: 'the source'} as Raw);
const mockResult = jest.mocked({
title: 'foo',
uri: 'http://uri.foo.com',
raw: mockRaw,
} as Result);
const engine = buildSearchEngine({
configuration: getSampleSearchEngineConfiguration(),
});
const bindings = {engine} as Bindings;
const result = TestUtils.buildMockResult({
title: 'foo',
uri: 'http://uri.foo.com',
raw: {
...TestUtils.buildMockResult().raw,
source: 'the source',
},
});

it('should create string templates', () => {
const templates = [
Expand All @@ -30,9 +29,9 @@ describe('buildStringTemplateFromResult', () => {
];

templates.forEach((template) =>
expect(buildStringTemplateFromResult(template.in, result, bindings)).toBe(
template.out
)
expect(
buildStringTemplateFromResult(template.in, mockResult, bindings)
).toBe(template.out)
);
});

Expand All @@ -41,7 +40,7 @@ describe('buildStringTemplateFromResult', () => {
expect(
buildStringTemplateFromResult(
'${title}/${raw.notafield}',
result,
mockResult,
bindings
)
).toBe('foo/');
Expand Down
13 changes: 1 addition & 12 deletions packages/headless/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import {polyfillCryptoNode} from './api/analytics/analytics-crypto-polyfill';
import {buildMockSearchEngine} from './test/mock-engine-v2';
import {buildMockRaw} from './test/mock-raw';
import {buildMockResult} from './test/mock-result';
import {createMockState} from './test/mock-state';
import * as HighlightUtils from './utils/highlight';

const TestUtils = {
buildMockRaw,
buildMockSearchEngine,
buildMockResult,
createMockState,
};

polyfillCryptoNode();

// 3rd Party Libraries
Expand Down Expand Up @@ -562,7 +551,7 @@ export * from './features/actions-history/ipx-actions-history-actions-loader';

// Types & Helpers
export {API_DATE_FORMAT} from './api/search/date/date-format';
export {TestUtils, HighlightUtils};
export {HighlightUtils};
export type {Result} from './api/search/search/result';
export type {FieldDescription} from './api/search/fields/fields-response';
export type {Raw} from './api/search/search/raw';
Expand Down
5 changes: 2 additions & 3 deletions packages/samples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
"@angular-devkit/build-angular": "17.3.9",
"@angular/cli": "17.3.9",
"@angular/compiler-cli": "17.3.12",
"@types/jasmine": "5.1.4",
"@types/node": "20.14.12",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"cypress": "13.13.1",
"cypress-repeat": "2.3.5",
"gts": "5.3.1",
"jest": "29.7.0",
"ncp": "2.0.0",
"typescript": "5.4.5",
"jest": "29.7.0"
"typescript": "5.4.5"
}
}

0 comments on commit 310cf53

Please sign in to comment.