@@ -69,6 +69,7 @@ import {MainViewComponent, SHARE_BUTTON_COMPONENT} from './main_view_component';
6969import { MainViewContainer } from './main_view_container' ;
7070import { PinnedViewComponent } from './pinned_view_component' ;
7171import { PinnedViewContainer } from './pinned_view_container' ;
72+ import { buildMockState } from '../../../testing/utils' ;
7273
7374@Component ( {
7475 selector : 'card-view' ,
@@ -182,7 +183,11 @@ describe('metrics main view', () => {
182183 ] ,
183184 providers : [
184185 provideMockStore ( {
185- initialState : appStateFromMetricsState ( buildMetricsState ( ) ) ,
186+ initialState : {
187+ ...buildMockState ( {
188+ ...appStateFromMetricsState ( buildMetricsState ( ) ) ,
189+ } ) ,
190+ } ,
186191 } ) ,
187192 ] ,
188193 // Skip errors for card renderers, which are tested separately.
@@ -1606,6 +1611,67 @@ describe('metrics main view', () => {
16061611 expect ( indicator ) . toBeTruthy ( ) ;
16071612 } ) ;
16081613 } ) ;
1614+
1615+ describe ( 'clear all pins button' , ( ) => {
1616+ beforeEach ( ( ) => {
1617+ store . overrideSelector ( selectors . getEnableGlobalPins , true ) ;
1618+ } ) ;
1619+
1620+ it ( 'does not show the button if getEnableGlobalPins is false' , ( ) => {
1621+ store . overrideSelector ( selectors . getEnableGlobalPins , false ) ;
1622+ store . overrideSelector ( selectors . getPinnedCardsWithMetadata , [ ] ) ;
1623+ const fixture = TestBed . createComponent ( MainViewContainer ) ;
1624+ fixture . detectChanges ( ) ;
1625+
1626+ const clearAllButton = fixture . debugElement . query (
1627+ By . css ( '[aria-label="Clear all pinned cards"]' )
1628+ ) ;
1629+ expect ( clearAllButton ) . toBeNull ( ) ;
1630+ } ) ;
1631+
1632+ it ( 'does not show the button if there is no pinned card' , ( ) => {
1633+ store . overrideSelector ( selectors . getPinnedCardsWithMetadata , [ ] ) ;
1634+ const fixture = TestBed . createComponent ( MainViewContainer ) ;
1635+ fixture . detectChanges ( ) ;
1636+
1637+ const clearAllButton = fixture . debugElement . query (
1638+ By . css ( '[aria-label="Clear all pinned cards"]' )
1639+ ) ;
1640+ expect ( clearAllButton ) . toBeNull ( ) ;
1641+ } ) ;
1642+
1643+ it ( 'shows the button if there is a pinned card' , ( ) => {
1644+ store . overrideSelector ( selectors . getPinnedCardsWithMetadata , [
1645+ { cardId : 'card1' , ...createCardMetadata ( PluginType . SCALARS ) } ,
1646+ { cardId : 'card2' , ...createCardMetadata ( PluginType . IMAGES ) } ,
1647+ ] ) ;
1648+ const fixture = TestBed . createComponent ( MainViewContainer ) ;
1649+ fixture . detectChanges ( ) ;
1650+
1651+ const clearAllButton = fixture . debugElement . query (
1652+ By . css ( '[aria-label="Clear all pinned cards"]' )
1653+ ) ;
1654+ expect ( clearAllButton ) . toBeTruthy ( ) ;
1655+ } ) ;
1656+
1657+ it ( 'dispatch clear all action when the button is clicked' , ( ) => {
1658+ store . overrideSelector ( selectors . getPinnedCardsWithMetadata , [
1659+ { cardId : 'card1' , ...createCardMetadata ( PluginType . SCALARS ) } ,
1660+ { cardId : 'card2' , ...createCardMetadata ( PluginType . IMAGES ) } ,
1661+ ] ) ;
1662+ const fixture = TestBed . createComponent ( MainViewContainer ) ;
1663+ fixture . detectChanges ( ) ;
1664+
1665+ const clearAllButton = fixture . debugElement . query (
1666+ By . css ( '[aria-label="Clear all pinned cards"]' )
1667+ ) ;
1668+ clearAllButton . nativeElement . click ( ) ;
1669+
1670+ expect ( dispatchedActions ) . toEqual ( [
1671+ actions . metricsClearAllPinnedCards ( ) ,
1672+ ] ) ;
1673+ } ) ;
1674+ } ) ;
16091675 } ) ;
16101676
16111677 describe ( 'slideout menu' , ( ) => {
0 commit comments