Skip to content

Commit

Permalink
Remove recently accessed and custom nav props in test
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <[email protected]>
  • Loading branch information
yuye-aws committed Jul 6, 2023
1 parent 13d4ba3 commit 7895e5c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 83 deletions.
2 changes: 0 additions & 2 deletions src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ export class ChromeService {
isVisible$={this.isVisible$}
opensearchDashboardsVersion={injectedMetadata.getOpenSearchDashboardsVersion()}
navLinks$={navLinks.getNavLinks$()}
customNavLink$={customNavLink$.pipe(takeUntil(this.stop$))}
recentlyAccessed$={recentlyAccessed.get$()}
navControlsLeft$={navControls.getLeft$()}
navControlsCenter$={navControls.getCenter$()}
navControlsRight$={navControls.getRight$()}
Expand Down
57 changes: 5 additions & 52 deletions src/core/public/chrome/ui/header/collapsible_nav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import sinon from 'sinon';
import { StubBrowserStorage } from 'test_utils/stub_browser_storage';
import { ChromeNavLink, DEFAULT_APP_CATEGORIES } from '../../..';
import { httpServiceMock } from '../../../http/http_service.mock';
import { ChromeRecentlyAccessedHistoryItem } from '../../recently_accessed';
import { CollapsibleNav } from './collapsible_nav';
import { workspacesServiceMock } from '../../../fatal_errors/fatal_errors_service.mock';

Expand All @@ -56,15 +55,6 @@ function mockLink({ title = 'discover', category }: Partial<ChromeNavLink>) {
'data-test-subj': title,
};
}

function mockRecentNavLink({ label = 'recent' }: Partial<ChromeRecentlyAccessedHistoryItem>) {
return {
label,
link: label,
id: label,
};
}

function mockProps() {
return {
appId$: new BehaviorSubject('test'),
Expand All @@ -74,15 +64,13 @@ function mockProps() {
isNavOpen: false,
homeHref: '/',
navLinks$: new BehaviorSubject([]),
recentlyAccessed$: new BehaviorSubject([]),
storage: new StubBrowserStorage(),
onIsLockedUpdate: () => {},
closeNav: () => {},
navigateToApp: () => Promise.resolve(),
navigateToUrl: () => Promise.resolve(),
exitWorkspace: () => {},
getWorkspaceUrl: (id: string) => '',
customNavLink$: new BehaviorSubject(undefined),
currentWorkspace$: workspacesServiceMock.createStartContract().client.currentWorkspace$,
workspaceList$: workspacesServiceMock.createStartContract().client.workspaceList$,
branding: {
Expand Down Expand Up @@ -139,19 +127,8 @@ describe('CollapsibleNav', () => {
mockLink({ title: 'canvas' }), // links should be able to be rendered top level as well
mockLink({ title: 'logs', category: observability }),
];
const recentNavLinks = [
mockRecentNavLink({ label: 'recent 1' }),
mockRecentNavLink({ label: 'recent 2' }),
];
const customNavLink = mockLink({ title: 'Custom link' });
const component = mount(
<CollapsibleNav
{...mockProps()}
isNavOpen={true}
navLinks$={new BehaviorSubject(navLinks)}
recentlyAccessed$={new BehaviorSubject(recentNavLinks)}
customNavLink$={new BehaviorSubject(customNavLink)}
/>
<CollapsibleNav {...mockProps()} isNavOpen={true} navLinks$={new BehaviorSubject(navLinks)} />
);
expect(component).toMatchSnapshot();
});
Expand All @@ -161,14 +138,8 @@ describe('CollapsibleNav', () => {
mockLink({ category: opensearchDashboards }),
mockLink({ category: observability }),
];
const recentNavLinks = [mockRecentNavLink({})];
const component = mount(
<CollapsibleNav
{...mockProps()}
isNavOpen={true}
navLinks$={new BehaviorSubject(navLinks)}
recentlyAccessed$={new BehaviorSubject(recentNavLinks)}
/>
<CollapsibleNav {...mockProps()} isNavOpen={true} navLinks$={new BehaviorSubject(navLinks)} />
);
expectShownNavLinksCount(component, 3);
clickGroup(component, 'opensearchDashboards');
Expand All @@ -186,14 +157,8 @@ describe('CollapsibleNav', () => {
mockLink({ category: opensearchDashboards }),
mockLink({ title: 'categoryless' }),
];
const recentNavLinks = [mockRecentNavLink({})];
const component = mount(
<CollapsibleNav
{...mockProps()}
isNavOpen={true}
navLinks$={new BehaviorSubject(navLinks)}
recentlyAccessed$={new BehaviorSubject(recentNavLinks)}
/>
<CollapsibleNav {...mockProps()} isNavOpen={true} navLinks$={new BehaviorSubject(navLinks)} />
);
component.setProps({
closeNav: () => {
Expand Down Expand Up @@ -222,14 +187,8 @@ describe('CollapsibleNav', () => {
mockLink({ category: opensearchDashboards }),
mockLink({ category: observability }),
];
const recentNavLinks = [mockRecentNavLink({})];
const component = mount(
<CollapsibleNav
{...mockProps()}
isNavOpen={true}
navLinks$={new BehaviorSubject(navLinks)}
recentlyAccessed$={new BehaviorSubject(recentNavLinks)}
/>
<CollapsibleNav {...mockProps()} isNavOpen={true} navLinks$={new BehaviorSubject(navLinks)} />
);
// check if nav bar renders default mode custom logo
expect(component).toMatchSnapshot();
Expand All @@ -249,14 +208,8 @@ describe('CollapsibleNav', () => {
mockLink({ category: opensearchDashboards }),
mockLink({ category: observability }),
];
const recentNavLinks = [mockRecentNavLink({})];
const component = mount(
<CollapsibleNav
{...mockProps()}
isNavOpen={true}
navLinks$={new BehaviorSubject(navLinks)}
recentlyAccessed$={new BehaviorSubject(recentNavLinks)}
/>
<CollapsibleNav {...mockProps()} isNavOpen={true} navLinks$={new BehaviorSubject(navLinks)} />
);
// check if nav bar renders dark mode custom logo
component.setProps({
Expand Down
5 changes: 1 addition & 4 deletions src/core/public/chrome/ui/header/collapsible_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { groupBy, sortBy } from 'lodash';
import React, { useRef } from 'react';
import useObservable from 'react-use/lib/useObservable';
import * as Rx from 'rxjs';
import { ChromeNavLink, ChromeRecentlyAccessedHistoryItem } from '../..';
import { ChromeNavLink } from '../..';
import { AppCategory } from '../../../../types';
import { InternalApplicationStart } from '../../../application';
import { HttpStart } from '../../../http';
Expand Down Expand Up @@ -94,13 +94,11 @@ interface Props {
isNavOpen: boolean;
homeHref: string;
navLinks$: Rx.Observable<ChromeNavLink[]>;
recentlyAccessed$: Rx.Observable<ChromeRecentlyAccessedHistoryItem[]>;
storage?: Storage;
onIsLockedUpdate: OnIsLockedUpdate;
closeNav: () => void;
navigateToApp: InternalApplicationStart['navigateToApp'];
navigateToUrl: InternalApplicationStart['navigateToUrl'];
customNavLink$: Rx.Observable<ChromeNavLink | undefined>;
branding: ChromeBranding;
exitWorkspace: () => void;
getWorkspaceUrl: (id: string) => string;
Expand All @@ -125,7 +123,6 @@ export function CollapsibleNav({
...observables
}: Props) {
const navLinks = useObservable(observables.navLinks$, []).filter((link) => !link.hidden);

const appId = useObservable(observables.appId$, '');
const currentWorkspace = useObservable(observables.currentWorkspace$);
const workspaceList = useObservable(observables.workspaceList$, []).slice(0, 5);
Expand Down
13 changes: 0 additions & 13 deletions src/core/public/chrome/ui/header/header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ function mockProps() {
isVisible$: new BehaviorSubject(true),
opensearchDashboardsDocLink: '/docs',
navLinks$: new BehaviorSubject([]),
customNavLink$: new BehaviorSubject(undefined),
recentlyAccessed$: new BehaviorSubject([]),
forceAppSwitcherNavigation$: new BehaviorSubject(false),
helpExtension$: new BehaviorSubject(undefined),
helpSupportUrl$: new BehaviorSubject(''),
Expand Down Expand Up @@ -98,24 +96,13 @@ describe('Header', () => {
const navLinks$ = new BehaviorSubject([
{ id: 'opensearchDashboards', title: 'opensearchDashboards', baseUrl: '', href: '' },
]);
const customNavLink$ = new BehaviorSubject({
id: 'cloud-deployment-link',
title: 'Manage cloud deployment',
baseUrl: '',
href: '',
});
const recentlyAccessed$ = new BehaviorSubject([
{ link: '', label: 'dashboard', id: 'dashboard' },
]);
const component = mountWithIntl(
<Header
{...mockProps()}
isVisible$={isVisible$}
breadcrumbs$={breadcrumbs$}
navLinks$={navLinks$}
recentlyAccessed$={recentlyAccessed$}
isLocked$={isLocked$}
customNavLink$={customNavLink$}
/>
);
expect(component.find('EuiHeader').exists()).toBeFalsy();
Expand Down
14 changes: 2 additions & 12 deletions src/core/public/chrome/ui/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,8 @@ import React, { createRef, useState } from 'react';
import useObservable from 'react-use/lib/useObservable';
import { Observable, BehaviorSubject } from 'rxjs';
import { LoadingIndicator } from '../';
import {
ChromeBadge,
ChromeBreadcrumb,
ChromeNavControl,
ChromeNavLink,
ChromeRecentlyAccessedHistoryItem,
} from '../..';
import { InternalApplicationStart } from '../../../application/types';
import { ChromeBadge, ChromeBreadcrumb, ChromeNavControl, ChromeNavLink } from '../..';
import { InternalApplicationStart } from '../../../application';
import { HttpStart } from '../../../http';
import { ChromeHelpExtension, ChromeBranding } from '../../chrome_service';
import { OnIsLockedUpdate } from './';
Expand All @@ -71,12 +65,10 @@ export interface HeaderProps {
appTitle$: Observable<string>;
badge$: Observable<ChromeBadge | undefined>;
breadcrumbs$: Observable<ChromeBreadcrumb[]>;
customNavLink$: Observable<ChromeNavLink | undefined>;
homeHref: string;
isVisible$: Observable<boolean>;
opensearchDashboardsDocLink: string;
navLinks$: Observable<ChromeNavLink[]>;
recentlyAccessed$: Observable<ChromeRecentlyAccessedHistoryItem[]>;
forceAppSwitcherNavigation$: Observable<boolean>;
helpExtension$: Observable<ChromeHelpExtension | undefined>;
helpSupportUrl$: Observable<string>;
Expand Down Expand Up @@ -247,7 +239,6 @@ export function Header({
id={navId}
isLocked={isLocked}
navLinks$={observables.navLinks$}
recentlyAccessed$={observables.recentlyAccessed$}
isNavOpen={isNavOpen}
homeHref={homeHref}
basePath={basePath}
Expand All @@ -262,7 +253,6 @@ export function Header({
toggleCollapsibleNavRef.current.focus();
}
}}
customNavLink$={observables.customNavLink$}
branding={branding}
currentWorkspace$={observables.currentWorkspace$}
workspaceList$={observables.workspaceList$}
Expand Down

0 comments on commit 7895e5c

Please sign in to comment.