-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
140 additions
and
120 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/docusaurus-theme-common/src/contexts/__tests__/docsSidebar.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import {renderHook} from '@testing-library/react-hooks'; | ||
import {useDocsSidebar, DocsSidebarProvider} from '../docsSidebar'; | ||
import type {PropSidebar} from '@docusaurus/plugin-content-docs'; | ||
|
||
describe('useDocsSidebar', () => { | ||
it('throws if context provider is missing', () => { | ||
expect( | ||
() => renderHook(() => useDocsSidebar()).result.current, | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"Hook useDocsSidebar is called outside the <DocsSidebarProvider>. "`, | ||
); | ||
}); | ||
|
||
it('reads value from context provider', () => { | ||
const sidebar: PropSidebar = []; | ||
const {result} = renderHook(() => useDocsSidebar(), { | ||
wrapper: ({children}) => ( | ||
<DocsSidebarProvider sidebar={sidebar}>{children}</DocsSidebarProvider> | ||
), | ||
}); | ||
expect(result.current).toBe(sidebar); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
packages/docusaurus-theme-common/src/contexts/__tests__/docsVersion.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import {renderHook} from '@testing-library/react-hooks'; | ||
import {useDocsVersion, DocsVersionProvider} from '../docsVersion'; | ||
import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs'; | ||
|
||
function testVersion(data?: Partial<PropVersionMetadata>): PropVersionMetadata { | ||
return { | ||
version: 'versionName', | ||
label: 'Version Label', | ||
className: 'version className', | ||
badge: true, | ||
banner: 'unreleased', | ||
docs: {}, | ||
docsSidebars: {}, | ||
isLast: false, | ||
pluginId: 'default', | ||
...data, | ||
}; | ||
} | ||
|
||
describe('useDocsVersion', () => { | ||
it('throws if context provider is missing', () => { | ||
expect( | ||
() => renderHook(() => useDocsVersion()).result.current, | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"Hook useDocsVersion is called outside the <DocsVersionProvider>. "`, | ||
); | ||
}); | ||
|
||
it('reads value from context provider', () => { | ||
const version = testVersion(); | ||
const {result} = renderHook(() => useDocsVersion(), { | ||
wrapper: ({children}) => ( | ||
<DocsVersionProvider version={version}>{children}</DocsVersionProvider> | ||
), | ||
}); | ||
expect(result.current).toBe(version); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 0 additions & 58 deletions
58
packages/docusaurus-theme-common/src/utils/useContextualSearchFilters.ts
This file was deleted.
Oops, something went wrong.