@@ -69,6 +69,7 @@ import {MainViewComponent, SHARE_BUTTON_COMPONENT} from './main_view_component';
69
69
import { MainViewContainer } from './main_view_container' ;
70
70
import { PinnedViewComponent } from './pinned_view_component' ;
71
71
import { PinnedViewContainer } from './pinned_view_container' ;
72
+ import { buildMockState } from '../../../testing/utils' ;
72
73
73
74
@Component ( {
74
75
selector : 'card-view' ,
@@ -182,7 +183,11 @@ describe('metrics main view', () => {
182
183
] ,
183
184
providers : [
184
185
provideMockStore ( {
185
- initialState : appStateFromMetricsState ( buildMetricsState ( ) ) ,
186
+ initialState : {
187
+ ...buildMockState ( {
188
+ ...appStateFromMetricsState ( buildMetricsState ( ) ) ,
189
+ } ) ,
190
+ } ,
186
191
} ) ,
187
192
] ,
188
193
// Skip errors for card renderers, which are tested separately.
@@ -1606,6 +1611,67 @@ describe('metrics main view', () => {
1606
1611
expect ( indicator ) . toBeTruthy ( ) ;
1607
1612
} ) ;
1608
1613
} ) ;
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
+ } ) ;
1609
1675
} ) ;
1610
1676
1611
1677
describe ( 'slideout menu' , ( ) => {
0 commit comments