@@ -36,6 +36,7 @@ import { act } from 'react-dom/test-utils'
3636import { App } from './App'
3737import { Plots } from './Plots'
3838import { NewSectionBlock } from './templatePlots/TemplatePlots'
39+ import { CopyTooltip } from './ribbon/RibbonBlock'
3940import { vsCodeApi } from '../../shared/api'
4041import { createBubbledEvent , dragAndDrop , dragEnter } from '../../test/dragDrop'
4142import { DragEnterDirection } from '../../shared/components/dragDrop/util'
@@ -353,7 +354,9 @@ describe('App', () => {
353354 cancelable : true
354355 } )
355356
356- const workspaceHeader = screen . queryByText ( 'workspace' )
357+ const comparisonTable = screen . getByRole ( 'table' )
358+
359+ const workspaceHeader = within ( comparisonTable ) . queryByText ( 'workspace' )
357360 expect ( workspaceHeader ) . toBeInTheDocument ( )
358361
359362 const [ , pickerButton ] = screen . queryAllByTestId ( 'icon-menu-item' )
@@ -378,8 +381,7 @@ describe('App', () => {
378381 cancelable : true
379382 } )
380383
381- const table = screen . getByRole ( 'table' )
382- expect ( within ( table ) . getByText ( 'workspace' ) ) . toBeInTheDocument ( )
384+ expect ( within ( comparisonTable ) . getByText ( 'workspace' ) ) . toBeInTheDocument ( )
383385 } )
384386
385387 it ( 'should show the newest revision in the comparision table even if some revisions were filtered out' , async ( ) => {
@@ -432,7 +434,7 @@ describe('App', () => {
432434 )
433435
434436 const workspaceHeader = screen . queryAllByText ( newRevision )
435- expect ( workspaceHeader . length ) . toBe ( 2 ) // One in the table and one in the menu
437+ expect ( workspaceHeader . length ) . toBe ( 3 ) // One in the table, one in the menu, and one in the ribbon
436438 } )
437439
438440 it ( 'should send a message to the extension with the selected metrics when toggling the visibility of a plot' , async ( ) => {
@@ -1541,4 +1543,107 @@ describe('App', () => {
15411543 expect ( contextMenuEvent . defaultPrevented ) . toBe ( true )
15421544 } )
15431545 } )
1546+
1547+ describe ( 'Ribbon' , ( ) => {
1548+ it ( 'should show the revisions at the top' , ( ) => {
1549+ renderAppWithData ( {
1550+ comparison : comparisonTableFixture ,
1551+ sectionCollapsed : DEFAULT_SECTION_COLLAPSED
1552+ } )
1553+ const ribbon = screen . getByTestId ( 'ribbon' )
1554+
1555+ const revisions = within ( ribbon )
1556+ . getAllByRole ( 'listitem' )
1557+ . map ( item => item . textContent )
1558+ expect ( revisions ) . toStrictEqual (
1559+ comparisonTableFixture . revisions . map ( rev =>
1560+ rev . group ? rev . group . slice ( 1 , - 1 ) + rev . revision : rev . revision
1561+ )
1562+ )
1563+ } )
1564+
1565+ it ( 'should send a message with the revision to be removed when clicking the clear button' , ( ) => {
1566+ renderAppWithData ( {
1567+ comparison : comparisonTableFixture ,
1568+ sectionCollapsed : DEFAULT_SECTION_COLLAPSED
1569+ } )
1570+
1571+ const mainClearButton = within (
1572+ screen . getByTestId ( 'ribbon-main' )
1573+ ) . getAllByRole ( 'button' ) [ 1 ]
1574+
1575+ fireEvent . click ( mainClearButton )
1576+
1577+ expect ( mockPostMessage ) . toBeCalledWith ( {
1578+ payload : 'main' ,
1579+ type : MessageFromWebviewType . TOGGLE_EXPERIMENT
1580+ } )
1581+ } )
1582+
1583+ describe ( 'Copy button' , ( ) => {
1584+ const mockWriteText = jest . fn ( )
1585+ Object . assign ( navigator , {
1586+ clipboard : {
1587+ writeText : mockWriteText
1588+ }
1589+ } )
1590+
1591+ it ( 'should copy the experiment name when clicking the text' , ( ) => {
1592+ renderAppWithData ( {
1593+ comparison : comparisonTableFixture ,
1594+ sectionCollapsed : DEFAULT_SECTION_COLLAPSED
1595+ } )
1596+
1597+ const mainNameButton = within (
1598+ screen . getByTestId ( 'ribbon-main' )
1599+ ) . getAllByRole ( 'button' ) [ 0 ]
1600+
1601+ fireEvent . click ( mainNameButton )
1602+
1603+ expect ( mockWriteText ) . toBeCalledWith ( 'main' )
1604+ } )
1605+
1606+ it ( 'should display that the experiment was copied when clicking the text' , async ( ) => {
1607+ jest . useFakeTimers ( )
1608+
1609+ mockWriteText . mockResolvedValueOnce ( 'success' )
1610+
1611+ renderAppWithData ( {
1612+ comparison : comparisonTableFixture ,
1613+ sectionCollapsed : DEFAULT_SECTION_COLLAPSED
1614+ } )
1615+
1616+ const mainNameButton = within (
1617+ screen . getByTestId ( 'ribbon-main' )
1618+ ) . getAllByRole ( 'button' ) [ 0 ]
1619+
1620+ fireEvent . mouseEnter ( mainNameButton , { bubbles : true } )
1621+ fireEvent . click ( mainNameButton )
1622+
1623+ expect ( await screen . findByText ( CopyTooltip . COPIED ) ) . toBeInTheDocument ( )
1624+ jest . useRealTimers ( )
1625+ } )
1626+
1627+ it ( 'should display copy again when hovering the text 2s after clicking the text' , ( ) => {
1628+ jest . useFakeTimers ( )
1629+
1630+ renderAppWithData ( {
1631+ comparison : comparisonTableFixture ,
1632+ sectionCollapsed : DEFAULT_SECTION_COLLAPSED
1633+ } )
1634+
1635+ const mainNameButton = within (
1636+ screen . getByTestId ( 'ribbon-main' )
1637+ ) . getAllByRole ( 'button' ) [ 0 ]
1638+
1639+ fireEvent . click ( mainNameButton )
1640+ fireEvent . mouseEnter ( mainNameButton , { bubbles : true } )
1641+
1642+ jest . advanceTimersByTime ( 2001 )
1643+
1644+ expect ( screen . getByText ( CopyTooltip . NORMAL ) ) . toBeInTheDocument ( )
1645+ jest . useRealTimers ( )
1646+ } )
1647+ } )
1648+ } )
15441649} )
0 commit comments