diff options
Diffstat (limited to 'server/sonar-web/src/main/js/components/docs')
19 files changed, 0 insertions, 1523 deletions
diff --git a/server/sonar-web/src/main/js/components/docs/DocCollapsibleBlock.tsx b/server/sonar-web/src/main/js/components/docs/DocCollapsibleBlock.tsx deleted file mode 100644 index 4a3eb1d604a..00000000000 --- a/server/sonar-web/src/main/js/components/docs/DocCollapsibleBlock.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import OpenCloseIcon from '../../components/icons/OpenCloseIcon'; - -interface State { - open: boolean; -} - -export default class DocCollapsibleBlock extends React.PureComponent<{}, State> { - state = { open: false }; - - handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => { - this.setState(state => ({ open: !state.open })); - event.stopPropagation(); - event.preventDefault(); - }; - - renderTitle(children: any) { - return ( - <a - aria-expanded={this.state.open} - aria-haspopup={true} - role="button" - className="link-no-underline" - href="#" - onClick={this.handleClick}> - <OpenCloseIcon className="text-middle little-spacer-right" open={this.state.open} /> - {children.props ? children.props.children : children} - </a> - ); - } - - render() { - const childrenAsArray = React.Children.toArray(this.props.children); - if (childrenAsArray.length < 1) { - return null; - } - - const firstChildChildren = React.Children.toArray( - (childrenAsArray[0] as React.ReactElement<any>).props.children - ); - if (firstChildChildren.length < 2) { - return null; - } - - return ( - <div className="collapse-container"> - {this.renderTitle(firstChildChildren[0])} - {this.state.open && firstChildChildren.slice(1)} - </div> - ); - } -} diff --git a/server/sonar-web/src/main/js/components/docs/DocImg.tsx b/server/sonar-web/src/main/js/components/docs/DocImg.tsx deleted file mode 100644 index b5cd154b2bf..00000000000 --- a/server/sonar-web/src/main/js/components/docs/DocImg.tsx +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { getBaseUrl } from '../../helpers/system'; - -export default function DocImg(props: React.ImgHTMLAttributes<HTMLImageElement>) { - const { alt, src, ...other } = props; - - if (process.env.NODE_ENV === 'development') { - return <img alt={alt} className="max-width-100" src={getBaseUrl() + src} {...other} />; - } - - return ( - <img - alt={alt} - className="max-width-100" - src={getBaseUrl() + '/images/embed-doc' + src} - {...other} - /> - ); -} diff --git a/server/sonar-web/src/main/js/components/docs/DocLink.tsx b/server/sonar-web/src/main/js/components/docs/DocLink.tsx deleted file mode 100644 index 78c3228bb92..00000000000 --- a/server/sonar-web/src/main/js/components/docs/DocLink.tsx +++ /dev/null @@ -1,113 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import withAppStateContext from '../../app/components/app-state/withAppStateContext'; -import { AppState } from '../../types/appstate'; -import Link from '../common/Link'; - -interface OwnProps { - appState: AppState; - customProps?: { - [k: string]: any; - }; -} - -type Props = OwnProps & React.AnchorHTMLAttributes<HTMLAnchorElement>; - -const SONARQUBE_LINK = '/#sonarqube#/'; -const SONARQUBE_ADMIN_LINK = '/#sonarqube-admin#/'; - -export class DocLink extends React.PureComponent<Props> { - handleClickOnAnchor = (event: React.MouseEvent<HTMLAnchorElement>) => { - const { customProps, href = '#' } = this.props; - if (customProps && customProps.onAnchorClick) { - customProps.onAnchorClick(href, event); - } - }; - - render() { - const { appState, children, href, customProps, ...other } = this.props; - if (href && href.startsWith('#')) { - return ( - <a href="#" onClick={this.handleClickOnAnchor}> - {children} - </a> - ); - } - - if (href && href.startsWith('/')) { - if (href.startsWith(SONARQUBE_LINK)) { - return <SonarQubeLink url={href}>{children}</SonarQubeLink>; - } else if (href.startsWith(SONARQUBE_ADMIN_LINK)) { - return ( - <SonarQubeAdminLink canAdmin={appState.canAdmin} url={href}> - {children} - </SonarQubeAdminLink> - ); - } - const url = '/documentation' + href; - return ( - <Link to={url} {...other}> - {children} - </Link> - ); - } - - return href ? ( - <Link to={href} target="_blank" size={12} {...other}> - {children} - </Link> - ) : null; - } -} - -export default withAppStateContext(DocLink); - -interface SonarQubeLinkProps { - children: React.ReactNode; - url: string; -} - -function SonarQubeLink({ children, url }: SonarQubeLinkProps) { - const to = `/${url.substr(SONARQUBE_LINK.length)}`; - return ( - <Link target="_blank" to={to}> - {children} - </Link> - ); -} - -interface SonarQubeAdminLinkProps { - canAdmin?: boolean; - children: React.ReactNode; - url: string; -} - -function SonarQubeAdminLink({ canAdmin, children, url }: SonarQubeAdminLinkProps) { - if (!canAdmin) { - return <>{children}</>; - } - const to = `/${url.substr(SONARQUBE_ADMIN_LINK.length)}`; - return ( - <Link target="_blank" to={to}> - {children} - </Link> - ); -} diff --git a/server/sonar-web/src/main/js/components/docs/DocMarkdownBlock.css b/server/sonar-web/src/main/js/components/docs/DocMarkdownBlock.css deleted file mode 100644 index 840ceebe78f..00000000000 --- a/server/sonar-web/src/main/js/components/docs/DocMarkdownBlock.css +++ /dev/null @@ -1,74 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -.markdown-content .alert { - margin-bottom: var(--gridSize); - border: 1px solid; - border-radius: 2px; -} - -.markdown-content .alert.is-inline { - display: inline-flex; -} - -.markdown-content .alert:empty { - display: none; -} - -.markdown-content .alert-error, -.markdown-content .alert-danger { - border-color: var(--alertBorderError); - background-color: var(--alertBackgroundError); - color: var(--alertTextError); -} - -.markdown-content .alert-error .alert-icon, -.markdown-content .alert-danger .alert-icon { - border-color: var(--alertBorderError); -} - -.markdown-content .alert-warning { - border-color: var(--alertBorderWarning); - background-color: var(--alertBackgroundWarning); - color: var(--alertTextWarning); -} - -.markdown-content .alert-warning .alert-icon { - border-color: var(--alertBorderWarning); -} - -.markdown-content .alert-info { - border-color: var(--alertBorderInfo); - background-color: var(--alertBackgroundInfo); - color: var(--alertTextInfo); -} - -.markdown-content .alert-info .alert-icon { - border-color: var(--alertBorderInfo); -} - -.markdown-content .alert-success { - border-color: var(--alertBorderSuccess); - background-color: var(--alertBackgroundSuccess); - color: var(--alertTextSuccess); -} - -.markdown-content .alert-success .alert-icon { - border-color: var(--alertBorderSuccess); -} diff --git a/server/sonar-web/src/main/js/components/docs/DocMarkdownBlock.tsx b/server/sonar-web/src/main/js/components/docs/DocMarkdownBlock.tsx deleted file mode 100644 index 2e9a7770578..00000000000 --- a/server/sonar-web/src/main/js/components/docs/DocMarkdownBlock.tsx +++ /dev/null @@ -1,140 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import classNames from 'classnames'; -import * as React from 'react'; -import rehypeRaw from 'rehype-raw'; -import rehypeReact from 'rehype-react'; -import rehypeSlug from 'rehype-slug'; -import remark from 'remark'; -import remarkCustomBlocks from 'remark-custom-blocks'; -import remarkRehype from 'remark-rehype'; -import { scrollToElement } from '../../helpers/scrolling'; -import { Dict } from '../../types/types'; -import DocCollapsibleBlock from './DocCollapsibleBlock'; -import DocImg from './DocImg'; -import DocLink from './DocLink'; -import './DocMarkdownBlock.css'; -import DocToc from './DocToc'; -import DocTooltipLink from './DocTooltipLink'; - -interface Props { - childProps?: Dict<string>; - className?: string; - content: string; - isTooltip?: boolean; - scrollToHref?: string; - stickyToc?: boolean; - title?: string; -} - -const WAIT_TIMEOUT = 500; - -export default class DocMarkdownBlock extends React.PureComponent<Props> { - node: HTMLElement | null = null; - - componentDidMount() { - const { scrollToHref } = this.props; - if (scrollToHref) { - setTimeout(() => { - this.handleAnchorClick(scrollToHref); - }, WAIT_TIMEOUT); - } - } - - handleAnchorClick = (href: string, event?: React.MouseEvent<HTMLAnchorElement>) => { - if (this.node) { - const element = this.node.querySelector(href); - if (element) { - if (event) { - event.preventDefault(); - } - scrollToElement(element, { bottomOffset: window.innerHeight - 80 }); - - // We cannot use React Router here, because we cannot simply replace a hash. - if (history.pushState) { - history.pushState(null, '', href); - } - } - } - }; - - render() { - const { childProps, content, className, title, stickyToc, isTooltip } = this.props; - - const md = remark(); - - // TODO find a way to replace these custom blocks with real Alert components - md.use(remarkCustomBlocks, { - danger: { classes: 'alert alert-danger' }, - warning: { classes: 'alert alert-warning' }, - info: { classes: 'alert alert-info' }, - success: { classes: 'alert alert-success' }, - collapse: { classes: 'collapse' } - }) - .use(remarkRehype, { allowDangerousHTML: true }) - .use(rehypeSlug) - .use(rehypeRaw) - .use(rehypeReact, { - createElement: React.createElement, - components: { - div: Block, - // use custom link to render documentation anchors - a: isTooltip - ? withChildProps(DocTooltipLink, childProps) - : withChildProps(DocLink, { onAnchorClick: this.handleAnchorClick }), - // use custom img tag to render documentation images - img: DocImg - } - }); - - return ( - <div - className={classNames('markdown', className, { 'has-toc': stickyToc })} - ref={ref => (this.node = ref)}> - <div className="markdown-content"> - {title !== undefined && <h1 className="documentation-title">{title}</h1>} - {md.processSync(content).contents} - </div> - {stickyToc && <DocToc content={content} onAnchorClick={this.handleAnchorClick} />} - </div> - ); - } -} - -function withChildProps<P>( - WrappedComponent: React.ComponentType<P & { customProps?: Dict<any> }>, - childProps?: Dict<any> -) { - return function withChildProps(props: P) { - return <WrappedComponent customProps={childProps} {...props} />; - }; -} - -function Block(props: React.HtmlHTMLAttributes<HTMLDivElement>) { - if (props.className) { - if (props.className.includes('collapse')) { - return <DocCollapsibleBlock>{props.children}</DocCollapsibleBlock>; - } else { - return <div className={classNames('cut-margins', props.className)}>{props.children}</div>; - } - } else { - return props.children; - } -} diff --git a/server/sonar-web/src/main/js/components/docs/DocToc.tsx b/server/sonar-web/src/main/js/components/docs/DocToc.tsx deleted file mode 100644 index 2332fd17337..00000000000 --- a/server/sonar-web/src/main/js/components/docs/DocToc.tsx +++ /dev/null @@ -1,155 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import classNames from 'classnames'; -import { debounce, memoize } from 'lodash'; -import * as React from 'react'; -import { findDOMNode } from 'react-dom'; -import remark from 'remark'; -import reactRenderer from 'remark-react'; -import { translate } from '../../helpers/l10n'; -import onlyToc from './plugins/remark-only-toc'; - -interface Props { - content: string; - onAnchorClick: (href: string, event: React.MouseEvent<HTMLAnchorElement>) => void; -} - -interface State { - anchors: AnchorObject[]; - highlightAnchor?: string; -} - -interface AnchorObject { - href: string; - title: string; -} - -export default class DocToc extends React.PureComponent<Props, State> { - debouncedScrollHandler: () => void; - - node: HTMLDivElement | null = null; - - state: State = { anchors: [] }; - - constructor(props: Props) { - super(props); - this.debouncedScrollHandler = debounce(this.scrollHandler); - } - - static getDerivedStateFromProps(props: Props) { - const { content } = props; - return { anchors: DocToc.getAnchors(content) }; - } - - componentDidMount() { - window.addEventListener('scroll', this.debouncedScrollHandler, true); - this.scrollHandler(); - } - - componentWillUnmount() { - window.removeEventListener('scroll', this.debouncedScrollHandler, true); - } - - static getAnchors = memoize((content: string) => { - const file: { contents: JSX.Element } = remark() - .use(reactRenderer) - .use(onlyToc) - .processSync('\n## doctoc\n' + content); - - if (file && file.contents.props.children) { - let list = file.contents; - let limit = 10; - while (limit && list.props.children.length && list.type !== 'ul') { - list = list.props.children[0]; - limit--; - } - - if (list.type === 'ul' && list.props.children.length) { - return list.props.children - .map((li: JSX.Element | string) => { - if (typeof li === 'string') { - return null; - } - - const anchor = li.props.children[0]; - return { - href: anchor.props.href, - title: anchor.props.children[0] - } as AnchorObject; - }) - .filter((item: AnchorObject | null) => item); - } - } - return []; - }); - - scrollHandler = () => { - // eslint-disable-next-line react/no-find-dom-node - const node = findDOMNode(this) as HTMLElement; - - if (!node || !node.parentNode) { - return; - } - - const headings: NodeListOf<HTMLHeadingElement> = node.parentNode.querySelectorAll('h2[id]'); - const scrollTop = window.pageYOffset || document.body.scrollTop; - let highlightAnchor; - - for (let i = 0, len = headings.length; i < len; i++) { - if (headings.item(i).offsetTop > scrollTop + 120) { - break; - } - highlightAnchor = `#${headings.item(i).id}`; - } - - this.setState({ - highlightAnchor - }); - }; - - render() { - const { anchors, highlightAnchor } = this.state; - - if (anchors.length === 0) { - return null; - } - - return ( - <div className="markdown-toc"> - <div className="markdown-toc-content"> - <h4>{translate('documentation.on_this_page')}</h4> - {anchors.map(anchor => { - return ( - <a - className={classNames({ active: highlightAnchor === anchor.href })} - href={anchor.href} - key={anchor.title} - onClick={(event: React.MouseEvent<HTMLAnchorElement>) => { - this.props.onAnchorClick(anchor.href, event); - }}> - {anchor.title} - </a> - ); - })} - </div> - </div> - ); - } -} diff --git a/server/sonar-web/src/main/js/components/docs/DocTooltipLink.tsx b/server/sonar-web/src/main/js/components/docs/DocTooltipLink.tsx deleted file mode 100644 index daf1c8c4662..00000000000 --- a/server/sonar-web/src/main/js/components/docs/DocTooltipLink.tsx +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { forEach } from 'lodash'; -import * as React from 'react'; -import { Dict } from '../../types/types'; -import Link from '../common/Link'; - -interface OwnProps { - customProps?: Dict<string>; -} - -type Props = OwnProps & React.AnchorHTMLAttributes<HTMLAnchorElement>; - -export default function DocTooltipLink({ children, customProps, href, ...other }: Props) { - if (customProps) { - forEach(customProps, (value, key) => { - if (href) { - href = href.replace(`#${key}#`, encodeURIComponent(value)); - } - }); - } - - if (href && href.startsWith('/')) { - href = `/documentation/${href.substr(1)}`; - - return ( - <Link target="_blank" to={href} {...other}> - {children} - </Link> - ); - } - - return href ? ( - <Link size={12} to={href} target="_blank" {...other}> - {children} - </Link> - ) : null; -} diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/DocCollapsibleBlock-test.tsx b/server/sonar-web/src/main/js/components/docs/__tests__/DocCollapsibleBlock-test.tsx deleted file mode 100644 index b0eba13816e..00000000000 --- a/server/sonar-web/src/main/js/components/docs/__tests__/DocCollapsibleBlock-test.tsx +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { click } from '../../../helpers/testUtils'; -import DocCollapsibleBlock from '../DocCollapsibleBlock'; - -const children = ( - <div> - <h2>Foo</h2> - <p>Bar</p> - </div> -); - -it('should render a collapsible block', () => { - const wrapper = shallow(<DocCollapsibleBlock>{children}</DocCollapsibleBlock>); - expect(wrapper).toMatchSnapshot(); - - click(wrapper.find('a')); - wrapper.update(); - expect(wrapper).toMatchSnapshot(); -}); - -it('should not render if not at least 2 children', () => { - const wrapper = shallow( - <DocCollapsibleBlock> - <div>foobar</div> - </DocCollapsibleBlock> - ); - expect(wrapper).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/DocLink-test.tsx b/server/sonar-web/src/main/js/components/docs/__tests__/DocLink-test.tsx deleted file mode 100644 index fbc71124d70..00000000000 --- a/server/sonar-web/src/main/js/components/docs/__tests__/DocLink-test.tsx +++ /dev/null @@ -1,82 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockAppState } from '../../../helpers/testMocks'; -import { DocLink } from '../DocLink'; - -it('should render simple link', () => { - expect( - shallow( - <DocLink appState={mockAppState({ canAdmin: false })} href="http://sample.com"> - link text - </DocLink> - ) - ).toMatchSnapshot(); -}); - -it('should render documentation link', () => { - expect( - shallow( - <DocLink appState={mockAppState({ canAdmin: false })} href="/foo/bar"> - link text - </DocLink> - ) - ).toMatchSnapshot(); -}); - -it('should render sonarqube link on sonarqube', () => { - const wrapper = shallow( - <DocLink appState={mockAppState({ canAdmin: false })} href="/#sonarqube#/foo/bar"> - link text - </DocLink> - ); - expect(wrapper).toMatchSnapshot(); - expect(wrapper.find('SonarQubeLink').dive()).toMatchSnapshot(); -}); - -it('should render sonarqube admin link on sonarqube for admin', () => { - const wrapper = shallow( - <DocLink appState={mockAppState({ canAdmin: true })} href="/#sonarqube-admin#/foo/bar"> - link text - </DocLink> - ); - expect(wrapper).toMatchSnapshot(); - expect(wrapper.find('SonarQubeAdminLink').dive()).toMatchSnapshot(); -}); - -it('should not render sonarqube admin link on sonarqube for non-admin', () => { - const wrapper = shallow( - <DocLink appState={mockAppState({ canAdmin: false })} href="/#sonarqube-admin#/foo/bar"> - link text - </DocLink> - ); - expect(wrapper.find('SonarQubeAdminLink').dive()).toMatchSnapshot(); -}); - -it('should render documentation anchor', () => { - expect( - shallow( - <DocLink appState={mockAppState({ canAdmin: false })} href="#quality-profiles"> - link text - </DocLink> - ) - ).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/DocMarkdownBlock-test.tsx b/server/sonar-web/src/main/js/components/docs/__tests__/DocMarkdownBlock-test.tsx deleted file mode 100644 index 1df772fbe6f..00000000000 --- a/server/sonar-web/src/main/js/components/docs/__tests__/DocMarkdownBlock-test.tsx +++ /dev/null @@ -1,153 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { scrollToElement } from '../../../helpers/scrolling'; -import { mockEvent } from '../../../helpers/testUtils'; -import DocMarkdownBlock from '../DocMarkdownBlock'; - -const CONTENT = ` -## Lorem ipsum - -Quisque vitae tincidunt felis. Nam blandit risus placerat, efficitur enim ut, pellentesque sem. Mauris non lorem auctor, consequat neque eget, dignissim augue. - -## Sit amet - -### Maecenas diam - -Velit, vestibulum nec ultrices id, mollis eget arcu. Sed dapibus, sapien ut auctor consectetur, mi tortor vestibulum ante, eget dapibus lacus risus. - -### Integer - -At cursus turpis. Aenean at elit fringilla, porttitor mi eget, dapibus nisi. Donec quis congue odio. - -## Nam blandit - -Risus placerat, efficitur enim ut, pellentesque sem. Mauris non lorem auctor, consequat neque eget, dignissim augue. -`; - -// mock `remark` & co to work around the issue with cjs imports -jest.mock('remark', () => jest.requireActual('remark')); -jest.mock('remark-rehype', () => jest.requireActual('remark-rehype')); -jest.mock('rehype-raw', () => jest.requireActual('rehype-raw')); -jest.mock('rehype-react', () => jest.requireActual('rehype-react')); -jest.mock('rehype-slug', () => jest.requireActual('rehype-slug')); - -jest.mock('../../../helpers/scrolling', () => ({ - scrollToElement: jest.fn() -})); - -const WINDOW_HEIGHT = 800; -const originalWindowHeight = window.innerHeight; - -const historyPushState = jest.fn(); -const originalHistoryPushState = history.pushState; - -beforeEach(jest.clearAllMocks); - -beforeAll(() => { - Object.defineProperty(window, 'innerHeight', { - writable: true, - configurable: true, - value: WINDOW_HEIGHT - }); - Object.defineProperty(history, 'pushState', { - writable: true, - configurable: true, - value: historyPushState - }); -}); - -afterAll(() => { - Object.defineProperty(window, 'innerHeight', { - writable: true, - configurable: true, - value: originalWindowHeight - }); - Object.defineProperty(history, 'pushState', { - writable: true, - configurable: true, - value: originalHistoryPushState - }); -}); - -it('should render correctly', () => { - expect(shallowRender({ content: 'this is *bold* text' })).toMatchSnapshot('default'); - expect( - shallowRender({ content: 'some [link](/quality-profiles)' }).find('withChildProps') - ).toMatchSnapshot('custom component for links'); - expect( - shallowRender({ - childProps: { foo: 'bar' }, - content: 'some [link](#quality-profiles)', - isTooltip: true - }).find('withChildProps') - ).toMatchSnapshot('custom props for links'); - expect(shallowRender({ content: CONTENT, stickyToc: true })).toMatchSnapshot('sticky TOC'); -}); - -it('should correctly scroll to clicked headings', () => { - const element = {} as Element; - const querySelector: (selector: string) => Element | null = jest.fn((selector: string) => - selector === '#id' ? element : null - ); - const preventDefault = jest.fn(); - const wrapper = shallowRender(); - const instance = wrapper.instance(); - - // Node Ref isn't set yet. - instance.handleAnchorClick('#unknown', mockEvent()); - expect(scrollToElement).not.toHaveBeenCalled(); - - // Set node Ref. - instance.node = { querySelector } as HTMLElement; - - // Unknown element. - instance.handleAnchorClick('#unknown', mockEvent()); - expect(scrollToElement).not.toHaveBeenCalled(); - - // Known element, should scroll. - instance.handleAnchorClick('#id', mockEvent({ preventDefault })); - expect(scrollToElement).toHaveBeenCalledWith(element, { bottomOffset: 720 }); - expect(preventDefault).toHaveBeenCalled(); - expect(historyPushState).toHaveBeenCalledWith(null, '', '#id'); -}); - -it('should correctly scroll to a specific heading if passed as a prop', () => { - jest.useFakeTimers(); - - const element = {} as Element; - const querySelector: (_: string) => Element | null = jest.fn(() => element); - const wrapper = shallowRender({ scrollToHref: '#id' }); - const instance = wrapper.instance(); - instance.node = { querySelector } as HTMLElement; - - expect(scrollToElement).not.toHaveBeenCalled(); - - jest.runAllTimers(); - - expect(scrollToElement).toHaveBeenCalledWith(element, { bottomOffset: 720 }); - jest.runOnlyPendingTimers(); - jest.useRealTimers(); -}); - -function shallowRender(props: Partial<DocMarkdownBlock['props']> = {}) { - return shallow<DocMarkdownBlock>(<DocMarkdownBlock content="" {...props} />); -} diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/DocToc-test.tsx b/server/sonar-web/src/main/js/components/docs/__tests__/DocToc-test.tsx deleted file mode 100644 index 1a837603275..00000000000 --- a/server/sonar-web/src/main/js/components/docs/__tests__/DocToc-test.tsx +++ /dev/null @@ -1,116 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { mount } from 'enzyme'; -import * as React from 'react'; -import { click, scrollTo } from '../../../helpers/testUtils'; -import DocToc from '../DocToc'; - -const OFFSET = 300; - -const CONTENT = ` -## Lorem ipsum - -Quisque vitae tincidunt felis. Nam blandit risus placerat, efficitur enim ut, pellentesque sem. Mauris non lorem auctor, consequat neque eget, dignissim augue. - -## Sit amet - -### Maecenas diam - -Velit, vestibulum nec ultrices id, mollis eget arcu. Sed dapibus, sapien ut auctor consectetur, mi tortor vestibulum ante, eget dapibus lacus risus. - -### Integer - -At cursus turpis. Aenean at elit fringilla, porttitor mi eget, dapibus nisi. Donec quis congue odio. - -## Nam blandit - -Risus placerat, efficitur enim ut, pellentesque sem. Mauris non lorem auctor, consequat neque eget, dignissim augue. -`; - -jest.mock('remark', () => { - const remark = jest.requireActual('remark'); - return remark; -}); - -jest.mock('remark-react', () => { - const remarkReact = jest.requireActual('remark-react'); - return remarkReact; -}); - -jest.mock('lodash', () => { - const lodash = jest.requireActual('lodash'); - lodash.debounce = (fn: any) => fn; - return lodash; -}); - -jest.mock('react-dom', () => ({ - findDOMNode: jest.fn() -})); - -it('should render correctly', () => { - const wrapper = renderComponent(); - expect(wrapper).toMatchSnapshot(); -}); - -it('should trigger the handler when an anchor is clicked', () => { - const onAnchorClick = jest.fn(); - const wrapper = renderComponent({ onAnchorClick }); - click(wrapper.find('a[href="#sit-amet"]')); - expect(onAnchorClick).toHaveBeenCalled(); -}); - -it('should highlight anchors when scrolling', () => { - mockDomEnv(); - const wrapper = renderComponent(); - - scrollTo({ top: OFFSET }); - expect(wrapper.state('highlightAnchor')).toEqual('#lorem-ipsum'); - - scrollTo({ top: OFFSET * 3 }); - expect(wrapper.state('highlightAnchor')).toEqual('#nam-blandit'); -}); - -function renderComponent(props: Partial<DocToc['props']> = {}) { - return mount(<DocToc content={CONTENT} onAnchorClick={jest.fn()} {...props} />); -} - -function mockDomEnv() { - const findDOMNode = require('react-dom').findDOMNode as jest.Mock<any>; - const parent = document.createElement('div'); - const element = document.createElement('div'); - parent.appendChild(element); - - let offset = OFFSET; - (CONTENT.match(/^## .+$/gm) as Array<string>).forEach(match => { - const slug = match - .replace(/^#+ */, '') - .replace(' ', '-') - .toLowerCase() - .trim(); - const heading = document.createElement('h2'); - heading.id = slug; - Object.defineProperty(heading, 'offsetTop', { value: offset }); - offset += OFFSET; - - parent.appendChild(heading); - }); - - findDOMNode.mockReturnValue(element); -} diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/DocTooltipLink-test.tsx b/server/sonar-web/src/main/js/components/docs/__tests__/DocTooltipLink-test.tsx deleted file mode 100644 index 632d4d31af6..00000000000 --- a/server/sonar-web/src/main/js/components/docs/__tests__/DocTooltipLink-test.tsx +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import DocTooltipLink from '../DocTooltipLink'; - -it('should render simple link', () => { - expect(shallow(<DocTooltipLink href="http://sample.com" />)).toMatchSnapshot(); -}); - -it('should render internal link', () => { - expect(shallow(<DocTooltipLink href="/foo/bar" />)).toMatchSnapshot(); -}); - -it('should render links with custom props', () => { - expect( - shallow(<DocTooltipLink customProps={{ bar: 'baz' }} href="/foo/#bar#" />) - ).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocCollapsibleBlock-test.tsx.snap b/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocCollapsibleBlock-test.tsx.snap deleted file mode 100644 index 7d1afc88f86..00000000000 --- a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocCollapsibleBlock-test.tsx.snap +++ /dev/null @@ -1,50 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should not render if not at least 2 children 1`] = `""`; - -exports[`should render a collapsible block 1`] = ` -<div - className="collapse-container" -> - <a - aria-expanded={false} - aria-haspopup={true} - className="link-no-underline" - href="#" - onClick={[Function]} - role="button" - > - <OpenCloseIcon - className="text-middle little-spacer-right" - open={false} - /> - Foo - </a> -</div> -`; - -exports[`should render a collapsible block 2`] = ` -<div - className="collapse-container" -> - <a - aria-expanded={true} - aria-haspopup={true} - className="link-no-underline" - href="#" - onClick={[Function]} - role="button" - > - <OpenCloseIcon - className="text-middle little-spacer-right" - open={true} - /> - Foo - </a> - <p - key=".1" - > - Bar - </p> -</div> -`; diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocLink-test.tsx.snap b/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocLink-test.tsx.snap deleted file mode 100644 index 48b6223cb29..00000000000 --- a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocLink-test.tsx.snap +++ /dev/null @@ -1,69 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should not render sonarqube admin link on sonarqube for non-admin 1`] = ` -<Fragment> - link text -</Fragment> -`; - -exports[`should render documentation anchor 1`] = ` -<a - href="#" - onClick={[Function]} -> - link text -</a> -`; - -exports[`should render documentation link 1`] = ` -<ForwardRef(Link) - to="/documentation/foo/bar" -> - link text -</ForwardRef(Link)> -`; - -exports[`should render simple link 1`] = ` -<ForwardRef(Link) - size={12} - target="_blank" - to="http://sample.com" -> - link text -</ForwardRef(Link)> -`; - -exports[`should render sonarqube admin link on sonarqube for admin 1`] = ` -<SonarQubeAdminLink - canAdmin={true} - url="/#sonarqube-admin#/foo/bar" -> - link text -</SonarQubeAdminLink> -`; - -exports[`should render sonarqube admin link on sonarqube for admin 2`] = ` -<ForwardRef(Link) - target="_blank" - to="/foo/bar" -> - link text -</ForwardRef(Link)> -`; - -exports[`should render sonarqube link on sonarqube 1`] = ` -<SonarQubeLink - url="/#sonarqube#/foo/bar" -> - link text -</SonarQubeLink> -`; - -exports[`should render sonarqube link on sonarqube 2`] = ` -<ForwardRef(Link) - target="_blank" - to="/foo/bar" -> - link text -</ForwardRef(Link)> -`; diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocMarkdownBlock-test.tsx.snap b/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocMarkdownBlock-test.tsx.snap deleted file mode 100644 index e15b023ec86..00000000000 --- a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocMarkdownBlock-test.tsx.snap +++ /dev/null @@ -1,148 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: custom component for links 1`] = ` -<withChildProps - href="/quality-profiles" - key="h-2" -> - link -</withChildProps> -`; - -exports[`should render correctly: custom props for links 1`] = ` -<withChildProps - href="#quality-profiles" - key="h-2" -> - link -</withChildProps> -`; - -exports[`should render correctly: default 1`] = ` -<div - className="markdown" -> - <div - className="markdown-content" - > - <div> - <p - key="h-1" - > - this is - <em - key="h-2" - > - bold - </em> - text - </p> - </div> - </div> -</div> -`; - -exports[`should render correctly: sticky TOC 1`] = ` -<div - className="markdown has-toc" -> - <div - className="markdown-content" - > - <div> - <Block - key="h-1" - > - <h2 - id="lorem-ipsum" - key="h-2" - > - Lorem ipsum - </h2> - - - <p - key="h-3" - > - Quisque vitae tincidunt felis. Nam blandit risus placerat, efficitur enim ut, pellentesque sem. Mauris non lorem auctor, consequat neque eget, dignissim augue. - </p> - - - <h2 - id="sit-amet" - key="h-4" - > - Sit amet - </h2> - - - <h3 - id="maecenas-diam" - key="h-5" - > - Maecenas diam - </h3> - - - <p - key="h-6" - > - Velit, vestibulum nec ultrices id, mollis eget arcu. Sed dapibus, sapien ut auctor consectetur, mi tortor vestibulum ante, eget dapibus lacus risus. - </p> - - - <h3 - id="integer" - key="h-7" - > - Integer - </h3> - - - <p - key="h-8" - > - At cursus turpis. Aenean at elit fringilla, porttitor mi eget, dapibus nisi. Donec quis congue odio. - </p> - - - <h2 - id="nam-blandit" - key="h-9" - > - Nam blandit - </h2> - - - <p - key="h-10" - > - Risus placerat, efficitur enim ut, pellentesque sem. Mauris non lorem auctor, consequat neque eget, dignissim augue. - </p> - </Block> - </div> - </div> - <DocToc - content=" -## Lorem ipsum - -Quisque vitae tincidunt felis. Nam blandit risus placerat, efficitur enim ut, pellentesque sem. Mauris non lorem auctor, consequat neque eget, dignissim augue. - -## Sit amet - -### Maecenas diam - -Velit, vestibulum nec ultrices id, mollis eget arcu. Sed dapibus, sapien ut auctor consectetur, mi tortor vestibulum ante, eget dapibus lacus risus. - -### Integer - -At cursus turpis. Aenean at elit fringilla, porttitor mi eget, dapibus nisi. Donec quis congue odio. - -## Nam blandit - -Risus placerat, efficitur enim ut, pellentesque sem. Mauris non lorem auctor, consequat neque eget, dignissim augue. -" - onAnchorClick={[Function]} - /> -</div> -`; diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocToc-test.tsx.snap b/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocToc-test.tsx.snap deleted file mode 100644 index ea33e896b40..00000000000 --- a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocToc-test.tsx.snap +++ /dev/null @@ -1,62 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<DocToc - content=" -## Lorem ipsum - -Quisque vitae tincidunt felis. Nam blandit risus placerat, efficitur enim ut, pellentesque sem. Mauris non lorem auctor, consequat neque eget, dignissim augue. - -## Sit amet - -### Maecenas diam - -Velit, vestibulum nec ultrices id, mollis eget arcu. Sed dapibus, sapien ut auctor consectetur, mi tortor vestibulum ante, eget dapibus lacus risus. - -### Integer - -At cursus turpis. Aenean at elit fringilla, porttitor mi eget, dapibus nisi. Donec quis congue odio. - -## Nam blandit - -Risus placerat, efficitur enim ut, pellentesque sem. Mauris non lorem auctor, consequat neque eget, dignissim augue. -" - onAnchorClick={[MockFunction]} -> - <div - className="markdown-toc" - > - <div - className="markdown-toc-content" - > - <h4> - documentation.on_this_page - </h4> - <a - className="" - href="#lorem-ipsum" - key="Lorem ipsum" - onClick={[Function]} - > - Lorem ipsum - </a> - <a - className="" - href="#sit-amet" - key="Sit amet" - onClick={[Function]} - > - Sit amet - </a> - <a - className="" - href="#nam-blandit" - key="Nam blandit" - onClick={[Function]} - > - Nam blandit - </a> - </div> - </div> -</DocToc> -`; diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocTooltipLink-test.tsx.snap b/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocTooltipLink-test.tsx.snap deleted file mode 100644 index 43cac601766..00000000000 --- a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocTooltipLink-test.tsx.snap +++ /dev/null @@ -1,23 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render internal link 1`] = ` -<ForwardRef(Link) - target="_blank" - to="/documentation/foo/bar" -/> -`; - -exports[`should render links with custom props 1`] = ` -<ForwardRef(Link) - target="_blank" - to="/documentation/foo/baz" -/> -`; - -exports[`should render simple link 1`] = ` -<ForwardRef(Link) - size={12} - target="_blank" - to="http://sample.com" -/> -`; diff --git a/server/sonar-web/src/main/js/components/docs/plugins/__tests__/remark-only-toc-test.ts b/server/sonar-web/src/main/js/components/docs/plugins/__tests__/remark-only-toc-test.ts deleted file mode 100644 index e3c6a7cde19..00000000000 --- a/server/sonar-web/src/main/js/components/docs/plugins/__tests__/remark-only-toc-test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import util from 'mdast-util-toc'; -import onlyToc from '../remark-only-toc'; - -jest.mock('mdast-util-toc', () => ({ - __esModule: true, - default: jest.fn().mockReturnValue({}) -})); - -it('should only render toc', () => { - const node = { type: 'test', children: ['a'] }; - onlyToc()(node); - expect(node.children).toHaveLength(0); - - (util as jest.Mock).mockReturnValue({ index: -1 }); - node.children.push('a'); - - onlyToc()(node); - expect(node.children).toHaveLength(0); - - (util as jest.Mock).mockReturnValue({ index: 0 }); - node.children.push('a'); - - onlyToc()(node); - expect(node.children).toHaveLength(0); - - (util as jest.Mock).mockReturnValue({ index: 0, map: 'a' }); - node.children.push('a'); - - onlyToc()(node); - expect(node.children).toHaveLength(1); -}); diff --git a/server/sonar-web/src/main/js/components/docs/plugins/remark-only-toc.ts b/server/sonar-web/src/main/js/components/docs/plugins/remark-only-toc.ts deleted file mode 100644 index 06d95a4ead9..00000000000 --- a/server/sonar-web/src/main/js/components/docs/plugins/remark-only-toc.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import util from 'mdast-util-toc'; -import { Node } from 'unist'; - -/** - * This is a simplified version of the remark-toc plugin: https://github.com/remarkjs/remark-toc - * It *only* renders the TOC, and leaves all the rest out. - */ -export default function onlyToc() { - return transformer; - - function transformer(node: Node) { - const result = util(node, { heading: 'doctoc', maxDepth: 2 }); - - if (result.index === null || result.index === -1 || !result.map) { - node.children = []; - } else { - node.children = [result.map]; - } - } -} |