Skip to content

Commit

Permalink
Fix TS errors in tests directory (#314)
Browse files Browse the repository at this point in the history
Fix all TS errors in the `tests` folder.

J=SLAP-2360
TEST=manual

Go through all files in `tests` and see that there are no more errors.
  • Loading branch information
nmanu1 authored Oct 13, 2022
1 parent 776086a commit d8e76b9
Show file tree
Hide file tree
Showing 35 changed files with 352 additions and 349 deletions.
2 changes: 1 addition & 1 deletion THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Apache License

The following NPM package may be included in this product:

- @reduxjs/[email protected].5
- @reduxjs/[email protected].6

This package contains the following license and notice below:

Expand Down
75 changes: 37 additions & 38 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@babel/preset-typescript": "^7.14.5",
"@percy/cli": "^1.8.0",
"@percy/storybook": "^4.3.3",
"@reduxjs/toolkit": "^1.8.6",
"@storybook/addon-a11y": "^6.5.10",
"@storybook/addon-actions": "^6.5.10",
"@storybook/addon-coverage": "^0.0.2",
Expand Down
11 changes: 9 additions & 2 deletions tests/__fixtures__/core/search-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { SearchService, UniversalSearchRequest, UniversalSearchResponse, VerticalSearchRequest, VerticalSearchResponse } from '@yext/search-core';
import { SearchService, Source, UniversalSearchRequest, UniversalSearchResponse, VerticalSearchRequest, VerticalSearchResponse } from '@yext/search-core';

/* A sample Universal Search response. */
const mockedUniversalResponse: UniversalSearchResponse = {
Expand All @@ -11,7 +11,14 @@ const mockedUniversalResponse: UniversalSearchResponse = {
const mockedVerticalResponse: VerticalSearchResponse = {
uuid: '123',
queryId: 'query-id',
verticalResults: null
verticalResults: {
appliedQueryFilters: [],
queryDurationMillis: 500,
verticalKey: 'vertical',
results: [],
resultsCount: 0,
source: 'KNOWLEDGE_MANAGER' as Source
}
};

/**
Expand Down
48 changes: 48 additions & 0 deletions tests/__fixtures__/data/filtercontext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { FiltersContextType } from '../../../src/components/Filters/FiltersContext';
import { SelectableFieldValueFilter } from '../../../src/models/SelectableFieldValueFilter';
import { FilterGroupContextType } from '../../../src/components/Filters/FilterGroupContext';
import { Matcher } from '@yext/search-headless-react';

const selectableFilter: SelectableFieldValueFilter = {
selected: true,
fieldId: '123',
matcher: Matcher.Equals,
value: 'test'
};

export const filterContextValue: FiltersContextType = {
selectFilter: () => null,
applyFilters: () => null,
filters: []
};

export const filterContextValueDisabled: FiltersContextType = {
selectFilter: () => null,
applyFilters: () => null,
filters: [selectableFilter]
};

export const filterGroupContextValue: FilterGroupContextType = {
searchValue: '',
fieldId: '123',
setSearchValue: () => null,
getCollapseProps: () => ({
id: 'id',
onTransitionEnd: () => null,
style: {},
'aria-hidden': 'false'
}),
getToggleProps: () => ({
disabled: false,
type: 'button',
role: 'role',
id: 'id',
'aria-controls': 'element',
'aria-expanded': 'true',
tabIndex: 0,
onClick: () => null
}),
isExpanded: true,
isOptionsDisabled: false,
setIsOptionsDisabled: () => null
};
23 changes: 23 additions & 0 deletions tests/__fixtures__/data/filters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DisplayableFacet, Matcher, SelectableStaticFilter } from '@yext/search-headless-react';
import { RemovableFilter } from '../../../src/components/AppliedFiltersDisplay';
import { StaticFiltersProps } from '../../../src/components/StaticFilters';

function createRemovableFilter(value: string) {
return {
Expand Down Expand Up @@ -96,3 +97,25 @@ export const staticFilters: SelectableStaticFilter[] = [
selected: false
}
];

export const staticFiltersProps: StaticFiltersProps = {
fieldId: 'c_puppyPreference',
title: 'Puppy Preference',
filterOptions: [
{
value: 'Marty',
displayName: 'MARTY!'
},
{
value: 'Frodo',
selectedByDefault: true
},
{
value: 'Bleecker'
},
{
value: 'Clifford',
selectedByDefault: false
}
]
};
2 changes: 1 addition & 1 deletion tests/__fixtures__/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function generateMockedStateManager(state: State): StateManager {
}

dispatchEvent(type: string, payload?: unknown): void {
return null;
return;
}

addListener<T>(listener: StateListener<T>): Unsubscribe {
Expand Down
4 changes: 2 additions & 2 deletions tests/__utils__/hierarchicalfacets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function createHierarchicalFacet(
.map(o => ({
value: o.value,
displayName: o.value,
selected: o.selected,
selected: o.selected ?? false,
count: 82,
matcher: Matcher.Equals
}));
Expand All @@ -19,4 +19,4 @@ export function createHierarchicalFacet(
displayName: 'Fruits',
options: transformedOptions
};
}
}
8 changes: 4 additions & 4 deletions tests/__utils__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export function spyOnActions(): jest.Mocked<SearchActions> {

export type RecursivePartial<T> = {
[P in keyof T]?:
T[P] extends (infer U)[] ? RecursivePartial<U>[] :
// eslint-disable-next-line @typescript-eslint/ban-types
T[P] extends object ? RecursivePartial<T[P]> :
T[P];
T[P] extends undefined ? undefined :
T[P] extends ((infer U)[] | undefined) ? RecursivePartial<U>[] :
T[P] extends (object | undefined) ? RecursivePartial<T[P]> :
T[P];
};

export function mockAnswersState(
Expand Down
35 changes: 15 additions & 20 deletions tests/components/AlternativeVerticals.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentMeta } from '@storybook/react';
import { ComponentMeta, Story } from '@storybook/react';
import { SearchHeadlessContext } from '@yext/search-headless-react';

import { AlternativeVerticals, AlternativeVerticalsProps } from '../../src/components/AlternativeVerticals';
Expand All @@ -24,33 +24,28 @@ const verticalConfigMap = {
locations: { label: 'Locations' }
};

export const Primary = (args: AlternativeVerticalsProps) => {
export const Primary: Story<AlternativeVerticalsProps> = (args) => {
return (
<SearchHeadlessContext.Provider value={generateMockedHeadless(mockedHeadlessState)}>
<AlternativeVerticals
currentVerticalLabel='Jobs'
verticalConfigMap={verticalConfigMap}
displayAllOnNoResults={false}
{...args}
/>
</SearchHeadlessContext.Provider>
);
};
Primary.args = {
currentVerticalLabel: 'Jobs',
verticalConfigMap,
displayAllOnNoResults: false
};

export const DisplayAllOnNoResults = (args: AlternativeVerticalsProps) => {
return (
<SearchHeadlessContext.Provider value={generateMockedHeadless(mockedHeadlessState)}>
<AlternativeVerticals
currentVerticalLabel='Jobs'
verticalConfigMap={verticalConfigMap}
displayAllOnNoResults={true}
{...args}
/>
</SearchHeadlessContext.Provider>
);
export const DisplayAllOnNoResults = Primary.bind({});
DisplayAllOnNoResults.args = {
...Primary.args,
displayAllOnNoResults: true
};

export const Loading = (args: AlternativeVerticalsProps) => {
export const Loading: Story<AlternativeVerticalsProps> = (args) => {
return (
<SearchHeadlessContext.Provider value={generateMockedHeadless({
...mockedHeadlessState,
Expand All @@ -59,11 +54,11 @@ export const Loading = (args: AlternativeVerticalsProps) => {
}
})}>
<AlternativeVerticals
currentVerticalLabel='Jobs'
verticalConfigMap={verticalConfigMap}
displayAllOnNoResults={true}
{...args}
/>
</SearchHeadlessContext.Provider>
);
};
Loading.args = {
...DisplayAllOnNoResults.args
};
9 changes: 4 additions & 5 deletions tests/components/AppliedFilters.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ComponentMeta } from '@storybook/react';
import { ComponentMeta, Story } from '@storybook/react';
import { SearchHeadlessContext, SearchTypeEnum } from '@yext/search-headless-react';

import { generateMockedHeadless } from '../__fixtures__/search-headless';
import { AppliedFiltersDisplay } from '../../src/components/AppliedFiltersDisplay';
import { AppliedFiltersProps, builtInCssClasses } from '../../src/components/AppliedFilters';
import { AppliedFiltersDisplay, AppliedFiltersDisplayProps } from '../../src/components/AppliedFiltersDisplay';
import { builtInCssClasses } from '../../src/components/AppliedFilters';
import { RemovableFilters } from '../__fixtures__/data/filters';

const meta: ComponentMeta<typeof AppliedFiltersDisplay> = {
Expand All @@ -12,7 +12,7 @@ const meta: ComponentMeta<typeof AppliedFiltersDisplay> = {
};
export default meta;

export const Primary = (args: AppliedFiltersProps) => {
export const Primary: Story<AppliedFiltersDisplayProps> = (args) => {
return (
<SearchHeadlessContext.Provider value={generateMockedHeadless({
meta: { searchType: SearchTypeEnum.Vertical }
Expand All @@ -26,4 +26,3 @@ export const Primary = (args: AppliedFiltersProps) => {
</SearchHeadlessContext.Provider>
);
};

Loading

0 comments on commit d8e76b9

Please sign in to comment.