Search in sources :

Example 1 with StashesTableModel

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

the class StashVisualTests method testListStashesTableValues.

/**
 * <p><b>Description:</b> Tests the "List stashes" table values</p>
 * <p><b>Bug ID:</b> EXM-45983</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testListStashesTableValues() 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);
        StashesTableModel model = (StashesTableModel) listStashesDialog.getStashesTable().getModel();
        assertEquals(3, model.getRowCount());
        assertEquals(stashes.get(0).getFullMessage(), model.getValueAt(0, StashesTableModel.STASH_DESCRIPTION_COLUMN));
        assertEquals(stashes.get(1).getFullMessage(), model.getValueAt(1, StashesTableModel.STASH_DESCRIPTION_COLUMN));
        assertEquals(stashes.get(2).getFullMessage(), model.getValueAt(2, StashesTableModel.STASH_DESCRIPTION_COLUMN));
        assertEquals(stashes.get(0).getAuthorIdent().getWhen(), model.getValueAt(0, StashesTableModel.STASH_DATE_COLUMN));
        assertEquals(stashes.get(1).getAuthorIdent().getWhen(), model.getValueAt(1, StashesTableModel.STASH_DATE_COLUMN));
        assertEquals(stashes.get(2).getAuthorIdent().getWhen(), model.getValueAt(2, StashesTableModel.STASH_DATE_COLUMN));
        JButton 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) StashesTableModel(com.oxygenxml.git.view.stash.StashesTableModel) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) ToolbarPanel(com.oxygenxml.git.view.staging.ToolbarPanel) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

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