@@ -24,7 +24,15 @@ define(function (require, exports, module) {
2424 const SpecRunnerUtils = require ( "spec/SpecRunnerUtils" ) ;
2525
2626 describe ( "integration:TabBar" , function ( ) {
27- let testWindow , PreferencesManager , $ , FileSystem , MainViewManager , CommandManager , Commands , DocumentManager , Strings ;
27+ let testWindow ,
28+ PreferencesManager ,
29+ $ ,
30+ FileSystem ,
31+ MainViewManager ,
32+ CommandManager ,
33+ Commands ,
34+ DocumentManager ,
35+ Strings ;
2836 let testFilePath , testFilePath2 , testFilePath3 , testDuplicateDir1 , testDuplicateDir2 , testDuplicateName ;
2937
3038 beforeAll ( async function ( ) {
@@ -1408,9 +1416,11 @@ define(function (require, exports, module) {
14081416 ) ;
14091417
14101418 // Find and click the "Close Tab" option
1411- const $closeTabOption = getContextMenu ( ) . find ( 'a.stylesheet-link' ) . filter ( function ( ) {
1412- return $ ( this ) . text ( ) . trim ( ) === Strings . CLOSE_TAB ;
1413- } ) ;
1419+ const $closeTabOption = getContextMenu ( )
1420+ . find ( "a.stylesheet-link" )
1421+ . filter ( function ( ) {
1422+ return $ ( this ) . text ( ) . trim ( ) === Strings . CLOSE_TAB ;
1423+ } ) ;
14141424 expect ( $closeTabOption . length ) . toBe ( 1 ) ;
14151425 $closeTabOption . click ( ) ;
14161426
@@ -1429,6 +1439,340 @@ define(function (require, exports, module) {
14291439 1000
14301440 ) ;
14311441 } ) ;
1442+
1443+ it ( "should close tabs to the right when selecting 'Close tabs to the right' from context menu" , async function ( ) {
1444+ // Open all three test files
1445+ await awaitsForDone (
1446+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath } ) ,
1447+ "Open first test file"
1448+ ) ;
1449+ await awaitsForDone (
1450+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath2 } ) ,
1451+ "Open second test file"
1452+ ) ;
1453+ await awaitsForDone (
1454+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath3 } ) ,
1455+ "Open third test file"
1456+ ) ;
1457+
1458+ // Wait for all tabs to appear
1459+ await awaitsFor (
1460+ function ( ) {
1461+ return tabExists ( testFilePath ) && tabExists ( testFilePath2 ) && tabExists ( testFilePath3 ) ;
1462+ } ,
1463+ "All tabs to appear" ,
1464+ 1000
1465+ ) ;
1466+
1467+ // Verify all three tabs exist
1468+ expect ( tabExists ( testFilePath ) ) . toBe ( true ) ;
1469+ expect ( tabExists ( testFilePath2 ) ) . toBe ( true ) ;
1470+ expect ( tabExists ( testFilePath3 ) ) . toBe ( true ) ;
1471+
1472+ // Get the first tab element
1473+ const $tab = getTab ( testFilePath ) ;
1474+
1475+ // Right-click on the first tab to open context menu
1476+ $tab . trigger ( "contextmenu" , {
1477+ pageX : 100 ,
1478+ pageY : 100
1479+ } ) ;
1480+
1481+ // Wait for context menu to appear
1482+ await awaitsFor (
1483+ function ( ) {
1484+ return getContextMenu ( ) . length > 0 ;
1485+ } ,
1486+ "Context menu to appear" ,
1487+ 1000
1488+ ) ;
1489+
1490+ // Find and click the "Close tabs to the right" option
1491+ const $closeTabsToRightOption = getContextMenu ( )
1492+ . find ( "a.stylesheet-link" )
1493+ . filter ( function ( ) {
1494+ return $ ( this ) . text ( ) . trim ( ) === Strings . CLOSE_TABS_TO_THE_RIGHT ;
1495+ } ) ;
1496+ expect ( $closeTabsToRightOption . length ) . toBe ( 1 ) ;
1497+ $closeTabsToRightOption . click ( ) ;
1498+
1499+ // Cancel any save dialogs that might appear
1500+ testWindow . brackets . test . Dialogs . cancelModalDialogIfOpen (
1501+ testWindow . brackets . test . DefaultDialogs . DIALOG_ID_SAVE_CLOSE ,
1502+ testWindow . brackets . test . DefaultDialogs . DIALOG_BTN_DONTSAVE
1503+ ) ;
1504+
1505+ // Verify tabs to the right are closed
1506+ await awaitsFor (
1507+ function ( ) {
1508+ return tabExists ( testFilePath ) && ! tabExists ( testFilePath2 ) && ! tabExists ( testFilePath3 ) ;
1509+ } ,
1510+ "Tabs to the right to be closed" ,
1511+ 1000
1512+ ) ;
1513+
1514+ // Verify only the first tab remains
1515+ expect ( tabExists ( testFilePath ) ) . toBe ( true ) ;
1516+ expect ( tabExists ( testFilePath2 ) ) . toBe ( false ) ;
1517+ expect ( tabExists ( testFilePath3 ) ) . toBe ( false ) ;
1518+ expect ( getTabCount ( ) ) . toBe ( 1 ) ;
1519+ } ) ;
1520+
1521+ it ( "should close tabs to the left when selecting 'Close tabs to the left' from context menu" , async function ( ) {
1522+ // Open all three test files
1523+ await awaitsForDone (
1524+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath } ) ,
1525+ "Open first test file"
1526+ ) ;
1527+ await awaitsForDone (
1528+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath2 } ) ,
1529+ "Open second test file"
1530+ ) ;
1531+ await awaitsForDone (
1532+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath3 } ) ,
1533+ "Open third test file"
1534+ ) ;
1535+
1536+ // Wait for all tabs to appear
1537+ await awaitsFor (
1538+ function ( ) {
1539+ return tabExists ( testFilePath ) && tabExists ( testFilePath2 ) && tabExists ( testFilePath3 ) ;
1540+ } ,
1541+ "All tabs to appear" ,
1542+ 1000
1543+ ) ;
1544+
1545+ // Verify all three tabs exist
1546+ expect ( tabExists ( testFilePath ) ) . toBe ( true ) ;
1547+ expect ( tabExists ( testFilePath2 ) ) . toBe ( true ) ;
1548+ expect ( tabExists ( testFilePath3 ) ) . toBe ( true ) ;
1549+
1550+ // Get the third tab element
1551+ const $tab = getTab ( testFilePath3 ) ;
1552+
1553+ // Right-click on the third tab to open context menu
1554+ $tab . trigger ( "contextmenu" , {
1555+ pageX : 100 ,
1556+ pageY : 100
1557+ } ) ;
1558+
1559+ // Wait for context menu to appear
1560+ await awaitsFor (
1561+ function ( ) {
1562+ return getContextMenu ( ) . length > 0 ;
1563+ } ,
1564+ "Context menu to appear" ,
1565+ 1000
1566+ ) ;
1567+
1568+ // Find and click the "Close tabs to the left" option
1569+ const $closeTabsToLeftOption = getContextMenu ( )
1570+ . find ( "a.stylesheet-link" )
1571+ . filter ( function ( ) {
1572+ return $ ( this ) . text ( ) . trim ( ) === Strings . CLOSE_TABS_TO_THE_LEFT ;
1573+ } ) ;
1574+ expect ( $closeTabsToLeftOption . length ) . toBe ( 1 ) ;
1575+ $closeTabsToLeftOption . click ( ) ;
1576+
1577+ // Cancel any save dialogs that might appear
1578+ testWindow . brackets . test . Dialogs . cancelModalDialogIfOpen (
1579+ testWindow . brackets . test . DefaultDialogs . DIALOG_ID_SAVE_CLOSE ,
1580+ testWindow . brackets . test . DefaultDialogs . DIALOG_BTN_DONTSAVE
1581+ ) ;
1582+
1583+ // Verify tabs to the left are closed
1584+ await awaitsFor (
1585+ function ( ) {
1586+ return ! tabExists ( testFilePath ) && ! tabExists ( testFilePath2 ) && tabExists ( testFilePath3 ) ;
1587+ } ,
1588+ "Tabs to the left to be closed" ,
1589+ 1000
1590+ ) ;
1591+
1592+ // Verify only the third tab remains
1593+ expect ( tabExists ( testFilePath ) ) . toBe ( false ) ;
1594+ expect ( tabExists ( testFilePath2 ) ) . toBe ( false ) ;
1595+ expect ( tabExists ( testFilePath3 ) ) . toBe ( true ) ;
1596+ expect ( getTabCount ( ) ) . toBe ( 1 ) ;
1597+ } ) ;
1598+
1599+ it ( "should close saved tabs when selecting 'Close saved tabs' from context menu" , async function ( ) {
1600+ // Open all three test files
1601+ await awaitsForDone (
1602+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath } ) ,
1603+ "Open first test file"
1604+ ) ;
1605+ await awaitsForDone (
1606+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath2 } ) ,
1607+ "Open second test file"
1608+ ) ;
1609+ await awaitsForDone (
1610+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath3 } ) ,
1611+ "Open third test file"
1612+ ) ;
1613+
1614+ // Wait for all tabs to appear
1615+ await awaitsFor (
1616+ function ( ) {
1617+ return tabExists ( testFilePath ) && tabExists ( testFilePath2 ) && tabExists ( testFilePath3 ) ;
1618+ } ,
1619+ "All tabs to appear" ,
1620+ 1000
1621+ ) ;
1622+
1623+ // Verify all three tabs exist
1624+ expect ( tabExists ( testFilePath ) ) . toBe ( true ) ;
1625+ expect ( tabExists ( testFilePath2 ) ) . toBe ( true ) ;
1626+ expect ( tabExists ( testFilePath3 ) ) . toBe ( true ) ;
1627+
1628+ // Make the second file dirty
1629+ const doc2 = DocumentManager . getOpenDocumentForPath ( testFilePath2 ) ;
1630+ doc2 . setText ( "// Modified content" ) ;
1631+
1632+ // Wait for the dirty indicator to appear
1633+ await awaitsFor (
1634+ function ( ) {
1635+ return isTabDirty ( testFilePath2 ) ;
1636+ } ,
1637+ "Dirty indicator to appear" ,
1638+ 1000
1639+ ) ;
1640+
1641+ // Verify the second tab is dirty
1642+ expect ( isTabDirty ( testFilePath2 ) ) . toBe ( true ) ;
1643+
1644+ // Get any tab element (we'll use the first)
1645+ const $tab = getTab ( testFilePath ) ;
1646+
1647+ // Right-click on the tab to open context menu
1648+ $tab . trigger ( "contextmenu" , {
1649+ pageX : 100 ,
1650+ pageY : 100
1651+ } ) ;
1652+
1653+ // Wait for context menu to appear
1654+ await awaitsFor (
1655+ function ( ) {
1656+ return getContextMenu ( ) . length > 0 ;
1657+ } ,
1658+ "Context menu to appear" ,
1659+ 1000
1660+ ) ;
1661+
1662+ // Find and click the "Close saved tabs" option
1663+ const $closeSavedTabsOption = getContextMenu ( )
1664+ . find ( "a.stylesheet-link" )
1665+ . filter ( function ( ) {
1666+ return $ ( this ) . text ( ) . trim ( ) === Strings . CLOSE_SAVED_TABS ;
1667+ } ) ;
1668+ expect ( $closeSavedTabsOption . length ) . toBe ( 1 ) ;
1669+ $closeSavedTabsOption . click ( ) ;
1670+
1671+ // Cancel any save dialogs that might appear
1672+ testWindow . brackets . test . Dialogs . cancelModalDialogIfOpen (
1673+ testWindow . brackets . test . DefaultDialogs . DIALOG_ID_SAVE_CLOSE ,
1674+ testWindow . brackets . test . DefaultDialogs . DIALOG_BTN_DONTSAVE
1675+ ) ;
1676+
1677+ // Verify only the dirty tab remains
1678+ await awaitsFor (
1679+ function ( ) {
1680+ return ! tabExists ( testFilePath ) && tabExists ( testFilePath2 ) && ! tabExists ( testFilePath3 ) ;
1681+ } ,
1682+ "Saved tabs to be closed" ,
1683+ 1000
1684+ ) ;
1685+
1686+ expect ( tabExists ( testFilePath ) ) . toBe ( false ) ;
1687+ expect ( tabExists ( testFilePath2 ) ) . toBe ( true ) ;
1688+ expect ( tabExists ( testFilePath3 ) ) . toBe ( false ) ;
1689+ expect ( getTabCount ( ) ) . toBe ( 1 ) ;
1690+ expect ( isTabDirty ( testFilePath2 ) ) . toBe ( true ) ;
1691+
1692+ // Clean up - revert changes to the second file
1693+ doc2 . setText ( "// Test file 2 for TabBar" ) ;
1694+ await awaitsForDone (
1695+ CommandManager . execute ( Commands . FILE_SAVE , { doc : doc2 } ) ,
1696+ "Save file with original content"
1697+ ) ;
1698+ } ) ;
1699+
1700+ it ( "should close all tabs when selecting 'Close all tabs' from context menu" , async function ( ) {
1701+ // Open all three test files
1702+ await awaitsForDone (
1703+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath } ) ,
1704+ "Open first test file"
1705+ ) ;
1706+ await awaitsForDone (
1707+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath2 } ) ,
1708+ "Open second test file"
1709+ ) ;
1710+ await awaitsForDone (
1711+ CommandManager . execute ( Commands . FILE_OPEN , { fullPath : testFilePath3 } ) ,
1712+ "Open third test file"
1713+ ) ;
1714+
1715+ // Wait for all tabs to appear
1716+ await awaitsFor (
1717+ function ( ) {
1718+ return tabExists ( testFilePath ) && tabExists ( testFilePath2 ) && tabExists ( testFilePath3 ) ;
1719+ } ,
1720+ "All tabs to appear" ,
1721+ 1000
1722+ ) ;
1723+
1724+ // Verify all three tabs exist
1725+ expect ( tabExists ( testFilePath ) ) . toBe ( true ) ;
1726+ expect ( tabExists ( testFilePath2 ) ) . toBe ( true ) ;
1727+ expect ( tabExists ( testFilePath3 ) ) . toBe ( true ) ;
1728+
1729+ // Get any tab element (we'll use the first)
1730+ const $tab = getTab ( testFilePath ) ;
1731+
1732+ // Right-click on the tab to open context menu
1733+ $tab . trigger ( "contextmenu" , {
1734+ pageX : 100 ,
1735+ pageY : 100
1736+ } ) ;
1737+
1738+ // Wait for context menu to appear
1739+ await awaitsFor (
1740+ function ( ) {
1741+ return getContextMenu ( ) . length > 0 ;
1742+ } ,
1743+ "Context menu to appear" ,
1744+ 1000
1745+ ) ;
1746+
1747+ // Find and click the "Close all tabs" option
1748+ const $closeAllTabsOption = getContextMenu ( )
1749+ . find ( "a.stylesheet-link" )
1750+ . filter ( function ( ) {
1751+ return $ ( this ) . text ( ) . trim ( ) === Strings . CLOSE_ALL_TABS ;
1752+ } ) ;
1753+ expect ( $closeAllTabsOption . length ) . toBe ( 1 ) ;
1754+ $closeAllTabsOption . click ( ) ;
1755+
1756+ // Cancel any save dialogs that might appear
1757+ testWindow . brackets . test . Dialogs . cancelModalDialogIfOpen (
1758+ testWindow . brackets . test . DefaultDialogs . DIALOG_ID_SAVE_CLOSE ,
1759+ testWindow . brackets . test . DefaultDialogs . DIALOG_BTN_DONTSAVE
1760+ ) ;
1761+
1762+ // Verify all tabs are closed
1763+ await awaitsFor (
1764+ function ( ) {
1765+ return ! tabExists ( testFilePath ) && ! tabExists ( testFilePath2 ) && ! tabExists ( testFilePath3 ) ;
1766+ } ,
1767+ "All tabs to be closed" ,
1768+ 1000
1769+ ) ;
1770+
1771+ expect ( tabExists ( testFilePath ) ) . toBe ( false ) ;
1772+ expect ( tabExists ( testFilePath2 ) ) . toBe ( false ) ;
1773+ expect ( tabExists ( testFilePath3 ) ) . toBe ( false ) ;
1774+ expect ( getTabCount ( ) ) . toBe ( 0 ) ;
1775+ } ) ;
14321776 } ) ;
14331777 } ) ;
14341778} ) ;
0 commit comments