Add tests for isLocationMatch function
Signed-off-by: hiba-aldalaty <hibaaldalaty@gmail.com>
This commit is contained in:
@@ -43,6 +43,8 @@ import {
|
||||
SidebarDivider,
|
||||
SidebarSpace,
|
||||
SidebarScrollWrapper,
|
||||
SidebarSubmenu,
|
||||
SidebarSubmenuItem,
|
||||
} from '@backstage/core-components';
|
||||
import { AzurePullRequestsIcon } from '@backstage/plugin-azure-devops';
|
||||
|
||||
@@ -81,13 +83,27 @@ const SidebarLogo = () => {
|
||||
|
||||
export const Root = ({ children }: PropsWithChildren<{}>) => (
|
||||
<SidebarPage>
|
||||
<Sidebar>
|
||||
<Sidebar disableExpandOnHover>
|
||||
<SidebarLogo />
|
||||
<SearchContextProvider>
|
||||
<SidebarSearchModal />
|
||||
</SearchContextProvider>
|
||||
<SidebarDivider />
|
||||
{/* Global nav, not org-specific */}
|
||||
<SidebarItem icon={HomeIcon} text="Catalog">
|
||||
<SidebarSubmenu title="Catalog">
|
||||
<SidebarSubmenuItem
|
||||
title="Services"
|
||||
to="catalog?x=foo&y=bar"
|
||||
icon={HomeIcon}
|
||||
/>
|
||||
<SidebarSubmenuItem
|
||||
title="Libraries"
|
||||
to="catalog?x=foo"
|
||||
icon={HomeIcon}
|
||||
/>
|
||||
</SidebarSubmenu>
|
||||
</SidebarItem>
|
||||
<SidebarItem icon={HomeIcon} to="catalog" text="Home" />
|
||||
<SidebarItem icon={ExtensionIcon} to="api-docs" text="APIs" />
|
||||
<SidebarItem icon={LibraryBooks} to="docs" text="Docs" />
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Location, Path } from 'history';
|
||||
import { isLocationMatch } from './utils';
|
||||
|
||||
describe('isLocationMatching', () => {
|
||||
let currentLocation: Location;
|
||||
let toLocation: Path;
|
||||
|
||||
it('return false when pathname in target and current location differ', async () => {
|
||||
currentLocation = {
|
||||
pathname: '/catalog',
|
||||
search: '?kind=component',
|
||||
state: null,
|
||||
hash: '',
|
||||
key: '',
|
||||
};
|
||||
toLocation = {
|
||||
pathname: '/catalog-a',
|
||||
search: '?kind=component',
|
||||
hash: '',
|
||||
};
|
||||
expect(isLocationMatch(currentLocation, toLocation)).toBe(false);
|
||||
});
|
||||
|
||||
it('return true when exact match between current and target location parameters', async () => {
|
||||
currentLocation = {
|
||||
pathname: '/catalog',
|
||||
search: '?kind=component',
|
||||
state: null,
|
||||
hash: '',
|
||||
key: '',
|
||||
};
|
||||
toLocation = { pathname: '/catalog', search: '?kind=component', hash: '' };
|
||||
expect(isLocationMatch(currentLocation, toLocation)).toBe(true);
|
||||
});
|
||||
|
||||
it('return true when target query parameters are subset of current location query parameters', async () => {
|
||||
currentLocation = {
|
||||
pathname: '/catalog',
|
||||
search: '?x=foo&y=bar',
|
||||
state: null,
|
||||
hash: '',
|
||||
key: '',
|
||||
};
|
||||
toLocation = { pathname: '/catalog', search: '?x=foo', hash: '' };
|
||||
expect(isLocationMatch(currentLocation, toLocation)).toBe(true);
|
||||
});
|
||||
|
||||
it('return false when no matching query parameters between target and current location', async () => {
|
||||
currentLocation = {
|
||||
pathname: '/catalog',
|
||||
search: '?y=bar',
|
||||
state: null,
|
||||
hash: '',
|
||||
key: '',
|
||||
};
|
||||
toLocation = { pathname: '/catalog', search: '?x=foo', hash: '' };
|
||||
expect(isLocationMatch(currentLocation, toLocation)).toBe(false);
|
||||
});
|
||||
|
||||
it('return true when query parameters match in different order', async () => {
|
||||
currentLocation = {
|
||||
pathname: '/catalog',
|
||||
search: '?y=bar&x=foo',
|
||||
state: null,
|
||||
hash: '',
|
||||
key: '',
|
||||
};
|
||||
toLocation = { pathname: '/catalog', search: '?x=foo&y=bar', hash: '' };
|
||||
expect(isLocationMatch(currentLocation, toLocation)).toBe(true);
|
||||
});
|
||||
|
||||
it('return true when there is a matching query parameter alongside extra parameters', async () => {
|
||||
currentLocation = {
|
||||
pathname: '/catalog',
|
||||
search: '?y=bar&x=foo',
|
||||
state: null,
|
||||
hash: '',
|
||||
key: '',
|
||||
};
|
||||
toLocation = { pathname: '/catalog', search: '', hash: '' };
|
||||
expect(isLocationMatch(currentLocation, toLocation)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user