Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 6490bca

Browse files
fix: change button to href so that link is visible at the bottom
1 parent 6d2ab3d commit 6490bca

File tree

6 files changed

+20
-51
lines changed

6 files changed

+20
-51
lines changed

src/features/Apiexplorer/Schema/HighlightCode/HighlightCode.module.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
}
1919

2020
.schemaLink {
21-
cursor: pointer;
2221
text-decoration: underline;
22+
color: var(--ifm-link-white);
23+
&:hover {
24+
color: var(--ifm-link-white);
25+
}
2326
}

src/features/Apiexplorer/Schema/HighlightCode/__tests__/HighlightCode.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import React from 'react';
22
import { HighlightCode } from '..';
33
import { render, screen } from '@testing-library/react';
4-
5-
jest.mock('@docusaurus/router', () => ({
6-
useLocation: () => ({
7-
pathname: '',
8-
hash: '',
9-
}),
10-
useHistory: () => ({
11-
push: jest.fn(),
12-
}),
13-
}));
4+
import userEvent from '@testing-library/user-event';
145

156
describe('HighlightCode', () => {
167
it('should render HighlightCode properly', async () => {
@@ -29,4 +20,13 @@ describe('HighlightCode', () => {
2920
const empty_highlight = render(<HighlightCode description={null} />);
3021
expect(empty_highlight.container.firstChild).toBe(null);
3122
});
23+
24+
it('should render page of the selected api call name in the description', async () => {
25+
render(<HighlightCode description={'This is a `residence_list` test'} />);
26+
const api_call_name = screen.getByText(/residence_list/i);
27+
28+
await userEvent.click(api_call_name);
29+
30+
expect(api_call_name.closest('a')).toHaveAttribute('href', '#residence_list');
31+
});
3232
});

src/features/Apiexplorer/Schema/HighlightCode/index.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
import React from 'react';
22
import clsx from 'clsx';
3-
import { useHistory, useLocation } from '@docusaurus/router';
43
import { playground_requests } from '@site/src/utils/playground_requests';
54
import { SchemaDescriptionTypes } from '../RecursiveContent/SchemaDescription';
65
import styles from './HighlightCode.module.scss';
76

87
export const HighlightCode = ({ description }: SchemaDescriptionTypes) => {
9-
const { pathname } = useLocation();
10-
const history = useHistory();
11-
128
if (!description) return null;
139

1410
const [first, code, ...rest] = description.split('`');
1511

1612
const has_api_call = playground_requests.some((el) => el.name === code);
17-
const link_api_call = (api_call_name) => {
18-
window.scrollTo(0, 0);
19-
history.push(`${pathname}#${api_call_name}`);
20-
};
2113

2214
return (
2315
<React.Fragment>
2416
{first}
2517
{code && (
2618
<span className={clsx(styles.schemaRole, styles.schemaCode)}>
2719
{has_api_call ? (
28-
<button onClick={() => link_api_call(code)} className={styles.schemaLink}>
20+
<a
21+
href={`#${code}`}
22+
onClick={() => window.scrollTo(0, 0)}
23+
className={styles.schemaLink}
24+
>
2925
{code}
30-
</button>
26+
</a>
3127
) : (
3228
code
3329
)}

src/features/Apiexplorer/Schema/RecursiveContent/RecursiveProperties/__tests__/RecursiveProperties.test.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ const fakeItem = {
1919
},
2020
};
2121

22-
jest.mock('@docusaurus/router', () => ({
23-
useLocation: () => ({
24-
pathname: '',
25-
hash: '',
26-
}),
27-
useHistory: () => ({
28-
push: jest.fn(),
29-
}),
30-
}));
31-
3222
describe('RecursiveProperties', () => {
3323
it('should be able to render recursive items', async () => {
3424
render(

src/features/Apiexplorer/Schema/RecursiveContent/SchemaObjectContent/__tests__/SchemaObjectContent.test.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ import SchemaObjectContent from '..';
33
import userEvent from '@testing-library/user-event';
44
import { screen, render } from '@testing-library/react';
55

6-
jest.mock('@docusaurus/router', () => ({
7-
useLocation: () => ({
8-
pathname: '',
9-
hash: '',
10-
}),
11-
useHistory: () => ({
12-
push: jest.fn(),
13-
}),
14-
}));
15-
166
const fake_properties = {
177
test_item: {
188
description: 'test description',

src/features/Apiexplorer/Schema/SchemaProperties/__tests__/SchemaProperties.test.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ import SchemaProperties from '..';
33
import userEvent from '@testing-library/user-event';
44
import { render, screen } from '@testing-library/react';
55

6-
jest.mock('@docusaurus/router', () => ({
7-
useLocation: () => ({
8-
pathname: '',
9-
hash: '',
10-
}),
11-
useHistory: () => ({
12-
push: jest.fn(),
13-
}),
14-
}));
15-
166
describe('SchemaProperties', () => {
177
it('should throw an error when invalid JSON properties are passed', async () => {
188
const consoleOutput = [];

0 commit comments

Comments
 (0)