Skip to content

Commit

Permalink
#203 add test for hool
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonatai committed Jan 26, 2024
1 parent e1a1eae commit c8ab280
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './useActiveAnchor';
export * from './useActiveLink';
export * from './useGenerateSearchEntries';
export * from './useGenerateSearchEntries/useGenerateSearchEntries';
export * from './useGetSpec';
export * from './useGetSummary';
export * from './useMarkdown';
Expand Down
87 changes: 87 additions & 0 deletions src/Hooks/useGenerateSearchEntries/mockSummery.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"project": "Neureka",
"version": "0.20.1",
"created": "Thu Jun 29 18:08:38 CEST 2023",
"statistics": {
"runs": "99",
"passed": "99",
"failed": "0",
"featureFailures": "0",
"successRate": "1.0",
"duration": "?"
},
"specifications": [
{
"className": "Example_Spec.Example_Spec",
"title": "An Introduction to writing Spock Specifications",
"narrative": "Hello and welcome to the example / template specification of this project.\n This is a simple introduction as to how to get started writing Spock specifications.\n\n Spock works on top of Groovy which is in essence a syntactic super-set of Java.\n That means that one can write Java code in Groovy, and 99% of the time it will \n work the exact same way.",
"featureCount": "5",
"failures": "0",
"errors": "0",
"skipped": "0",
"successRate": "1.0",
"duration": "?",
"executedFeatures": [
{ "id": "Call me feature not unit test!", "extraInfo": [] },
{
"id": "I am readable and also best practice!",
"extraInfo": []
},
{
"id": "Numbers to the power of two with a fancy data table!",
"extraInfo": []
}
],
"ignoredFeatures": []
},
{
"className": "it.Calculus_Stress_Test",
"title": "",
"narrative": "",
"featureCount": "5",
"failures": "0",
"errors": "0",
"skipped": "0",
"successRate": "1.0",
"duration": "?",
"executedFeatures": [
{
"id": "Activation functions work across types, on large prime sized 1D slices and non sliced 1D tensors.",
"extraInfo": []
},
{
"id": "Activation functions work across types.",
"extraInfo": []
},
{
"id": "Dot operation stress test runs error free and produces expected result",
"extraInfo": []
}
],
"ignoredFeatures": []
},
{
"className": "it.Cross_Device_Sliced_Tensor_System_Test",
"title": "Cross Device Tensor Slicing",
"narrative": "",
"featureCount": "2",
"failures": "0",
"errors": "0",
"skipped": "0",
"successRate": "1.0",
"duration": "?",
"executedFeatures": [
{
"id": "Cross device sliced tensor integration test runs without errors.",
"extraInfo": []
},
{
"id": "Slices can be created using the SliceBuilder.",
"extraInfo": []
}
],
"ignoredFeatures": []
}
],
"generator": "https://github.com/renatoathaydes/spock-reports"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { expect, test } from 'vitest';

import { renderHook } from '@testing-library/react-hooks';
import { HookProvider } from '../../test-utils';
import mockedSummery from './mockSummery.json';
import { useGenerateSearchEntries } from './useGenerateSearchEntries';
import { IMinimizedSummaryEntry } from 'spock-react/components/search-types';

const minimizedSummaries: IMinimizedSummaryEntry[] = [
{
className: 'Example_Spec.Example_Spec',
title: 'An Introduction to writing Spock Specifications',
narrative:
'Hello and welcome to the example / template specification of this project.\n This is a simple introduction as to how to get started writing Spock specifications.\n\n Spock works on top of Groovy which is in essence a syntactic super-set of Java.\n That means that one can write Java code in Groovy, and 99% of the time it will \n work the exact same way.',
features: [
{ id: 'Call me feature not unit test!' },
{
id: 'I am readable and also best practice!',
},
{
id: 'Numbers to the power of two with a fancy data table!',
},
],
},
{
className: 'it.Calculus_Stress_Test',
title: '',
narrative: '',
features: [
{
id: 'Activation functions work across types, on large prime sized 1D slices and non sliced 1D tensors.',
},
{
id: 'Activation functions work across types.',
},
{
id: 'Dot operation stress test runs error free and produces expected result',
},
],
},
{
className: 'it.Cross_Device_Sliced_Tensor_System_Test',
title: 'Cross Device Tensor Slicing',
narrative: '',
features: [
{
id: 'Cross device sliced tensor integration test runs without errors.',
},
{
id: 'Slices can be created using the SliceBuilder.',
},
],
},
];

test('hook example', () => {
const { result } = renderHook(
() => useGenerateSearchEntries({ summary: mockedSummery }),
{
wrapper: HookProvider,
}
);

expect(result.current?.length).toBe(3);
expect(result.current).toStrictEqual(minimizedSummaries);
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ export const useGenerateSearchEntries = (

useEffect(() => {
const minimizedSummary = summary?.specifications.map(
(entry: ISpecification): IMinimizedSummaryEntry => ({
className: entry.className,
features: entry.executedFeatures,
narrative: entry.narrative,
title: entry.title,
})
(entry: ISpecification): IMinimizedSummaryEntry => {
const features = entry.executedFeatures.map((feature) => ({
id: feature.id,
}));
return {
className: entry.className,
features,
narrative: entry.narrative,
title: entry.title,
};
}
);

minimizedSummary !== undefined && setSearchEntries(minimizedSummary);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/SearchInput/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ISearchInput } from 'spock-react/components/search-input-types';
import { faMagnifyingGlass } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { useGenerateSearchEntries } from '../../../Hooks/useGenerateSearchEntries';
import { useGenerateSearchEntries } from '../../../Hooks/useGenerateSearchEntries/useGenerateSearchEntries';
import { getSearchScoreV2TS } from '../getSearchScore';

export const SearchInput = (props: ISearchInput): JSX.Element => {
Expand Down
12 changes: 4 additions & 8 deletions src/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { http, HttpResponse } from 'msw';
import mockedSummery from './mockedSummery.json';

export const handlers = [
http.get('*summary.json', () => {
return new HttpResponse(
JSON.stringify({
name: '',
}),
{
status: 200,
}
);
return new HttpResponse(JSON.stringify(mockedSummery), {
status: 200,
});
}),
];
87 changes: 87 additions & 0 deletions src/mocks/mockedSummery.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"project": "Neureka",
"version": "0.20.1",
"created": "Thu Jun 29 18:08:38 CEST 2023",
"statistics": {
"runs": "99",
"passed": "99",
"failed": "0",
"featureFailures": "0",
"successRate": "1.0",
"duration": "?"
},
"specifications": [
{
"className": "Example_Spec.Example_Spec",
"title": "An Introduction to writing Spock Specifications",
"narrative": "Hello and welcome to the example / template specification of this project.\n This is a simple introduction as to how to get started writing Spock specifications.\n\n Spock works on top of Groovy which is in essence a syntactic super-set of Java.\n That means that one can write Java code in Groovy, and 99% of the time it will \n work the exact same way.",
"featureCount": "5",
"failures": "0",
"errors": "0",
"skipped": "0",
"successRate": "1.0",
"duration": "?",
"executedFeatures": [
{ "id": "Call me feature not unit test!", "extraInfo": [] },
{
"id": "I am readable and also best practice!",
"extraInfo": []
},
{
"id": "Numbers to the power of two with a fancy data table!",
"extraInfo": []
}
],
"ignoredFeatures": []
},
{
"className": "it.Calculus_Stress_Test",
"title": "",
"narrative": "",
"featureCount": "5",
"failures": "0",
"errors": "0",
"skipped": "0",
"successRate": "1.0",
"duration": "?",
"executedFeatures": [
{
"id": "Activation functions work across types, on large prime sized 1D slices and non sliced 1D tensors.",
"extraInfo": []
},
{
"id": "Activation functions work across types.",
"extraInfo": []
},
{
"id": "Dot operation stress test runs error free and produces expected result",
"extraInfo": []
}
],
"ignoredFeatures": []
},
{
"className": "it.Cross_Device_Sliced_Tensor_System_Test",
"title": "Cross Device Tensor Slicing",
"narrative": "",
"featureCount": "2",
"failures": "0",
"errors": "0",
"skipped": "0",
"successRate": "1.0",
"duration": "?",
"executedFeatures": [
{
"id": "Cross device sliced tensor integration test runs without errors.",
"extraInfo": []
},
{
"id": "Slices can be created using the SliceBuilder.",
"extraInfo": []
}
],
"ignoredFeatures": []
}
],
"generator": "https://github.com/renatoathaydes/spock-reports"
}

0 comments on commit c8ab280

Please sign in to comment.