Skip to content

Commit

Permalink
#144 separate hooks types
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonatai committed Jan 3, 2024
1 parent 8052dc9 commit 734e81c
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 105 deletions.
44 changes: 44 additions & 0 deletions src/Hooks/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
declare module 'spock-react/hooks-types' {
import { IFeature, ISummary } from 'spock-react-types';

export interface IMarkdown {
filePath: string;
}

export interface ISpec {
className: string;
statistics: {
runs: string;
passed: string;
failed: string;
featureFailures: string;
successRate: string;
duration: string;
};
title: string;
narrative: string;
headers: string[];
tags: any;
see: any[];
features: IFeature[];
generator: string;
}

export interface IGetSpec {
fileName: string;
}

export interface IGenerateSearchEntries {
summary?: ISummary;
}

export interface IActiveLink {
activeLink: string;
setActiveLink: (newLink: string) => void;
}

export interface IActiveAnchor {
activeAnchor: string;
setActiveAnchor: (newAnchor: string) => void;
}
}
5 changes: 1 addition & 4 deletions src/Hooks/useActiveAnchor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IActiveAnchor } from 'spock-react/hooks-types';
import { create } from 'zustand';

const getInitialState = () => {
Expand All @@ -9,10 +10,6 @@ const getInitialState = () => {
return pageAndAnchor.length === 2 ? decodeURI(pageAndAnchor[1]) : '';
};

interface IActiveAnchor {
activeAnchor: string;
setActiveAnchor: (newAnchor: string) => void;
}
export const useActiveAnchor = create<IActiveAnchor>((set) => ({
activeAnchor: getInitialState(),
setActiveAnchor: (newAnchor: string) => {
Expand Down
5 changes: 1 addition & 4 deletions src/Hooks/useActiveLink.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { create } from 'zustand';
import * as config from '../../environment.json';
import { IActiveLink } from 'spock-react/hooks-types';

const getInitialState = () => {
const pageAndAnchor = window.location.pathname.split('#');
Expand All @@ -11,10 +12,6 @@ const getInitialState = () => {
return page;
};

interface IActiveLink {
activeLink: string;
setActiveLink: (newLink: string) => void;
}
export const useActiveLink = create<IActiveLink>((set) => ({
activeLink: getInitialState(),
setActiveLink: (newLink: string) => {
Expand Down
7 changes: 2 additions & 5 deletions src/Hooks/useGenerateSearchEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import {
IMinimizedSummaryEntry,
ISearchEntry,
} from '../components/Search/generateSearchEntries';
import { ISpecification, ISummary } from './useGetSummary';

interface IGenerateSearchEntries {
summary?: ISummary;
}
import { ISpecification } from 'spock-react-types';
import { IGenerateSearchEntries } from 'spock-react/hooks-types';

export const useGenerateSearchEntries = (
props: IGenerateSearchEntries
Expand Down
43 changes: 1 addition & 42 deletions src/Hooks/useGetSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,14 @@ import axios from 'axios';
import { useQuery, UseQueryResult } from '@tanstack/react-query';

import config from '../../environment.json';

interface IBlock {
kind: string;
text: string;
code: string[];
}

export interface IFeature {
id: string;
result: string;
duration: string;
iterations: {
tags: any;
see: any[];
extraInfo: any[];
};
blocks: IBlock[];
problems: any[];
}

interface ISpec {
className: string;
statistics: {
runs: string;
passed: string;
failed: string;
featureFailures: string;
successRate: string;
duration: string;
};
title: string;
narrative: string;
headers: string[];
tags: any;
see: any[];
features: IFeature[];
generator: string;
}
import { IGetSpec, ISpec } from 'spock-react/hooks-types';

const getSpec = async (file: string): Promise<ISpec> => {
const data = await axios.get(`${config.specUrl}/${file}.json`);

return data.data as ISpec;
};

interface IGetSpec {
fileName: string;
}

export const useGetSpec = (props: IGetSpec): UseQueryResult<ISpec, unknown> => {
const { fileName } = props;

Expand Down
36 changes: 1 addition & 35 deletions src/Hooks/useGetSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,14 @@ import axios from 'axios';
import { useQuery, UseQueryResult } from '@tanstack/react-query';

import config from '../../environment.json';
import { ISummary } from 'spock-react-types';

const getSummary = async (): Promise<ISummary> => {
const data = await axios.get(config.summaryUrl);

return data.data as ISummary;
};

export interface IExecutedFeatures {
id: string;
extraInfo: any[];
}

export interface ISpecification {
className: string;
title: string;
narrative: string;
featureCount: string;
failures: string;
errors: string;
skipped: string;
successRate: string;
duration: string;
executedFeatures: IExecutedFeatures[];
ignoredFeatures: any[];
}

export interface ISummary {
generator: string;
project: string;
version: string;
created: string;
statistics: {
runs: string;
passed: string;
failed: string;
featureFailures: string;
successRate: string;
duration: string;
};
specifications: ISpecification[];
}

export const useGetSummary = (): UseQueryResult<ISummary, unknown> => {
return useQuery<ISummary>({
queryKey: ['summary'],
Expand Down
5 changes: 1 addition & 4 deletions src/Hooks/useMarkdown.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { useQuery } from '@tanstack/react-query';
import { IMarkdown } from 'spock-react/hooks-types';

const getMarkdown = async (mdFile: string) => {
const data = await fetch(mdFile);
return await data.text();
};

interface IMarkdown {
filePath: string;
}

export const useMarkdown = (props: IMarkdown) => {
const { filePath } = props;

Expand Down
3 changes: 2 additions & 1 deletion src/components/MainNav/MainNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import * as config from '../../../environment.json';
import GithubLogo from '../../assets/img/github-mark-white.png';
import { Search } from '../Search';
import { NavLink } from '../shared';
import { ISummary, useActiveLink } from '../../Hooks';
import { useActiveLink } from '../../Hooks';
import { ISummary } from 'spock-react-types';

interface IMainNav {
summary: ISummary;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import './styles.css';
import { useState } from 'react';
import { Dialog, DialogBackdrop, Separator, useDialogState } from 'reakit';

import { ISummary } from '../../Hooks';
import { SearchButton } from './SearchButton';
import { SearchFooter } from './SearchFooter';
import { SearchHits } from './SearchHits';
import { SearchInput } from './SearchInput';
import { ISummary } from 'spock-react-types';

export interface ISearchHit {
score: number;
Expand Down
5 changes: 1 addition & 4 deletions src/components/Search/SearchHits/SearchCard/SearchCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import { Link } from 'react-router-dom';
import { faAngleRight } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import {
IExecutedFeatures,
ISpecification,
} from '../../../../Hooks/useGetSummary';
import { ISearchHit } from '../../Search';
import { IExecutedFeatures, ISpecification } from 'spock-react-types';

interface ISearchCard {
onClick: (e?: any) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/SearchHits/SearchHits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import './styles.css';
import { nanoid } from 'nanoid';
import { DialogStateReturn } from 'reakit/ts';

import { ISummary } from '../../../Hooks/useGetSummary';
import { ISearchHit } from '../Search';
import { SearchCard } from './SearchCard';
import { ISummary } from 'spock-react-types';

interface ISearchHits {
searchHits: ISearchHit[] | null;
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,9 +6,9 @@ import { faMagnifyingGlass } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { useGenerateSearchEntries } from '../../../Hooks/useGenerateSearchEntries';
import { ISummary } from '../../../Hooks/useGetSummary';
import { getSearchScore } from '../getSearchScore';
import { ISearchHit } from '../Search';
import { ISummary } from 'spock-react-types';

interface ISearchInput {
summary: ISummary;
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import './styles.css';

import { PropsWithChildren } from 'react';

import { IFeature } from '../../../Hooks';
import { OnPageNav } from './OnPageNav';
import { IFeature } from 'spock-react-types';

interface ILayout {
hasOnPageNav?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/Layout/OnPageNav.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nanoid } from 'nanoid';

import { IFeature } from '../../../Hooks';
import { NavAnchor } from '..';
import { IFeature } from '../../Feature';

interface IOnPageNave {
features: IFeature[];
Expand Down
3 changes: 2 additions & 1 deletion src/tests/example.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { describe, expect, test } from 'vitest';
import { renderHook } from '@testing-library/react-hooks';

import { App } from '../App';
import { ISummary, useGetSummary } from '../Hooks';
import { useGetSummary } from '../Hooks';
import { HookProvider, render } from '../test-utils';
import { ISummary } from 'spock-react-types';

describe('test', () => {
test('component example', () => {
Expand Down
55 changes: 55 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
declare module 'spock-react-types' {
export interface IExecutedFeatures {
id: string;
extraInfo: any[];
}

export interface ISpecification {
className: string;
title: string;
narrative: string;
featureCount: string;
failures: string;
errors: string;
skipped: string;
successRate: string;
duration: string;
executedFeatures: IExecutedFeatures[];
ignoredFeatures: any[];
}

export interface ISummary {
generator: string;
project: string;
version: string;
created: string;
statistics: {
runs: string;
passed: string;
failed: string;
featureFailures: string;
successRate: string;
duration: string;
};
specifications: ISpecification[];
}

interface IBlock {
kind: string;
text: string;
code: string[];
}

export interface IFeature {
id: string;
result: string;
duration: string;
iterations: {
tags: any;
see: any[];
extraInfo: any[];
};
blocks: IBlock[];
problems: any[];
}
}

0 comments on commit 734e81c

Please sign in to comment.