@@ -19,25 +19,59 @@ | |||
*/ | |||
import { cloneDeep } from 'lodash'; | |||
import { OpenAPIV3 } from 'openapi-types'; | |||
import { fetchOpenAPI } from '../web-api'; | |||
import { mockAction } from '../../helpers/mocks/webapi'; | |||
import { fetchOpenAPI, fetchWebApi } from '../web-api'; | |||
import { openApiTestData } from './data/web-api'; | |||
jest.mock('../web-api'); | |||
const BASE_DOMAINS = [ | |||
{ | |||
actions: [ | |||
mockAction(), | |||
mockAction({ key: 'memos', description: 'get normal memos' }), | |||
mockAction({ | |||
key: 'deprecated', | |||
description: 'deprecated action', | |||
deprecatedSince: '2012-07-23', | |||
}), | |||
], | |||
description: 'foo', | |||
internal: false, | |||
path: 'foo/bar', | |||
since: '1.0', | |||
}, | |||
{ | |||
actions: [mockAction({ key: 'ia', description: 'get internal memos', internal: true })], | |||
description: 'internal stuff', | |||
internal: false, | |||
path: 'internal/thing1', | |||
since: '1.3', | |||
}, | |||
]; | |||
export default class WebApiServiceMock { | |||
openApiDocument: OpenAPIV3.Document; | |||
domains; | |||
constructor() { | |||
this.openApiDocument = cloneDeep(openApiTestData); | |||
this.domains = cloneDeep(BASE_DOMAINS); | |||
jest.mocked(fetchOpenAPI).mockImplementation(this.handleFetchOpenAPI); | |||
jest.mocked(fetchWebApi).mockImplementation(this.handleFetchWebAPI); | |||
} | |||
handleFetchOpenAPI: typeof fetchOpenAPI = () => { | |||
return Promise.resolve(this.openApiDocument); | |||
}; | |||
handleFetchWebAPI = () => { | |||
return Promise.resolve(this.domains); | |||
}; | |||
reset = () => { | |||
this.openApiDocument = cloneDeep(openApiTestData); | |||
this.domains = cloneDeep(BASE_DOMAINS); | |||
}; | |||
} |
@@ -0,0 +1,98 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 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 userEvent from '@testing-library/user-event'; | |||
import WebApiServiceMock from '../../../api/mocks/WebApiServiceMock'; | |||
import { renderAppRoutes } from '../../../helpers/testReactTestingUtils'; | |||
import { byLabelText, byRole, byText } from '../../../helpers/testSelector'; | |||
import routes from '../routes'; | |||
jest.mock('../../../components/common/ScreenPositionHelper'); | |||
const webApiHandler = new WebApiServiceMock(); | |||
jest.mock('../../../helpers/pages', () => ({ | |||
addSideBarClass: jest.fn(), | |||
removeSideBarClass: jest.fn(), | |||
})); | |||
beforeAll(() => { | |||
webApiHandler.reset(); | |||
}); | |||
it('should allow to browse the api', async () => { | |||
const user = userEvent.setup(); | |||
renderWebApi(); | |||
expect(await ui.sidebarHeader.find()).toBeInTheDocument(); | |||
expect(await ui.domainMenuItems.findAll()).toHaveLength(1); | |||
await user.click(ui.domainMenuItemLink('foo/bar').get()); | |||
expect(await ui.domainHeader('foo/bar').find()).toBeInTheDocument(); | |||
expect(await byText('get normal memos').find()).toBeInTheDocument(); | |||
expect(byText('Action 1').get()).toBeInTheDocument(); | |||
expect(byText('deprecated action').query()).not.toBeInTheDocument(); | |||
// Search to filter domains | |||
await user.type(ui.searchInput.get(), 'memo'); | |||
expect(await ui.domainMenuItems.findAll()).toHaveLength(1); | |||
// Open the domain again | |||
await user.click(ui.domainMenuItemLink('foo/bar').get()); | |||
expect(await byText('get normal memos').find()).toBeInTheDocument(); | |||
expect(byText('Action 1').query()).not.toBeInTheDocument(); | |||
expect(byText('deprecated action').query()).not.toBeInTheDocument(); | |||
await user.clear(ui.searchInput.get()); | |||
// Show internal | |||
await user.click(ui.showInternalCheckbox.get()); | |||
expect(await ui.domainMenuItems.findAll()).toHaveLength(2); | |||
await user.click(ui.domainMenuItemLink('internal/thing1 internal').get()); | |||
expect(await byText('get internal memos').find()).toBeInTheDocument(); | |||
expect(byText('get normal memos').query()).not.toBeInTheDocument(); | |||
expect(byText('Action 1').query()).not.toBeInTheDocument(); | |||
// Show deprecated | |||
await user.click(ui.showDeprecatedCheckbox.get()); | |||
await user.click(ui.domainMenuItemLink('foo/bar').get()); | |||
expect(await byText('deprecated action').find()).toBeInTheDocument(); | |||
expect(byText('get normal memos').get()).toBeInTheDocument(); | |||
expect(byText('Action 1').get()).toBeInTheDocument(); | |||
}); | |||
function renderWebApi(navigateTo?: string) { | |||
return renderAppRoutes('web_api', routes, { navigateTo }); | |||
} | |||
const ui = { | |||
domainMenuItems: byRole('menu').byRole('listitem'), | |||
domainMenuItemLink: (name: string) => byRole('menu').byRole('link', { name }), | |||
domainHeader: (name: string) => byRole('heading', { level: 2, name }), | |||
sidebarHeader: byRole('heading', { name: 'api_documentation.page' }), | |||
searchInput: byLabelText('api_documentation.search'), | |||
showInternalCheckbox: byRole('checkbox', { name: 'api_documentation.show_internal' }), | |||
showDeprecatedCheckbox: byRole('checkbox', { name: 'api_documentation.show_deprecated' }), | |||
}; |
@@ -46,25 +46,28 @@ export default function Menu(props: Props) { | |||
const renderDomain = (domain: WebApi.Domain) => { | |||
const internal = !domain.actions.find((action) => !action.internal); | |||
return ( | |||
<Link | |||
className={classNames('list-group-item', { | |||
<li | |||
className={classNames('list-group-item sw-p-0', { | |||
active: isDomainPathActive(domain.path, splat), | |||
})} | |||
key={domain.path} | |||
to={{ pathname: '/web_api/' + domain.path, search: queryToSearch(serializeQuery(query)) }} | |||
> | |||
<h3 className="list-group-item-heading"> | |||
{domain.path} | |||
{domain.deprecatedSince && <DeprecatedBadge since={domain.deprecatedSince} />} | |||
{internal && <InternalBadge />} | |||
</h3> | |||
</Link> | |||
<Link | |||
to={{ pathname: '/web_api/' + domain.path, search: queryToSearch(serializeQuery(query)) }} | |||
> | |||
<h3 className="sw-truncate sw-px-2 sw-py-3"> | |||
{domain.path} | |||
{domain.deprecatedSince && <DeprecatedBadge since={domain.deprecatedSince} />} | |||
{internal && <InternalBadge />} | |||
</h3> | |||
</Link> | |||
</li> | |||
); | |||
}; | |||
return ( | |||
<div className="api-documentation-results panel"> | |||
<div className="list-group">{filteredDomains.map(renderDomain)}</div> | |||
<div className="api-documentation-results panel" role="menu"> | |||
<ul className="list-group">{filteredDomains.map(renderDomain)}</ul> | |||
</div> | |||
); | |||
} |
@@ -1,75 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 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 Action from '../Action'; | |||
const ACTION = { | |||
key: 'foo', | |||
changelog: [{ description: 'Changelog desc', version: '5.0' }], | |||
description: 'Foo Desc', | |||
hasResponseExample: true, | |||
internal: false, | |||
params: [ | |||
{ | |||
key: 'param', | |||
description: 'Param desc', | |||
internal: true, | |||
required: true, | |||
}, | |||
], | |||
post: false, | |||
}; | |||
const DOMAIN = { | |||
actions: [ACTION], | |||
path: 'foo', | |||
description: 'API Foo', | |||
deprecated: false, | |||
internal: false, | |||
}; | |||
const PROPS = { | |||
action: ACTION, | |||
domain: DOMAIN, | |||
showDeprecated: false, | |||
showInternal: false, | |||
}; | |||
it('should render correctly', () => { | |||
expect(shallow(<Action {...PROPS} />)).toMatchSnapshot(); | |||
}); | |||
it('should display the params', () => { | |||
const wrapper = shallow(<Action {...PROPS} />); | |||
wrapper.setState({ showParams: true }); | |||
expect(wrapper.find('Params')).toMatchSnapshot(); | |||
}); | |||
it('should display the response example', () => { | |||
const wrapper = shallow(<Action {...PROPS} />); | |||
wrapper.setState({ showResponse: true }); | |||
expect(wrapper.find('ResponseExample')).toMatchSnapshot(); | |||
}); | |||
it('should display the changelog', () => { | |||
const wrapper = shallow(<Action {...PROPS} />); | |||
wrapper.setState({ showChangelog: true }); | |||
expect(wrapper.find('ActionChangelog')).toMatchSnapshot(); | |||
}); |
@@ -1,30 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 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 ActionChangelog from '../ActionChangelog'; | |||
it('should render', () => { | |||
const changelog = [ | |||
{ version: '5.0', description: 'foo' }, | |||
{ version: '5.1', description: 'bar' }, | |||
]; | |||
expect(shallow(<ActionChangelog changelog={changelog} />)).toMatchSnapshot(); | |||
}); |
@@ -0,0 +1,104 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 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 userEvent from '@testing-library/user-event'; | |||
import * as React from 'react'; | |||
import { mockAction, mockDomain, mockParam } from '../../../../helpers/mocks/webapi'; | |||
import { renderComponent } from '../../../../helpers/testReactTestingUtils'; | |||
import { byRole, byText } from '../../../../helpers/testSelector'; | |||
import Action from '../Action'; | |||
jest.mock('../../../../api/web-api', () => ({ | |||
fetchResponseExample: jest.fn().mockResolvedValue({ | |||
example: '{"example": "response"}', | |||
format: 'json', | |||
}), | |||
})); | |||
it('should have no additional information links', () => { | |||
renderAction(); | |||
expect(ui.changelogTab.query()).not.toBeInTheDocument(); | |||
expect(ui.paramsTab.query()).not.toBeInTheDocument(); | |||
expect(ui.responseExampleTab.query()).not.toBeInTheDocument(); | |||
}); | |||
it('should allow to browse additional information', async () => { | |||
const user = userEvent.setup(); | |||
renderAction({ | |||
action: mockAction({ | |||
changelog: [ | |||
{ description: 'change: Thing added', version: '1.2' }, | |||
{ description: 'change: thing removed', version: '2.6' }, | |||
], | |||
since: '1.0', | |||
params: [ | |||
mockParam({ key: 'id', description: 'param: identifier', required: true }), | |||
mockParam({ key: '2', description: 'param: other' }), | |||
], | |||
hasResponseExample: true, | |||
}), | |||
}); | |||
expect(ui.changelogTab.get()).toBeInTheDocument(); | |||
expect(ui.paramsTab.get()).toBeInTheDocument(); | |||
expect(ui.responseExampleTab.get()).toBeInTheDocument(); | |||
// All tabs should be hidden | |||
expect(byText(/change:/).queryAll()).toHaveLength(0); | |||
expect(byRole('row', { name: /param:/ }).queryAll()).toHaveLength(0); | |||
expect(byText('{"example": "response"}').query()).not.toBeInTheDocument(); | |||
await user.click(ui.changelogTab.get()); | |||
expect(byText(/change:/).getAll()).toHaveLength(2); | |||
expect(byRole('row', { name: /param:/ }).queryAll()).toHaveLength(0); | |||
expect(byText('{"example": "response"}').query()).not.toBeInTheDocument(); | |||
await user.click(ui.paramsTab.get()); | |||
expect(byText(/change:/).queryAll()).toHaveLength(0); | |||
expect(byRole('row', { name: /param:/ }).getAll()).toHaveLength(2); | |||
expect(byText('{"example": "response"}').query()).not.toBeInTheDocument(); | |||
await user.click(ui.responseExampleTab.get()); | |||
expect(byText(/change:/).queryAll()).toHaveLength(0); | |||
expect(byRole('row', { name: /param:/ }).queryAll()).toHaveLength(0); | |||
expect(await byText('{"example": "response"}').find()).toBeInTheDocument(); | |||
}); | |||
function renderAction(props: Partial<Action['props']> = {}) { | |||
renderComponent( | |||
<Action | |||
action={mockAction()} | |||
domain={mockDomain()} | |||
showDeprecated={false} | |||
showInternal={false} | |||
{...props} | |||
/> | |||
); | |||
} | |||
const ui = { | |||
paramsTab: byRole('link', { name: 'api_documentation.parameters' }), | |||
responseExampleTab: byRole('link', { name: 'api_documentation.response_example' }), | |||
changelogTab: byRole('link', { name: 'api_documentation.changelog' }), | |||
}; |
@@ -1,95 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 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 Domain from '../Domain'; | |||
const ACTION = { | |||
key: 'foo', | |||
changelog: [], | |||
description: 'Foo Desc', | |||
hasResponseExample: false, | |||
internal: false, | |||
post: false, | |||
}; | |||
const DOMAIN = { | |||
actions: [ACTION], | |||
path: 'api', | |||
description: 'API Desc', | |||
deprecated: false, | |||
internal: false, | |||
}; | |||
const DEFAULT_PROPS = { | |||
domain: DOMAIN, | |||
query: { search: '', deprecated: false, internal: false }, | |||
}; | |||
const SHOW_DEPRECATED = { search: '', deprecated: true, internal: false }; | |||
const SHOW_INTERNAL = { search: '', deprecated: false, internal: true }; | |||
const SEARCH_FOO = { search: 'Foo', deprecated: false, internal: false }; | |||
it('should render deprecated actions', () => { | |||
const action = { ...ACTION, deprecatedSince: '5.0' }; | |||
const domain = { ...DOMAIN, actions: [action] }; | |||
expect( | |||
shallow(<Domain {...DEFAULT_PROPS} domain={domain} query={SHOW_DEPRECATED} />) | |||
).toMatchSnapshot(); | |||
}); | |||
it('should not render deprecated actions', () => { | |||
const action = { ...ACTION, deprecatedSince: '5.0' }; | |||
const domain = { ...DOMAIN, actions: [action] }; | |||
expect( | |||
shallow(<Domain {...DEFAULT_PROPS} domain={domain} query={SHOW_INTERNAL} />) | |||
).toMatchSnapshot(); | |||
}); | |||
it('should render internal actions', () => { | |||
const action = { ...ACTION, internal: true }; | |||
const domain = { ...DOMAIN, actions: [action] }; | |||
expect( | |||
shallow(<Domain {...DEFAULT_PROPS} domain={domain} query={SHOW_INTERNAL} />) | |||
).toMatchSnapshot(); | |||
}); | |||
it('should not render internal actions', () => { | |||
const action = { ...ACTION, internal: true }; | |||
const domain = { ...DOMAIN, actions: [action] }; | |||
expect(shallow(<Domain {...DEFAULT_PROPS} domain={domain} />)).toMatchSnapshot(); | |||
}); | |||
it('should render only actions matching the query', () => { | |||
const actions = [ACTION, { ...ACTION, key: 'bar', description: 'Bar desc' }]; | |||
const domain = { ...DOMAIN, actions }; | |||
expect( | |||
shallow(<Domain {...DEFAULT_PROPS} domain={domain} query={SEARCH_FOO} />) | |||
).toMatchSnapshot(); | |||
}); | |||
it('should also render actions with a description matching the query', () => { | |||
const actions = [ | |||
ACTION, | |||
{ ...ACTION, key: 'bar', description: 'Bar desc' }, | |||
{ ...ACTION, key: 'baz', description: 'foobar' }, | |||
]; | |||
const domain = { ...DOMAIN, actions }; | |||
expect( | |||
shallow(<Domain {...DEFAULT_PROPS} domain={domain} query={SEARCH_FOO} />) | |||
).toMatchSnapshot(); | |||
}); |
@@ -1,112 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 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 { WebApi } from '../../../../types/types'; | |||
import Menu from '../Menu'; | |||
const ACTION: WebApi.Action = { | |||
key: 'foo', | |||
changelog: [], | |||
description: 'Foo Desc', | |||
hasResponseExample: false, | |||
internal: false, | |||
post: false, | |||
}; | |||
const DOMAIN1: WebApi.Domain = { | |||
actions: [ACTION], | |||
path: 'foo', | |||
description: 'API Foo', | |||
}; | |||
const DOMAIN2: WebApi.Domain = { | |||
actions: [ACTION], | |||
path: 'bar', | |||
description: 'API Bar', | |||
}; | |||
const PROPS = { | |||
domains: [DOMAIN1, DOMAIN2], | |||
query: { search: '', deprecated: false, internal: false }, | |||
splat: '', | |||
}; | |||
const SHOW_DEPRECATED = { search: '', deprecated: true, internal: false }; | |||
const SHOW_INTERNAL = { search: '', deprecated: false, internal: true }; | |||
const SEARCH_FOO = { search: 'Foo', deprecated: false, internal: false }; | |||
const SEARCH_BAR = { search: 'Bar', deprecated: false, internal: false }; | |||
it('should render deprecated domains', () => { | |||
const domain: WebApi.Domain = { | |||
...DOMAIN2, | |||
deprecatedSince: '5.0', | |||
actions: [{ ...ACTION, deprecatedSince: '5.0' }], | |||
}; | |||
const domains = [DOMAIN1, domain]; | |||
expect(shallow(<Menu {...PROPS} domains={domains} query={SHOW_DEPRECATED} />)).toMatchSnapshot(); | |||
}); | |||
it('should not render deprecated domains', () => { | |||
const domain: WebApi.Domain = { | |||
...DOMAIN2, | |||
deprecatedSince: '5.0', | |||
actions: [{ ...ACTION, deprecatedSince: '5.0' }], | |||
}; | |||
const domains = [DOMAIN1, domain]; | |||
expect(shallow(<Menu {...PROPS} domains={domains} />)).toMatchSnapshot(); | |||
}); | |||
it('should render internal domains', () => { | |||
const domain: WebApi.Domain = { | |||
...DOMAIN2, | |||
internal: true, | |||
actions: [{ ...ACTION, internal: true }], | |||
}; | |||
const domains = [DOMAIN1, domain]; | |||
expect(shallow(<Menu {...PROPS} domains={domains} query={SHOW_INTERNAL} />)).toMatchSnapshot(); | |||
}); | |||
it('should not render internal domains', () => { | |||
const domain: WebApi.Domain = { | |||
...DOMAIN2, | |||
internal: true, | |||
actions: [{ ...ACTION, internal: true }], | |||
}; | |||
const domains = [DOMAIN1, domain]; | |||
expect(shallow(<Menu {...PROPS} domains={domains} />)).toMatchSnapshot(); | |||
}); | |||
it('should render only domains with an action matching the query', () => { | |||
const domain: WebApi.Domain = { | |||
...DOMAIN2, | |||
actions: [{ ...ACTION, key: 'bar', description: 'Bar Desc' }], | |||
}; | |||
const domains = [DOMAIN1, domain]; | |||
expect(shallow(<Menu {...PROPS} domains={domains} query={SEARCH_FOO} />)).toMatchSnapshot(); | |||
}); | |||
it('should also render domains with an actions description matching the query', () => { | |||
const domain: WebApi.Domain = { | |||
...DOMAIN1, | |||
path: 'baz', | |||
description: 'API Baz', | |||
actions: [{ ...ACTION, key: 'baz', description: 'barbaz' }], | |||
}; | |||
const domains = [DOMAIN1, DOMAIN2, domain]; | |||
expect(shallow(<Menu {...PROPS} domains={domains} query={SEARCH_BAR} />)).toMatchSnapshot(); | |||
}); |
@@ -1,68 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 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 { WebApi } from '../../../../types/types'; | |||
import Params from '../Params'; | |||
const DEFAULT_PARAM: WebApi.Param = { | |||
key: 'foo', | |||
description: 'Foo desc', | |||
internal: false, | |||
required: false, | |||
}; | |||
it('should render deprecated and internal parameters', () => { | |||
const params = [ | |||
{ ...DEFAULT_PARAM, deprecatedSince: '5.0' }, | |||
{ ...DEFAULT_PARAM, deprecatedSince: '5.0', internal: true }, | |||
]; | |||
expect(shallow(<Params params={params} showDeprecated showInternal />)).toMatchSnapshot(); | |||
}); | |||
it('should not render deprecated parameters', () => { | |||
const params = [{ ...DEFAULT_PARAM, deprecatedSince: '5.0' }]; | |||
expect( | |||
shallow(<Params params={params} showDeprecated={false} showInternal={false} />) | |||
).toMatchSnapshot(); | |||
}); | |||
it('should render deprecated key', () => { | |||
const params = [ | |||
{ ...DEFAULT_PARAM, deprecatedKey: 'foo-deprecated', deprecatedKeySince: '5.0' }, | |||
{ ...DEFAULT_PARAM, deprecatedSince: '5.0', internal: true }, | |||
]; | |||
expect(shallow(<Params params={params} showDeprecated showInternal={false} />)).toMatchSnapshot(); | |||
}); | |||
it('should render different value constraints', () => { | |||
const param: WebApi.Param = { | |||
...DEFAULT_PARAM, | |||
defaultValue: 'def', | |||
exampleValue: 'foo', | |||
minimumLength: 2, | |||
maximumLength: 200, | |||
minimumValue: 1, | |||
maximumValue: 500, | |||
maxValuesAllowed: 1000, | |||
possibleValues: ['foo', 'bar'], | |||
}; | |||
expect(shallow(<Params params={[param]} showDeprecated showInternal />)).toMatchSnapshot(); | |||
}); |
@@ -1,50 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 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 ResponseExample from '../ResponseExample'; | |||
const ACTION = { | |||
key: 'foo', | |||
changelog: [], | |||
description: 'Foo Desc', | |||
hasResponseExample: false, | |||
internal: false, | |||
post: false, | |||
}; | |||
const DOMAIN = { | |||
actions: [ACTION], | |||
path: 'foo', | |||
description: 'API Foo', | |||
deprecated: false, | |||
internal: false, | |||
}; | |||
const PROPS = { | |||
action: ACTION, | |||
domain: DOMAIN, | |||
}; | |||
it('should render correctly after fetching an example', () => { | |||
const wrapper = shallow(<ResponseExample {...PROPS} />); | |||
expect(wrapper).toMatchSnapshot(); | |||
wrapper.setState({ responseExample: { format: 'json', example: 'my example' } }); | |||
expect(wrapper).toMatchSnapshot(); | |||
}); |
@@ -1,33 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 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 Search from '../Search'; | |||
const PROPS = { | |||
query: { search: '', deprecated: false, internal: false }, | |||
onSearch: () => {}, | |||
onToggleInternal: () => {}, | |||
onToggleDeprecated: () => {}, | |||
}; | |||
it('should render correctly', () => { | |||
expect(shallow(<Search {...PROPS} />)).toMatchSnapshot(); | |||
}); |
@@ -1,72 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 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 { fetchWebApi } from '../../../../api/web-api'; | |||
import { addSideBarClass, removeSideBarClass } from '../../../../helpers/pages'; | |||
import { mockLocation, mockRouter } from '../../../../helpers/testMocks'; | |||
import { waitAndUpdate } from '../../../../helpers/testUtils'; | |||
import { WebApiApp } from '../WebApiApp'; | |||
jest.mock('../../../../components/common/ScreenPositionHelper'); | |||
jest.mock('../../../../api/web-api', () => ({ | |||
fetchWebApi: jest.fn().mockResolvedValue([ | |||
{ | |||
actions: [], | |||
description: 'foo', | |||
internal: true, | |||
path: 'foo/bar', | |||
since: '1.0', | |||
}, | |||
]), | |||
})); | |||
jest.mock('../../../../helpers/pages', () => ({ | |||
addSideBarClass: jest.fn(), | |||
removeSideBarClass: jest.fn(), | |||
})); | |||
it('should render correctly', async () => { | |||
(global as any).scrollTo = jest.fn(); | |||
const wrapper = shallowRender(); | |||
expect(addSideBarClass).toHaveBeenCalled(); | |||
expect(fetchWebApi).toHaveBeenCalled(); | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper).toMatchSnapshot(); | |||
expect(wrapper.find('ScreenPositionHelper').dive()).toMatchSnapshot(); | |||
wrapper.unmount(); | |||
expect(removeSideBarClass).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<WebApiApp['props']> = {}) { | |||
return shallow( | |||
<WebApiApp | |||
location={mockLocation()} | |||
params={{ splat: 'foo/bar' }} | |||
router={mockRouter()} | |||
{...props} | |||
/> | |||
); | |||
} |
@@ -1,160 +0,0 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
exports[`should display the changelog 1`] = ` | |||
<ActionChangelog | |||
changelog={ | |||
[ | |||
{ | |||
"description": "Changelog desc", | |||
"version": "5.0", | |||
}, | |||
] | |||
} | |||
/> | |||
`; | |||
exports[`should display the params 1`] = ` | |||
<Params | |||
params={ | |||
[ | |||
{ | |||
"description": "Param desc", | |||
"internal": true, | |||
"key": "param", | |||
"required": true, | |||
}, | |||
] | |||
} | |||
showDeprecated={false} | |||
showInternal={false} | |||
/> | |||
`; | |||
exports[`should display the response example 1`] = ` | |||
<ResponseExample | |||
action={ | |||
{ | |||
"changelog": [ | |||
{ | |||
"description": "Changelog desc", | |||
"version": "5.0", | |||
}, | |||
], | |||
"description": "Foo Desc", | |||
"hasResponseExample": true, | |||
"internal": false, | |||
"key": "foo", | |||
"params": [ | |||
{ | |||
"description": "Param desc", | |||
"internal": true, | |||
"key": "param", | |||
"required": true, | |||
}, | |||
], | |||
"post": false, | |||
} | |||
} | |||
domain={ | |||
{ | |||
"actions": [ | |||
{ | |||
"changelog": [ | |||
{ | |||
"description": "Changelog desc", | |||
"version": "5.0", | |||
}, | |||
], | |||
"description": "Foo Desc", | |||
"hasResponseExample": true, | |||
"internal": false, | |||
"key": "foo", | |||
"params": [ | |||
{ | |||
"description": "Param desc", | |||
"internal": true, | |||
"key": "param", | |||
"required": true, | |||
}, | |||
], | |||
"post": false, | |||
}, | |||
], | |||
"deprecated": false, | |||
"description": "API Foo", | |||
"internal": false, | |||
"path": "foo", | |||
} | |||
} | |||
/> | |||
`; | |||
exports[`should render correctly 1`] = ` | |||
<div | |||
className="boxed-group" | |||
id="foo/foo" | |||
> | |||
<header | |||
className="web-api-action-header boxed-group-header" | |||
> | |||
<ForwardRef(Link) | |||
className="spacer-right link-no-underline" | |||
to={ | |||
{ | |||
"pathname": "/web_api/foo/foo", | |||
"search": "?", | |||
} | |||
} | |||
> | |||
<LinkIcon /> | |||
</ForwardRef(Link)> | |||
<h3 | |||
className="web-api-action-title" | |||
> | |||
GET | |||
foo/foo | |||
</h3> | |||
</header> | |||
<div | |||
className="boxed-group-inner" | |||
> | |||
<div | |||
className="web-api-action-description markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "Foo Desc", | |||
} | |||
} | |||
/> | |||
<ul | |||
className="web-api-action-actions tabs" | |||
> | |||
<li> | |||
<a | |||
href="#" | |||
onClick={[Function]} | |||
> | |||
api_documentation.parameters | |||
</a> | |||
</li> | |||
<li> | |||
<a | |||
href="#" | |||
onClick={[Function]} | |||
> | |||
api_documentation.response_example | |||
</a> | |||
</li> | |||
<li> | |||
<a | |||
href="#" | |||
onClick={[Function]} | |||
> | |||
api_documentation.changelog | |||
</a> | |||
</li> | |||
</ul> | |||
</div> | |||
</div> | |||
`; |
@@ -1,30 +0,0 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
exports[`should render 1`] = ` | |||
<ul | |||
className="big-spacer-top" | |||
> | |||
<li | |||
className="spacer-top" | |||
key="0" | |||
> | |||
<span | |||
className="spacer-right badge" | |||
> | |||
5.0 | |||
</span> | |||
foo | |||
</li> | |||
<li | |||
className="spacer-top" | |||
key="1" | |||
> | |||
<span | |||
className="spacer-right badge" | |||
> | |||
5.1 | |||
</span> | |||
bar | |||
</li> | |||
</ul> | |||
`; |
@@ -1,37 +0,0 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
exports[`should render with malformed version 1`] = ` | |||
<Tooltip | |||
overlay="api_documentation.deprecation_tooltip" | |||
> | |||
<span | |||
className="badge badge-warning" | |||
> | |||
api_documentation.deprecated_since_x.foo | |||
</span> | |||
</Tooltip> | |||
`; | |||
exports[`should render with version 1`] = ` | |||
<Tooltip | |||
overlay="api_documentation.will_be_removed_in_x.6.0" | |||
> | |||
<span | |||
className="badge badge-warning" | |||
> | |||
api_documentation.deprecated_since_x.5.6 | |||
</span> | |||
</Tooltip> | |||
`; | |||
exports[`should render without version 1`] = ` | |||
<Tooltip | |||
overlay="api_documentation.deprecation_tooltip" | |||
> | |||
<span | |||
className="badge badge-warning" | |||
> | |||
api_documentation.deprecated | |||
</span> | |||
</Tooltip> | |||
`; |
@@ -1,374 +0,0 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
exports[`should also render actions with a description matching the query 1`] = ` | |||
<div | |||
className="web-api-domain" | |||
> | |||
<header | |||
className="web-api-domain-header" | |||
> | |||
<h2 | |||
className="web-api-domain-title" | |||
> | |||
api | |||
</h2> | |||
</header> | |||
<div | |||
className="web-api-domain-description markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "API Desc", | |||
} | |||
} | |||
/> | |||
<div | |||
className="web-api-domain-actions" | |||
> | |||
<Action | |||
action={ | |||
{ | |||
"changelog": [], | |||
"description": "Foo Desc", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "foo", | |||
"post": false, | |||
} | |||
} | |||
domain={ | |||
{ | |||
"actions": [ | |||
{ | |||
"changelog": [], | |||
"description": "Foo Desc", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "foo", | |||
"post": false, | |||
}, | |||
{ | |||
"changelog": [], | |||
"description": "Bar desc", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "bar", | |||
"post": false, | |||
}, | |||
{ | |||
"changelog": [], | |||
"description": "foobar", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "baz", | |||
"post": false, | |||
}, | |||
], | |||
"deprecated": false, | |||
"description": "API Desc", | |||
"internal": false, | |||
"path": "api", | |||
} | |||
} | |||
key="api/foo" | |||
showDeprecated={false} | |||
showInternal={false} | |||
/> | |||
<Action | |||
action={ | |||
{ | |||
"changelog": [], | |||
"description": "foobar", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "baz", | |||
"post": false, | |||
} | |||
} | |||
domain={ | |||
{ | |||
"actions": [ | |||
{ | |||
"changelog": [], | |||
"description": "Foo Desc", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "foo", | |||
"post": false, | |||
}, | |||
{ | |||
"changelog": [], | |||
"description": "Bar desc", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "bar", | |||
"post": false, | |||
}, | |||
{ | |||
"changelog": [], | |||
"description": "foobar", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "baz", | |||
"post": false, | |||
}, | |||
], | |||
"deprecated": false, | |||
"description": "API Desc", | |||
"internal": false, | |||
"path": "api", | |||
} | |||
} | |||
key="api/baz" | |||
showDeprecated={false} | |||
showInternal={false} | |||
/> | |||
</div> | |||
</div> | |||
`; | |||
exports[`should not render deprecated actions 1`] = ` | |||
<div | |||
className="web-api-domain" | |||
> | |||
<header | |||
className="web-api-domain-header" | |||
> | |||
<h2 | |||
className="web-api-domain-title" | |||
> | |||
api | |||
</h2> | |||
</header> | |||
<div | |||
className="web-api-domain-description markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "API Desc", | |||
} | |||
} | |||
/> | |||
<div | |||
className="web-api-domain-actions" | |||
/> | |||
</div> | |||
`; | |||
exports[`should not render internal actions 1`] = ` | |||
<div | |||
className="web-api-domain" | |||
> | |||
<header | |||
className="web-api-domain-header" | |||
> | |||
<h2 | |||
className="web-api-domain-title" | |||
> | |||
api | |||
</h2> | |||
</header> | |||
<div | |||
className="web-api-domain-description markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "API Desc", | |||
} | |||
} | |||
/> | |||
<div | |||
className="web-api-domain-actions" | |||
/> | |||
</div> | |||
`; | |||
exports[`should render deprecated actions 1`] = ` | |||
<div | |||
className="web-api-domain" | |||
> | |||
<header | |||
className="web-api-domain-header" | |||
> | |||
<h2 | |||
className="web-api-domain-title" | |||
> | |||
api | |||
</h2> | |||
</header> | |||
<div | |||
className="web-api-domain-description markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "API Desc", | |||
} | |||
} | |||
/> | |||
<div | |||
className="web-api-domain-actions" | |||
> | |||
<Action | |||
action={ | |||
{ | |||
"changelog": [], | |||
"deprecatedSince": "5.0", | |||
"description": "Foo Desc", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "foo", | |||
"post": false, | |||
} | |||
} | |||
domain={ | |||
{ | |||
"actions": [ | |||
{ | |||
"changelog": [], | |||
"deprecatedSince": "5.0", | |||
"description": "Foo Desc", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "foo", | |||
"post": false, | |||
}, | |||
], | |||
"deprecated": false, | |||
"description": "API Desc", | |||
"internal": false, | |||
"path": "api", | |||
} | |||
} | |||
key="api/foo" | |||
showDeprecated={true} | |||
showInternal={false} | |||
/> | |||
</div> | |||
</div> | |||
`; | |||
exports[`should render internal actions 1`] = ` | |||
<div | |||
className="web-api-domain" | |||
> | |||
<header | |||
className="web-api-domain-header" | |||
> | |||
<h2 | |||
className="web-api-domain-title" | |||
> | |||
api | |||
</h2> | |||
</header> | |||
<div | |||
className="web-api-domain-description markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "API Desc", | |||
} | |||
} | |||
/> | |||
<div | |||
className="web-api-domain-actions" | |||
> | |||
<Action | |||
action={ | |||
{ | |||
"changelog": [], | |||
"description": "Foo Desc", | |||
"hasResponseExample": false, | |||
"internal": true, | |||
"key": "foo", | |||
"post": false, | |||
} | |||
} | |||
domain={ | |||
{ | |||
"actions": [ | |||
{ | |||
"changelog": [], | |||
"description": "Foo Desc", | |||
"hasResponseExample": false, | |||
"internal": true, | |||
"key": "foo", | |||
"post": false, | |||
}, | |||
], | |||
"deprecated": false, | |||
"description": "API Desc", | |||
"internal": false, | |||
"path": "api", | |||
} | |||
} | |||
key="api/foo" | |||
showDeprecated={false} | |||
showInternal={true} | |||
/> | |||
</div> | |||
</div> | |||
`; | |||
exports[`should render only actions matching the query 1`] = ` | |||
<div | |||
className="web-api-domain" | |||
> | |||
<header | |||
className="web-api-domain-header" | |||
> | |||
<h2 | |||
className="web-api-domain-title" | |||
> | |||
api | |||
</h2> | |||
</header> | |||
<div | |||
className="web-api-domain-description markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "API Desc", | |||
} | |||
} | |||
/> | |||
<div | |||
className="web-api-domain-actions" | |||
> | |||
<Action | |||
action={ | |||
{ | |||
"changelog": [], | |||
"description": "Foo Desc", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "foo", | |||
"post": false, | |||
} | |||
} | |||
domain={ | |||
{ | |||
"actions": [ | |||
{ | |||
"changelog": [], | |||
"description": "Foo Desc", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "foo", | |||
"post": false, | |||
}, | |||
{ | |||
"changelog": [], | |||
"description": "Bar desc", | |||
"hasResponseExample": false, | |||
"internal": false, | |||
"key": "bar", | |||
"post": false, | |||
}, | |||
], | |||
"deprecated": false, | |||
"description": "API Desc", | |||
"internal": false, | |||
"path": "api", | |||
} | |||
} | |||
key="api/foo" | |||
showDeprecated={false} | |||
showInternal={false} | |||
/> | |||
</div> | |||
</div> | |||
`; |
@@ -1,215 +0,0 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
exports[`should also render domains with an actions description matching the query 1`] = ` | |||
<div | |||
className="api-documentation-results panel" | |||
> | |||
<div | |||
className="list-group" | |||
> | |||
<ForwardRef(Link) | |||
className="list-group-item" | |||
key="bar" | |||
to={ | |||
{ | |||
"pathname": "/web_api/bar", | |||
"search": "?query=Bar", | |||
} | |||
} | |||
> | |||
<h3 | |||
className="list-group-item-heading" | |||
> | |||
bar | |||
</h3> | |||
</ForwardRef(Link)> | |||
<ForwardRef(Link) | |||
className="list-group-item" | |||
key="baz" | |||
to={ | |||
{ | |||
"pathname": "/web_api/baz", | |||
"search": "?query=Bar", | |||
} | |||
} | |||
> | |||
<h3 | |||
className="list-group-item-heading" | |||
> | |||
baz | |||
</h3> | |||
</ForwardRef(Link)> | |||
</div> | |||
</div> | |||
`; | |||
exports[`should not render deprecated domains 1`] = ` | |||
<div | |||
className="api-documentation-results panel" | |||
> | |||
<div | |||
className="list-group" | |||
> | |||
<ForwardRef(Link) | |||
className="list-group-item" | |||
key="foo" | |||
to={ | |||
{ | |||
"pathname": "/web_api/foo", | |||
"search": "?", | |||
} | |||
} | |||
> | |||
<h3 | |||
className="list-group-item-heading" | |||
> | |||
foo | |||
</h3> | |||
</ForwardRef(Link)> | |||
</div> | |||
</div> | |||
`; | |||
exports[`should not render internal domains 1`] = ` | |||
<div | |||
className="api-documentation-results panel" | |||
> | |||
<div | |||
className="list-group" | |||
> | |||
<ForwardRef(Link) | |||
className="list-group-item" | |||
key="foo" | |||
to={ | |||
{ | |||
"pathname": "/web_api/foo", | |||
"search": "?", | |||
} | |||
} | |||
> | |||
<h3 | |||
className="list-group-item-heading" | |||
> | |||
foo | |||
</h3> | |||
</ForwardRef(Link)> | |||
</div> | |||
</div> | |||
`; | |||
exports[`should render deprecated domains 1`] = ` | |||
<div | |||
className="api-documentation-results panel" | |||
> | |||
<div | |||
className="list-group" | |||
> | |||
<ForwardRef(Link) | |||
className="list-group-item" | |||
key="foo" | |||
to={ | |||
{ | |||
"pathname": "/web_api/foo", | |||
"search": "?deprecated=true", | |||
} | |||
} | |||
> | |||
<h3 | |||
className="list-group-item-heading" | |||
> | |||
foo | |||
</h3> | |||
</ForwardRef(Link)> | |||
<ForwardRef(Link) | |||
className="list-group-item" | |||
key="bar" | |||
to={ | |||
{ | |||
"pathname": "/web_api/bar", | |||
"search": "?deprecated=true", | |||
} | |||
} | |||
> | |||
<h3 | |||
className="list-group-item-heading" | |||
> | |||
bar | |||
<DeprecatedBadge | |||
since="5.0" | |||
/> | |||
</h3> | |||
</ForwardRef(Link)> | |||
</div> | |||
</div> | |||
`; | |||
exports[`should render internal domains 1`] = ` | |||
<div | |||
className="api-documentation-results panel" | |||
> | |||
<div | |||
className="list-group" | |||
> | |||
<ForwardRef(Link) | |||
className="list-group-item" | |||
key="foo" | |||
to={ | |||
{ | |||
"pathname": "/web_api/foo", | |||
"search": "?internal=true", | |||
} | |||
} | |||
> | |||
<h3 | |||
className="list-group-item-heading" | |||
> | |||
foo | |||
</h3> | |||
</ForwardRef(Link)> | |||
<ForwardRef(Link) | |||
className="list-group-item" | |||
key="bar" | |||
to={ | |||
{ | |||
"pathname": "/web_api/bar", | |||
"search": "?internal=true", | |||
} | |||
} | |||
> | |||
<h3 | |||
className="list-group-item-heading" | |||
> | |||
bar | |||
<InternalBadge /> | |||
</h3> | |||
</ForwardRef(Link)> | |||
</div> | |||
</div> | |||
`; | |||
exports[`should render only domains with an action matching the query 1`] = ` | |||
<div | |||
className="api-documentation-results panel" | |||
> | |||
<div | |||
className="list-group" | |||
> | |||
<ForwardRef(Link) | |||
className="list-group-item" | |||
key="foo" | |||
to={ | |||
{ | |||
"pathname": "/web_api/foo", | |||
"search": "?query=Foo", | |||
} | |||
} | |||
> | |||
<h3 | |||
className="list-group-item-heading" | |||
> | |||
foo | |||
</h3> | |||
</ForwardRef(Link)> | |||
</div> | |||
</div> | |||
`; |
@@ -1,331 +0,0 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
exports[`should not render deprecated parameters 1`] = ` | |||
<div | |||
className="web-api-params" | |||
> | |||
<table> | |||
<tbody /> | |||
</table> | |||
</div> | |||
`; | |||
exports[`should render deprecated and internal parameters 1`] = ` | |||
<div | |||
className="web-api-params" | |||
> | |||
<table> | |||
<tbody> | |||
<tr | |||
key="foo" | |||
> | |||
<td | |||
className="markdown" | |||
style={ | |||
{ | |||
"width": 180, | |||
} | |||
} | |||
> | |||
<code> | |||
foo | |||
</code> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<DeprecatedBadge | |||
since="5.0" | |||
/> | |||
</div> | |||
<div | |||
className="note little-spacer-top" | |||
> | |||
optional | |||
</div> | |||
</td> | |||
<td> | |||
<div | |||
className="markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "Foo desc", | |||
} | |||
} | |||
/> | |||
</td> | |||
<td | |||
style={ | |||
{ | |||
"width": 250, | |||
} | |||
} | |||
/> | |||
</tr> | |||
<tr | |||
key="foo" | |||
> | |||
<td | |||
className="markdown" | |||
style={ | |||
{ | |||
"width": 180, | |||
} | |||
} | |||
> | |||
<code> | |||
foo | |||
</code> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<InternalBadge /> | |||
</div> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<DeprecatedBadge | |||
since="5.0" | |||
/> | |||
</div> | |||
<div | |||
className="note little-spacer-top" | |||
> | |||
optional | |||
</div> | |||
</td> | |||
<td> | |||
<div | |||
className="markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "Foo desc", | |||
} | |||
} | |||
/> | |||
</td> | |||
<td | |||
style={ | |||
{ | |||
"width": 250, | |||
} | |||
} | |||
/> | |||
</tr> | |||
</tbody> | |||
</table> | |||
</div> | |||
`; | |||
exports[`should render deprecated key 1`] = ` | |||
<div | |||
className="web-api-params" | |||
> | |||
<table> | |||
<tbody> | |||
<tr | |||
key="foo" | |||
> | |||
<td | |||
className="markdown" | |||
style={ | |||
{ | |||
"width": 180, | |||
} | |||
} | |||
> | |||
<code> | |||
foo | |||
</code> | |||
<div | |||
className="note little-spacer-top" | |||
> | |||
optional | |||
</div> | |||
<div | |||
className="big-spacer-top spacer-left" | |||
> | |||
<div | |||
className="note little-spacer-bottom" | |||
> | |||
replaces | |||
: | |||
</div> | |||
<code> | |||
foo-deprecated | |||
</code> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<DeprecatedBadge | |||
since="5.0" | |||
/> | |||
</div> | |||
</div> | |||
</td> | |||
<td> | |||
<div | |||
className="markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "Foo desc", | |||
} | |||
} | |||
/> | |||
</td> | |||
<td | |||
style={ | |||
{ | |||
"width": 250, | |||
} | |||
} | |||
/> | |||
</tr> | |||
</tbody> | |||
</table> | |||
</div> | |||
`; | |||
exports[`should render different value constraints 1`] = ` | |||
<div | |||
className="web-api-params" | |||
> | |||
<table> | |||
<tbody> | |||
<tr | |||
key="foo" | |||
> | |||
<td | |||
className="markdown" | |||
style={ | |||
{ | |||
"width": 180, | |||
} | |||
} | |||
> | |||
<code> | |||
foo | |||
</code> | |||
<div | |||
className="note little-spacer-top" | |||
> | |||
optional | |||
</div> | |||
</td> | |||
<td> | |||
<div | |||
className="markdown" | |||
dangerouslySetInnerHTML={ | |||
{ | |||
"__html": "Foo desc", | |||
} | |||
} | |||
/> | |||
</td> | |||
<td | |||
style={ | |||
{ | |||
"width": 250, | |||
} | |||
} | |||
> | |||
<div> | |||
<h4> | |||
api_documentation.possible_values | |||
</h4> | |||
<ul | |||
className="list-styled" | |||
> | |||
<li | |||
className="little-spacer-top" | |||
key="foo" | |||
> | |||
<code> | |||
foo | |||
</code> | |||
</li> | |||
<li | |||
className="little-spacer-top" | |||
key="bar" | |||
> | |||
<code> | |||
bar | |||
</code> | |||
</li> | |||
</ul> | |||
</div> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<h4> | |||
api_documentation.default_values | |||
</h4> | |||
<code> | |||
def | |||
</code> | |||
</div> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<h4> | |||
api_documentation.example_values | |||
</h4> | |||
<code> | |||
foo | |||
</code> | |||
</div> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<h4> | |||
api_documentation.max_values | |||
</h4> | |||
<code> | |||
1000 | |||
</code> | |||
</div> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<h4> | |||
api_documentation.min_value | |||
</h4> | |||
<code> | |||
1 | |||
</code> | |||
</div> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<h4> | |||
api_documentation.max_value | |||
</h4> | |||
<code> | |||
500 | |||
</code> | |||
</div> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<h4> | |||
api_documentation.min_length | |||
</h4> | |||
<code> | |||
2 | |||
</code> | |||
</div> | |||
<div | |||
className="little-spacer-top" | |||
> | |||
<h4> | |||
api_documentation.max_length | |||
</h4> | |||
<code> | |||
200 | |||
</code> | |||
</div> | |||
</td> | |||
</tr> | |||
</tbody> | |||
</table> | |||
</div> | |||
`; |
@@ -1,23 +0,0 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
exports[`should render correctly after fetching an example 1`] = ` | |||
<div | |||
className="web-api-response" | |||
/> | |||
`; | |||
exports[`should render correctly after fetching an example 2`] = ` | |||
<div | |||
className="web-api-response" | |||
> | |||
<pre | |||
style={ | |||
{ | |||
"whiteSpace": "pre-wrap", | |||
} | |||
} | |||
> | |||
my example | |||
</pre> | |||
</div> | |||
`; |
@@ -1,55 +0,0 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
exports[`should render correctly 1`] = ` | |||
<div | |||
className="web-api-search" | |||
> | |||
<div> | |||
<SearchBox | |||
onChange={[Function]} | |||
placeholder="api_documentation.search" | |||
value="" | |||
/> | |||
</div> | |||
<div | |||
className="big-spacer-top" | |||
> | |||
<Checkbox | |||
checked={false} | |||
className="text-middle" | |||
onCheck={[Function]} | |||
thirdState={false} | |||
> | |||
<span | |||
className="little-spacer-left" | |||
> | |||
api_documentation.show_internal | |||
</span> | |||
</Checkbox> | |||
<HelpTooltip | |||
className="spacer-left" | |||
overlay="api_documentation.internal_tooltip" | |||
/> | |||
</div> | |||
<div | |||
className="spacer-top" | |||
> | |||
<Checkbox | |||
checked={false} | |||
className="text-middle" | |||
onCheck={[Function]} | |||
thirdState={false} | |||
> | |||
<span | |||
className="little-spacer-left" | |||
> | |||
api_documentation.show_deprecated | |||
</span> | |||
</Checkbox> | |||
<HelpTooltip | |||
className="spacer-left" | |||
overlay="api_documentation.deprecation_tooltip" | |||
/> | |||
</div> | |||
</div> | |||
`; |
@@ -1,118 +0,0 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
exports[`should render correctly 1`] = ` | |||
<div | |||
className="layout-page" | |||
> | |||
<Suggestions | |||
suggestions="api_documentation" | |||
/> | |||
<Helmet | |||
defer={false} | |||
encodeSpecialCharacters={true} | |||
prioritizeSeoTags={false} | |||
title="api_documentation.page" | |||
/> | |||
<ScreenPositionHelper | |||
className="layout-page-side-outer" | |||
> | |||
<Component /> | |||
</ScreenPositionHelper> | |||
<div | |||
className="layout-page-main" | |||
> | |||
<div | |||
className="layout-page-main-inner" | |||
> | |||
<Domain | |||
domain={ | |||
{ | |||
"actions": [], | |||
"deprecatedSince": undefined, | |||
"description": "foo", | |||
"internal": true, | |||
"path": "foo/bar", | |||
"since": "1.0", | |||
} | |||
} | |||
key="foo/bar" | |||
query={ | |||
{ | |||
"deprecated": false, | |||
"internal": false, | |||
"search": "", | |||
} | |||
} | |||
/> | |||
</div> | |||
</div> | |||
</div> | |||
`; | |||
exports[`should render correctly 2`] = ` | |||
<div | |||
className="layout-page-side" | |||
style={ | |||
{ | |||
"top": 0, | |||
} | |||
} | |||
> | |||
<div | |||
className="layout-page-side-inner" | |||
> | |||
<div | |||
className="layout-page-filters" | |||
> | |||
<A11ySkipTarget | |||
anchor="webapi_main" | |||
/> | |||
<div | |||
className="web-api-page-header" | |||
> | |||
<ForwardRef(Link) | |||
to="/web_api/" | |||
> | |||
<h1> | |||
api_documentation.page | |||
</h1> | |||
</ForwardRef(Link)> | |||
</div> | |||
<Search | |||
onSearch={[Function]} | |||
onToggleDeprecated={[Function]} | |||
onToggleInternal={[Function]} | |||
query={ | |||
{ | |||
"deprecated": false, | |||
"internal": false, | |||
"search": "", | |||
} | |||
} | |||
/> | |||
<Menu | |||
domains={ | |||
[ | |||
{ | |||
"actions": [], | |||
"deprecatedSince": undefined, | |||
"description": "foo", | |||
"internal": true, | |||
"path": "foo/bar", | |||
"since": "1.0", | |||
}, | |||
] | |||
} | |||
query={ | |||
{ | |||
"deprecated": false, | |||
"internal": false, | |||
"search": "", | |||
} | |||
} | |||
splat="foo/bar" | |||
/> | |||
</div> | |||
</div> | |||
</div> | |||
`; |
@@ -17,18 +17,36 @@ | |||
* 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 DeprecatedBadge from '../DeprecatedBadge'; | |||
import { WebApi } from '../../types/types'; | |||
it('should render with version', () => { | |||
expect(shallow(<DeprecatedBadge since="5.6" />)).toMatchSnapshot(); | |||
}); | |||
export function mockAction(overrides: Partial<WebApi.Action> = {}): WebApi.Action { | |||
return { | |||
key: 'action1', | |||
internal: false, | |||
changelog: [], | |||
description: 'Action 1', | |||
hasResponseExample: false, | |||
post: false, | |||
...overrides, | |||
}; | |||
} | |||
it('should render without version', () => { | |||
expect(shallow(<DeprecatedBadge />)).toMatchSnapshot(); | |||
}); | |||
export function mockDomain(overrides: Partial<WebApi.Domain> = {}): WebApi.Domain { | |||
return { | |||
actions: [mockAction()], | |||
description: 'foo', | |||
path: 'foo/bar', | |||
since: '1.0', | |||
...overrides, | |||
}; | |||
} | |||
it('should render with malformed version', () => { | |||
expect(shallow(<DeprecatedBadge since="foo" />)).toMatchSnapshot(); | |||
}); | |||
export function mockParam(overrides: Partial<WebApi.Param> = {}): WebApi.Param { | |||
return { | |||
key: 'p1', | |||
description: 'parameter 1', | |||
internal: false, | |||
required: false, | |||
...overrides, | |||
}; | |||
} |