Skip to content

Commit

Permalink
test: updating tests of next package
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasio committed Jul 9, 2024
1 parent ad6beaf commit a7dea3a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 8 deletions.
9 changes: 8 additions & 1 deletion packages/next/src/data/hooks/__tests__/useAppSettings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import type { AppEntity, EndpointParams } from '@headstartwp/core';
import { setHeadstartWPConfig, type AppEntity, type EndpointParams } from '@headstartwp/core';
import { expectTypeOf } from 'expect-type';
import { renderHook } from '@testing-library/react';
import { useAppSettings } from '../useAppSettings';

describe('useAppSettings types', () => {
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

it('allows overriding types', () => {
interface MyAppEntity extends AppEntity {
myCustomSetting: string;
Expand Down
9 changes: 8 additions & 1 deletion packages/next/src/data/hooks/__tests__/useAuthorArchive.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import type { PostEntity, PostsArchiveParams } from '@headstartwp/core';
import { setHeadstartWPConfig, type PostEntity, type PostsArchiveParams } from '@headstartwp/core';
import { renderHook } from '@testing-library/react';
import { expectTypeOf } from 'expect-type';
import { useAuthorArchive } from '../useAuthorArchive';

describe('useAuthorArchive types', () => {
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

it('allows overriding types', () => {
interface Book extends PostEntity {
isbn: string;
Expand Down
24 changes: 22 additions & 2 deletions packages/next/src/data/hooks/__tests__/usePosts.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PostEntity, PostsArchiveParams } from '@headstartwp/core';
import { setHeadstartWPConfig, type PostEntity, type PostsArchiveParams } from '@headstartwp/core';
import { SettingsProvider } from '@headstartwp/core/react';
import { renderHook, waitFor } from '@testing-library/react';
import { expectTypeOf } from 'expect-type';
Expand All @@ -12,8 +12,21 @@ jest.mock('next/router', () => ({
}));

describe('usePosts', () => {
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

const wrapper = ({ children }) => {
return <SettingsProvider settings={{ sourceUrl: '' }}>{children}</SettingsProvider>;
return (
<SettingsProvider
settings={{ sourceUrl: 'https://js1.10up.com', useWordPressPlugin: true }}
>
{children}
</SettingsProvider>
);
};

beforeAll(() => {
Expand All @@ -36,6 +49,13 @@ describe('usePosts types', () => {
useRouterMock.mockReturnValue({ query: { path: '' } });
});

beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

it('allows overriding types', () => {
interface Book extends PostEntity {
isbn: string;
Expand Down
20 changes: 18 additions & 2 deletions packages/next/src/data/hooks/__tests__/usePrepareFetch.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SettingsProvider } from '@headstartwp/core/react';
import { renderHook } from '@testing-library/react';
import * as React from 'react';
import { setHeadstartWPConfig } from '@headstartwp/core';
import { usePrepareFetch } from '../usePrepareFetch';

const useRouterMock = jest.fn();
Expand All @@ -10,11 +11,22 @@ jest.mock('next/router', () => ({
}));

describe('usePrepareFetch', () => {
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

it('injects locale if locale is set and polylang integration is enabled', () => {
const wrapper = ({ children }) => {
return (
<SettingsProvider
settings={{ sourceUrl: '', integrations: { polylang: { enable: true } } }}
settings={{
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
integrations: { polylang: { enable: true } },
}}
>
{children}
</SettingsProvider>
Expand All @@ -36,7 +48,11 @@ describe('usePrepareFetch', () => {
const wrapper = ({ children }) => {
return (
<SettingsProvider
settings={{ sourceUrl: '', integrations: { polylang: { enable: true } } }}
settings={{
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
integrations: { polylang: { enable: true } },
}}
>
{children}
</SettingsProvider>
Expand Down
9 changes: 8 additions & 1 deletion packages/next/src/data/hooks/__tests__/useSearch.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import type { PostEntity, PostsArchiveParams } from '@headstartwp/core';
import { setHeadstartWPConfig, type PostEntity, type PostsArchiveParams } from '@headstartwp/core';
import { renderHook } from '@testing-library/react';
import { expectTypeOf } from 'expect-type';
import { useSearch } from '../useSearch';

describe('useSearch types', () => {
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

it('allows overriding types', () => {
interface Book extends PostEntity {
isbn: string;
Expand Down
13 changes: 12 additions & 1 deletion packages/next/src/data/hooks/__tests__/useTerms.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import type { TaxonomyArchiveParams, TermEntity } from '@headstartwp/core';
import {
setHeadstartWPConfig,
type TaxonomyArchiveParams,
type TermEntity,
} from '@headstartwp/core';
import { renderHook } from '@testing-library/react';
import { expectTypeOf } from 'expect-type';
import { useTerms } from '../useTerms';

describe('useTerms types', () => {
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

it('allows overriding types', () => {
interface Genre extends TermEntity {
editor: string;
Expand Down

0 comments on commit a7dea3a

Please sign in to comment.