Search in sources :

Example 6 with ListStashesDialog

use of com.oxygenxml.git.view.stash.ListStashesDialog in project oxygen-git-client-addon by oxygenxml.

the class StashVisualTests method testListStashDeleteAllAction.

/**
 * <p><b>Description:</b> Tests the "List stashes" delete all action</p>
 * <p><b>Bug ID:</b> EXM-45983</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testListStashDeleteAllAction() throws Exception {
    // Make the first commit for the local repository
    File file = new File(LOCAL_REPO, "local.txt");
    file.createNewFile();
    setFileContent(file, "local content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
    gitAccess.commit("First local commit.");
    // Make the first commit for the remote repository
    gitAccess.setRepositorySynchronously(REMOTE_REPO);
    file = new File(REMOTE_REPO, "remote1.txt");
    file.createNewFile();
    setFileContent(file, "remote content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
    gitAccess.commit("First remote commit.");
    // Switch back to local repo and create local branch
    gitAccess.setRepositorySynchronously(LOCAL_REPO);
    gitAccess.createBranch(LOCAL_BRANCH);
    gitAccess.fetch();
    JFrame frame = new JFrame();
    try {
        // Init UI
        GitController gitCtrl = new GitController();
        GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
        stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
        ToolbarPanel toolbarPanel = stagingPanel.getToolbarPanel();
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        flushAWT();
        toolbarPanel.updateButtonsStates();
        refreshSupport.call();
        flushAWT();
        SplitMenuButton stashButton = toolbarPanel.getStashButton();
        initStashes(toolbarPanel);
        List<RevCommit> stashes = new ArrayList<>(gitAccess.listStashes());
        assertEquals(3, stashes.size());
        JMenuItem[] listStashesItem = new JMenuItem[1];
        listStashesItem[0] = stashButton.getItem(1);
        SwingUtilities.invokeLater(() -> listStashesItem[0].getAction().actionPerformed(null));
        ListStashesDialog listStashesDialog = (ListStashesDialog) findDialog(Tags.STASHES);
        assertNotNull(listStashesDialog);
        assertEquals(3, listStashesDialog.getStashesTable().getModel().getRowCount());
        assertEquals(1, listStashesDialog.getAffectedFilesTable().getModel().getRowCount());
        JButton[] deleteAllStashesButton = new JButton[1];
        deleteAllStashesButton[0] = findFirstButton(listStashesDialog, Tags.DELETE_ALL);
        assertNotNull(deleteAllStashesButton);
        SwingUtilities.invokeLater(() -> deleteAllStashesButton[0].doClick());
        flushAWT();
        // Test the no button.
        JDialog deleteAllStashesDialog = findDialog(Tags.DELETE_ALL_STASHES);
        assertNotNull(deleteAllStashesDialog);
        JButton[] noButton = new JButton[1];
        flushAWT();
        noButton[0] = findFirstButton(deleteAllStashesDialog, Tags.NO);
        assertNotNull(noButton[0]);
        SwingUtilities.invokeLater(() -> noButton[0].doClick());
        flushAWT();
        stashes = new ArrayList<>(gitAccess.listStashes());
        assertEquals(3, stashes.size());
        flushAWT();
        JButton cancelButton = findFirstButton(listStashesDialog, Tags.CLOSE);
        assertNotNull(cancelButton);
        cancelButton.doClick();
        listStashesItem[0] = stashButton.getItem(1);
        SwingUtilities.invokeLater(() -> listStashesItem[0].getAction().actionPerformed(null));
        flushAWT();
        listStashesDialog = (ListStashesDialog) findDialog(Tags.STASHES);
        assertNotNull(listStashesDialog);
        deleteAllStashesButton[0] = findFirstButton(listStashesDialog, Tags.DELETE_ALL);
        assertNotNull(deleteAllStashesButton);
        SwingUtilities.invokeLater(() -> deleteAllStashesButton[0].doClick());
        flushAWT();
        // Test the yes button.
        deleteAllStashesDialog = findDialog(Tags.DELETE_ALL_STASHES);
        assertNotNull(deleteAllStashesDialog);
        flushAWT();
        JButton yesButton = findFirstButton(deleteAllStashesDialog, Tags.YES);
        assertNotNull(yesButton);
        SwingUtilities.invokeLater(yesButton::doClick);
        flushAWT();
        stashes = new ArrayList<>(gitAccess.listStashes());
        assertEquals(0, stashes.size());
        cancelButton = findFirstButton(listStashesDialog, Tags.CLOSE);
        assertNotNull(cancelButton);
        cancelButton.doClick();
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) SplitMenuButton(ro.sync.exml.workspace.api.standalone.ui.SplitMenuButton) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) ListStashesDialog(com.oxygenxml.git.view.stash.ListStashesDialog) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager) JFrame(javax.swing.JFrame) JMenuItem(javax.swing.JMenuItem) File(java.io.File) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) ToolbarPanel(com.oxygenxml.git.view.staging.ToolbarPanel) JDialog(javax.swing.JDialog) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

ListStashesDialog (com.oxygenxml.git.view.stash.ListStashesDialog)6 FileStatus (com.oxygenxml.git.service.entities.FileStatus)5 GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)5 GitController (com.oxygenxml.git.view.event.GitController)5 StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)5 ToolbarPanel (com.oxygenxml.git.view.staging.ToolbarPanel)5 File (java.io.File)5 JButton (javax.swing.JButton)5 JFrame (javax.swing.JFrame)5 JMenuItem (javax.swing.JMenuItem)5 SplitMenuButton (ro.sync.exml.workspace.api.standalone.ui.SplitMenuButton)5 ArrayList (java.util.ArrayList)4 JDialog (javax.swing.JDialog)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 StagingResourcesTableCellRenderer (com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer)1 FilesTableModel (com.oxygenxml.git.view.stash.FilesTableModel)1 StashesTableModel (com.oxygenxml.git.view.stash.StashesTableModel)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1