@@ -1552,9 +1552,10 @@ describe('App', () => {
15521552 } )
15531553 const ribbon = screen . getByTestId ( 'ribbon' )
15541554
1555- const revisions = within ( ribbon )
1556- . getAllByRole ( 'listitem' )
1557- . map ( item => item . textContent )
1555+ const revisionBlocks = within ( ribbon ) . getAllByRole ( 'listitem' )
1556+ revisionBlocks . shift ( ) // Remove filter button
1557+ revisionBlocks . shift ( ) // Remove refresh all
1558+ const revisions = revisionBlocks . map ( item => item . textContent )
15581559 expect ( revisions ) . toStrictEqual (
15591560 comparisonTableFixture . revisions . map ( rev =>
15601561 rev . group ? rev . group . slice ( 1 , - 1 ) + rev . revision : rev . revision
@@ -1580,6 +1581,54 @@ describe('App', () => {
15801581 } )
15811582 } )
15821583
1584+ it ( 'should display the number of experiments selected' , ( ) => {
1585+ renderAppWithData ( {
1586+ comparison : comparisonTableFixture ,
1587+ sectionCollapsed : DEFAULT_SECTION_COLLAPSED
1588+ } )
1589+
1590+ expect (
1591+ screen . getByText ( `${ comparisonTableFixture . revisions . length } of 7` )
1592+ ) . toBeInTheDocument ( )
1593+ } )
1594+
1595+ it ( 'should send a message to select the revisions when clicking the filter button' , ( ) => {
1596+ renderAppWithData ( {
1597+ comparison : comparisonTableFixture ,
1598+ sectionCollapsed : DEFAULT_SECTION_COLLAPSED
1599+ } )
1600+
1601+ const filterButton = within ( screen . getByTestId ( 'ribbon' ) ) . getAllByRole (
1602+ 'button'
1603+ ) [ 0 ]
1604+
1605+ fireEvent . click ( filterButton )
1606+
1607+ expect ( mockPostMessage ) . toBeCalledWith ( {
1608+ type : MessageFromWebviewType . SELECT_EXPERIMENTS
1609+ } )
1610+ } )
1611+
1612+ it ( 'should send a message to refresh each revision when clicking the refresh all button' , ( ) => {
1613+ renderAppWithData ( {
1614+ comparison : comparisonTableFixture ,
1615+ sectionCollapsed : DEFAULT_SECTION_COLLAPSED
1616+ } )
1617+
1618+ const refreshAllButton = within (
1619+ screen . getByTestId ( 'ribbon' )
1620+ ) . getAllByRole ( 'button' ) [ 1 ]
1621+
1622+ mockPostMessage . mockReset ( )
1623+ fireEvent . click ( refreshAllButton )
1624+
1625+ expect ( mockPostMessage ) . toHaveBeenCalledTimes ( 1 )
1626+ expect ( mockPostMessage ) . toBeCalledWith ( {
1627+ payload : [ 'workspace' , 'main' , '4fb124a' , '42b8736' , '1ba7bcd' ] ,
1628+ type : MessageFromWebviewType . REFRESH_REVISIONS
1629+ } )
1630+ } )
1631+
15831632 describe ( 'Copy button' , ( ) => {
15841633 const mockWriteText = jest . fn ( )
15851634 Object . assign ( navigator , {
@@ -1588,7 +1637,17 @@ describe('App', () => {
15881637 }
15891638 } )
15901639
1591- it ( 'should copy the experiment name when clicking the text' , ( ) => {
1640+ beforeAll ( ( ) => {
1641+ jest . useFakeTimers ( )
1642+ } )
1643+
1644+ afterAll ( ( ) => {
1645+ jest . useRealTimers ( )
1646+ } )
1647+
1648+ it ( 'should copy the experiment name when clicking the text' , async ( ) => {
1649+ mockWriteText . mockResolvedValueOnce ( 'success' )
1650+
15921651 renderAppWithData ( {
15931652 comparison : comparisonTableFixture ,
15941653 sectionCollapsed : DEFAULT_SECTION_COLLAPSED
@@ -1598,14 +1657,14 @@ describe('App', () => {
15981657 screen . getByTestId ( 'ribbon-main' )
15991658 ) . getAllByRole ( 'button' ) [ 0 ]
16001659
1660+ fireEvent . mouseEnter ( mainNameButton , { bubbles : true } )
16011661 fireEvent . click ( mainNameButton )
16021662
16031663 expect ( mockWriteText ) . toBeCalledWith ( 'main' )
1664+ await screen . findByText ( CopyTooltip . COPIED )
16041665 } )
16051666
16061667 it ( 'should display that the experiment was copied when clicking the text' , async ( ) => {
1607- jest . useFakeTimers ( )
1608-
16091668 mockWriteText . mockResolvedValueOnce ( 'success' )
16101669
16111670 renderAppWithData ( {
@@ -1621,11 +1680,10 @@ describe('App', () => {
16211680 fireEvent . click ( mainNameButton )
16221681
16231682 expect ( await screen . findByText ( CopyTooltip . COPIED ) ) . toBeInTheDocument ( )
1624- jest . useRealTimers ( )
16251683 } )
16261684
1627- it ( 'should display copy again when hovering the text 2s after clicking the text' , ( ) => {
1628- jest . useFakeTimers ( )
1685+ it ( 'should display copy again when hovering the text 2s after clicking the text' , async ( ) => {
1686+ mockWriteText . mockResolvedValueOnce ( 'success' )
16291687
16301688 renderAppWithData ( {
16311689 comparison : comparisonTableFixture ,
@@ -1636,13 +1694,12 @@ describe('App', () => {
16361694 screen . getByTestId ( 'ribbon-main' )
16371695 ) . getAllByRole ( 'button' ) [ 0 ]
16381696
1639- fireEvent . click ( mainNameButton )
16401697 fireEvent . mouseEnter ( mainNameButton , { bubbles : true } )
1698+ fireEvent . click ( mainNameButton )
16411699
16421700 jest . advanceTimersByTime ( 2001 )
16431701
1644- expect ( screen . getByText ( CopyTooltip . NORMAL ) ) . toBeInTheDocument ( )
1645- jest . useRealTimers ( )
1702+ expect ( await screen . findByText ( CopyTooltip . NORMAL ) ) . toBeInTheDocument ( )
16461703 } )
16471704 } )
16481705 } )
0 commit comments