Fix test cases.

Signed-off-by: Aramis Sennyey <sennyeya@amazon.com>
This commit is contained in:
Aramis Sennyey
2022-11-29 12:53:18 -05:00
parent 62ad114c9e
commit c7ae6565a8
3 changed files with 4 additions and 47 deletions
@@ -21,11 +21,9 @@ import {
TestApiProvider,
wrapInTestApp,
} from '@backstage/test-utils';
import { analyticsApiRef, configApiRef } from '@backstage/core-plugin-api';
import { isExternalUri, Link, useResolvedPath } from './Link';
import { analyticsApiRef } from '@backstage/core-plugin-api';
import { isExternalUri, Link } from './Link';
import { Route, Routes } from 'react-router';
import { renderHook, WrapperComponent } from '@testing-library/react-hooks';
import { ConfigReader } from '@backstage/config';
describe('<Link />', () => {
it('navigates using react-router', async () => {
@@ -132,45 +130,4 @@ describe('<Link />', () => {
expect(isExternalUri(uri)).toBe(expected);
});
});
describe('useResolvedPath', () => {
const wrapper: WrapperComponent<{}> = ({ children }) => {
const configApi = new ConfigReader({
app: { baseUrl: 'http://localhost:3000/example' },
});
return (
<TestApiProvider apis={[[configApiRef, configApi]]}>
{children}
</TestApiProvider>
);
};
describe('concatenate base path', () => {
it('when uri is internal and does not start with base path', () => {
const path = '/catalog/default/component/artist-lookup';
const { result } = renderHook(() => useResolvedPath(path), {
wrapper,
});
expect(result.current).toBe('/example'.concat(path));
});
});
describe('does not concatenate base path', () => {
it('when uri is external', () => {
const path = 'https://stackoverflow.com/questions/1/example';
const { result } = renderHook(() => useResolvedPath(path), {
wrapper,
});
expect(result.current).toBe(path);
});
it('when uri already starts with base path', () => {
const path = '/example/catalog/default/component/artist-lookup';
const { result } = renderHook(() => useResolvedPath(path), {
wrapper,
});
expect(result.current).toBe(path);
});
});
});
});
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { configApiRef, useAnalytics, useApi } from '@backstage/core-plugin-api';
import { useAnalytics } from '@backstage/core-plugin-api';
import classnames from 'classnames';
// eslint-disable-next-line no-restricted-imports
import MaterialLink, {
@@ -373,7 +373,7 @@ export function Table<T extends object = {}>(props: TableProps<T>) {
const newData = (data as any[]).filter(
el =>
!!Object.entries(selectedFilters)
.filter(([, value]) => !!value.length)
.filter(([, value]: [any, any]) => !!value.length)
.every(([key, filterValue]) => {
const fieldValue = extractValueByField(
el,