Search in sources :

Example 1 with ToolbarPanel

use of com.oxygenxml.git.view.staging.ToolbarPanel in project oxygen-git-client-addon by oxygenxml.

the class StashVisualTests method testListStashDeleteAction.

/**
 * <p><b>Description:</b> Tests the "List stashes" delete action</p>
 * <p><b>Bug ID:</b> EXM-45983</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testListStashDeleteAction() 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());
        JButton[] deleteSelectedStashButton = new JButton[1];
        flushAWT();
        deleteSelectedStashButton[0] = findFirstButton(listStashesDialog, Tags.DELETE);
        assertNotNull(deleteSelectedStashButton);
        SwingUtilities.invokeLater(() -> deleteSelectedStashButton[0].doClick());
        flushAWT();
        // Test the no button.
        JDialog deleteSelectedStashDialog = findDialog(Tags.DELETE_STASH);
        assertNotNull(deleteSelectedStashDialog);
        JButton[] noButton = new JButton[1];
        flushAWT();
        noButton[0] = findFirstButton(deleteSelectedStashDialog, Tags.NO);
        assertNotNull(noButton[0]);
        SwingUtilities.invokeLater(() -> noButton[0].doClick());
        flushAWT();
        stashes = new ArrayList<>(gitAccess.listStashes());
        assertEquals(3, stashes.size());
        listStashesItem[0] = stashButton.getItem(1);
        SwingUtilities.invokeLater(() -> listStashesItem[0].getAction().actionPerformed(null));
        // Test the yes button.
        String[] stashesMessages = { "Stash1", "Stash0" };
        // Delete all stashes one by one
        for (int i = 0; i < 3; i++) {
            flushAWT();
            deleteSelectedStashButton[0] = findFirstButton(listStashesDialog, Tags.DELETE);
            assertNotNull(deleteSelectedStashButton);
            SwingUtilities.invokeLater(() -> deleteSelectedStashButton[0].doClick());
            flushAWT();
            deleteSelectedStashDialog = findDialog(Tags.DELETE_STASH);
            assertNotNull(deleteSelectedStashDialog);
            flushAWT();
            JButton yesButton = findFirstButton(deleteSelectedStashDialog, Tags.YES);
            assertNotNull(yesButton);
            SwingUtilities.invokeLater(yesButton::doClick);
            flushAWT();
            stashes = new ArrayList<>(gitAccess.listStashes());
            assertEquals(3 - i - 1, stashes.size());
            assertEquals(3 - i - 1, listStashesDialog.getStashesTable().getRowCount());
            int stashIndex = 0;
            for (int j = i + 1; j < 3; j++) {
                assertEquals(stashesMessages[i + stashIndex], stashes.get(stashIndex).getFullMessage());
                assertEquals(stashesMessages[i + stashIndex], listStashesDialog.getStashesTable().getValueAt(stashIndex++, 1));
            }
        }
        flushAWT();
        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) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) ToolbarPanel(com.oxygenxml.git.view.staging.ToolbarPanel) JDialog(javax.swing.JDialog) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with ToolbarPanel

use of com.oxygenxml.git.view.staging.ToolbarPanel in project oxygen-git-client-addon by oxygenxml.

the class StashVisualTests method testListStashApplyAndPopAction.

/**
 * <p><b>Description:</b> Tests the "List stashes" apply and pop actions</p>
 * <p><b>Bug ID:</b> EXM-45983</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testListStashApplyAndPopAction() throws Exception {
    // Init UI
    JFrame frame = new JFrame();
    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();
    // 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();
    try {
        SplitMenuButton stashButton = toolbarPanel.getStashButton();
        makeLocalChange("some_modification");
        flushAWT();
        JMenuItem[] stashChangesItem = new JMenuItem[1];
        stashChangesItem[0] = stashButton.getItem(0);
        SwingUtilities.invokeLater(() -> stashChangesItem[0].getAction().actionPerformed(null));
        flushAWT();
        // Stash changes and test if the actions become disabled.
        JDialog stashChangesDialog = findDialog(Tags.STASH_CHANGES);
        flushAWT();
        assertNotNull(stashChangesDialog);
        JButton doStashButton = findFirstButton(stashChangesDialog, Tags.STASH);
        assertNotNull(doStashButton);
        doStashButton.doClick();
        refreshSupport.call();
        flushAWT();
        assertEquals("local content", getFileContent(LOCAL_REPO + "/local.txt"));
        JMenuItem[] listStashesItem = new JMenuItem[1];
        listStashesItem[0] = stashButton.getItem(1);
        SwingUtilities.invokeLater(() -> listStashesItem[0].getAction().actionPerformed(null));
        flushAWT();
        ListStashesDialog listStashesDialog = (ListStashesDialog) findDialog(Tags.STASHES);
        flushAWT();
        assertNotNull(listStashesDialog);
        JCheckBox[] popStashCheckBox = new JCheckBox[1];
        flushAWT();
        popStashCheckBox[0] = findCheckBox(listStashesDialog, Tags.DELETE_STASH_AFTER_APPLIED);
        assertNotNull(popStashCheckBox[0]);
        SwingUtilities.invokeLater(() -> popStashCheckBox[0].setSelected(true));
        flushAWT();
        List<RevCommit> stashes = new ArrayList<>(gitAccess.listStashes());
        assertFalse(stashes.isEmpty());
        assertEquals(1, listStashesDialog.getStashesTable().getRowCount());
        JButton[] applyButton = new JButton[1];
        flushAWT();
        applyButton[0] = findFirstButton(listStashesDialog, Tags.APPLY);
        assertNotNull(applyButton[0]);
        SwingUtilities.invokeLater(() -> applyButton[0].doClick());
        flushAWT();
        // Check if the stash was been deleted and applied
        stashes = new ArrayList<>(gitAccess.listStashes());
        assertTrue(stashes.isEmpty());
        assertEquals(0, listStashesDialog.getStashesTable().getRowCount());
        assertEquals("some_modification", getFileContent(LOCAL_REPO + "/local.txt"));
        JButton cancelButton = findFirstButton(listStashesDialog, Tags.CLOSE);
        assertNotNull(cancelButton);
        cancelButton.doClick();
        stashChangesItem[0] = stashButton.getItem(0);
        SwingUtilities.invokeLater(() -> stashChangesItem[0].getAction().actionPerformed(null));
        flushAWT();
        stashChangesDialog = findDialog(Tags.STASH_CHANGES);
        assertNotNull(stashChangesDialog);
        doStashButton = findFirstButton(stashChangesDialog, Tags.STASH);
        assertNotNull(doStashButton);
        doStashButton.doClick();
        refreshSupport.call();
        flushAWT();
        assertEquals("local content", getFileContent(LOCAL_REPO + "/local.txt"));
        listStashesItem[0] = stashButton.getItem(1);
        SwingUtilities.invokeLater(() -> listStashesItem[0].getAction().actionPerformed(null));
        listStashesDialog = (ListStashesDialog) findDialog(Tags.STASHES);
        assertNotNull(listStashesDialog);
        popStashCheckBox[0] = findCheckBox(listStashesDialog, Tags.DELETE_STASH_AFTER_APPLIED);
        assertNotNull(popStashCheckBox[0]);
        SwingUtilities.invokeLater(() -> popStashCheckBox[0].setSelected(false));
        flushAWT();
        applyButton[0] = findFirstButton(listStashesDialog, Tags.APPLY);
        assertNotNull(applyButton[0]);
        SwingUtilities.invokeLater(() -> applyButton[0].doClick());
        flushAWT();
        stashes = new ArrayList<>(gitAccess.listStashes());
        assertFalse(stashes.isEmpty());
        assertEquals(1, listStashesDialog.getStashesTable().getRowCount());
        assertEquals("some_modification", getFileContent(LOCAL_REPO + "/local.txt"));
        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) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) GitController(com.oxygenxml.git.view.event.GitController) ListStashesDialog(com.oxygenxml.git.view.stash.ListStashesDialog) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager) JCheckBox(javax.swing.JCheckBox) 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)

Example 3 with ToolbarPanel

use of com.oxygenxml.git.view.staging.ToolbarPanel in project oxygen-git-client-addon by oxygenxml.

the class ToolbarPanelTest method testButtonsWhenNoRepo.

/**
 * <p><b>Description:</b> when trying to switch to another branch from the branches menu
 * and the checkout fails, tests the dialog</p>
 * <p><b>Bug ID:</b> EXM-48502</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testButtonsWhenNoRepo() throws Exception {
    File testDir = new File(String.format("target/test-resources/ToolbarPanelTest/%s", this.getName()));
    try {
        GitController gitCtrl = new GitController();
        GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
        stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
        refreshSupport.setStagingPanel(stagingPanel);
        ToolbarPanel toolbar = stagingPanel.getToolbarPanel();
        assertFalse("No repo, the button should be disabled.", toolbar.getPullMenuButton().isEnabled());
        assertFalse(toolbar.getPushButton().isEnabled());
        assertFalse(toolbar.getStashButton().isEnabled());
        // Creates repos
        String local = String.format("target/test-resources/ToolbarPanelTest/%s/localRepository", this.getName());
        String remote = String.format("target/test-resources/ToolbarPanelTest/%s/remoteRepository", this.getName());
        // Creates the remote repository.
        createRepo(remote, local);
        Repository remoteRepository = createRepository(remote);
        Repository localRepository = createRepository(local);
        bindLocalToRemote(localRepository, remoteRepository);
        flushAWT();
        assertTrue("Pull Merge action should be enabled.", gitActionsManager.getPullMergeAction().isEnabled());
        assertTrue("Pull Rebase action should be enabled.", gitActionsManager.getPullRebaseAction().isEnabled());
        assertTrue(toolbar.getPullMenuButton().isEnabled());
        assertTrue("Push action should be enabled.", gitActionsManager.getPushAction().isEnabled());
        assertTrue(toolbar.getPushButton().isEnabled());
        assertFalse(toolbar.getStashButton().isEnabled());
    } finally {
        FileSystemUtil.deleteRecursivelly(testDir);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) ToolbarPanel(com.oxygenxml.git.view.staging.ToolbarPanel) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

Example 4 with ToolbarPanel

use of com.oxygenxml.git.view.staging.ToolbarPanel in project oxygen-git-client-addon by oxygenxml.

the class StashVisualTests method testStashChanges.

/**
 * <p><b>Description:</b> Tests the "Stash" button basic characteristics and the "Stash Changes" functionality.</p>
 * <p><b>Bug ID:</b> EXM-45983</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testStashChanges() 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);
        refreshSupport.setStagingPanel(stagingPanel);
        ToolbarPanel toolbarPanel = stagingPanel.getToolbarPanel();
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        flushAWT();
        refreshSupport.call();
        flushAWT();
        SplitMenuButton stashButton = toolbarPanel.getStashButton();
        // Test the "Stash" button tooltip text
        assertEquals(Tags.STASH, stashButton.getToolTipText());
        refreshSupport.call();
        flushAWT();
        // Test if the button is disabled if none actions are possible.
        assertFalse(stashButton.isEnabled());
        makeLocalChange("new 2");
        JMenuItem stashChangesItem = stashButton.getItem(0);
        SwingUtilities.invokeLater(() -> stashChangesItem.getAction().actionPerformed(null));
        flushAWT();
        // Stash changes and test if the actions become disabled.
        JDialog stashChangesDialog = findDialog(Tags.STASH_CHANGES);
        assertNotNull(stashChangesDialog);
        flushAWT();
        JButton doStashButton = findFirstButton(stashChangesDialog, Tags.STASH);
        assertNotNull(doStashButton);
        doStashButton.doClick();
        refreshSupport.call();
        flushAWT();
        assertFalse(stashChangesItem.isEnabled());
        // Test if the stash were created.
        List<RevCommit> stashes = new ArrayList<>(gitAccess.listStashes());
        assertEquals(1, stashes.size());
        makeLocalChange("new 3");
        SwingUtilities.invokeLater(() -> {
            stashChangesItem.setSelected(true);
            stashChangesItem.getAction().actionPerformed(null);
        });
        flushAWT();
        // Test if the user can add a custom text
        stashChangesDialog = findDialog(Tags.STASH_CHANGES);
        assertNotNull(stashChangesDialog);
        flushAWT();
        JTextField textField = TestUtil.findFirstTextField(stashChangesDialog);
        assertNotNull(textField);
        textField.setText("Some custom text by user.");
        flushAWT();
        doStashButton = findFirstButton(stashChangesDialog, Tags.STASH);
        assertNotNull(doStashButton);
        doStashButton.doClick();
        refreshSupport.call();
        flushAWT();
        stashes = new ArrayList<>(gitAccess.listStashes());
        assertEquals(2, stashes.size());
        assertEquals("Some custom text by user.", stashes.get(0).getFullMessage());
        makeLocalChange("new 4");
        SwingUtilities.invokeLater(() -> stashChangesItem.getAction().actionPerformed(null));
        flushAWT();
        // Stash changes and test if the actions become disabled.
        stashChangesDialog = findDialog(Tags.STASH_CHANGES);
        assertNotNull(stashChangesDialog);
        flushAWT();
        JButton cancelStashButton = findFirstButton(stashChangesDialog, Tags.CANCEL);
        assertNotNull(cancelStashButton);
        cancelStashButton.doClick();
        refreshSupport.call();
        flushAWT();
        assertTrue(stashChangesItem.isEnabled());
        // Test if the stash wasn't created.
        stashes = new ArrayList<>(gitAccess.listStashes());
        assertEquals(2, stashes.size());
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) SplitMenuButton(ro.sync.exml.workspace.api.standalone.ui.SplitMenuButton) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) GitController(com.oxygenxml.git.view.event.GitController) JTextField(javax.swing.JTextField) 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)

Example 5 with ToolbarPanel

use of com.oxygenxml.git.view.staging.ToolbarPanel in project oxygen-git-client-addon by oxygenxml.

the class StashVisualTests method testListStashAffectedFilesTable.

/**
 * <p><b>Description:</b> Tests the "List stashes" affected files table</p>
 * <p><b>Bug ID:</b> EXM-45983</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testListStashAffectedFilesTable() 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();
        String[] filesNames = { "local.txt", "local1.txt", "local2.txt", "local3.txt", "local4.txt" };
        String[] foldersName = { "folder0", "folder1", "folder2", "folder3", "folder4", "folder5", "very_very_veeeeeeeeeeeeeeeeeery_long_folder_name" };
        String path = LOCAL_REPO + "/";
        String fileWithLongPathName = "file_with_long_path.txt";
        for (int i = 0; i < foldersName.length; i++) {
            path += foldersName[i];
            file = new File(path);
            assertTrue(file.mkdir());
        }
        makeLocalChange("some_modification");
        for (int i = 1; i < filesNames.length; i++) {
            file = new File(LOCAL_REPO, filesNames[i]);
            assertTrue(file.createNewFile());
            setFileContent(file, "local content" + i);
            gitAccess.add(new FileStatus(GitChangeType.ADD, filesNames[i]));
        }
        file = new File(path, fileWithLongPathName);
        assertTrue(file.createNewFile());
        setFileContent(file, "local content");
        flushAWT();
        gitAccess.add(new FileStatus(GitChangeType.ADD, path + fileWithLongPathName));
        path = path.substring((LOCAL_REPO + "/").length());
        flushAWT();
        JMenuItem[] stashChangesItem = new JMenuItem[1];
        stashChangesItem[0] = stashButton.getItem(0);
        SwingUtilities.invokeLater(() -> stashChangesItem[0].getAction().actionPerformed(null));
        flushAWT();
        JDialog stashChangesDialog = findDialog(Tags.STASH_CHANGES);
        flushAWT();
        assertNotNull(stashChangesDialog);
        JButton doStashButton = findFirstButton(stashChangesDialog, Tags.STASH);
        flushAWT();
        assertNotNull(doStashButton);
        doStashButton.doClick();
        refreshSupport.call();
        flushAWT();
        makeLocalChange("another_modification");
        flushAWT();
        stashChangesItem[0] = stashButton.getItem(0);
        SwingUtilities.invokeLater(() -> stashChangesItem[0].getAction().actionPerformed(null));
        flushAWT();
        stashChangesDialog = findDialog(Tags.STASH_CHANGES);
        flushAWT();
        assertNotNull(stashChangesDialog);
        doStashButton = findFirstButton(stashChangesDialog, Tags.STASH);
        assertNotNull(doStashButton);
        doStashButton.doClick();
        refreshSupport.call();
        flushAWT();
        JMenuItem[] listStashesItem = new JMenuItem[1];
        listStashesItem[0] = stashButton.getItem(1);
        SwingUtilities.invokeLater(() -> listStashesItem[0].getAction().actionPerformed(null));
        ListStashesDialog listStashesDialog = (ListStashesDialog) findDialog(Tags.STASHES);
        flushAWT();
        assertNotNull(listStashesDialog);
        StagingResourcesTableCellRenderer filesRender = (StagingResourcesTableCellRenderer) listStashesDialog.getAffectedFilesTable().getDefaultRenderer(FileStatus.class);
        FilesTableModel stashFilesTableModel = (FilesTableModel) listStashesDialog.getAffectedFilesTable().getModel();
        assertEquals(GitChangeType.CHANGED, stashFilesTableModel.getValueAt(0, 0));
        assertEquals(filesNames[0], ((FileStatus) stashFilesTableModel.getValueAt(0, 1)).getFileLocation());
        stashFilesTableModel = (FilesTableModel) listStashesDialog.getAffectedFilesTable().getModel();
        SwingUtilities.invokeLater(() -> listStashesDialog.getStashesTable().setRowSelectionInterval(1, 1));
        flushAWT();
        for (int i = 0; i < filesNames.length - 1; i++) {
            assertEquals(GitChangeType.ADD, stashFilesTableModel.getValueAt(i, 0));
            assertEquals(filesNames[i + 1], ((FileStatus) stashFilesTableModel.getValueAt(i, 1)).getFileLocation());
            String toolTipFileText = ((JLabel) filesRender.getTableCellRendererComponent(listStashesDialog.getAffectedFilesTable(), stashFilesTableModel.getValueAt(i, 1), true, true, i, 1)).getToolTipText();
            assertEquals(filesNames[i + 1], toolTipFileText);
        }
        int length = filesNames.length;
        assertEquals(GitChangeType.CHANGED, stashFilesTableModel.getValueAt(length - 1, 0));
        assertEquals(filesNames[0], ((FileStatus) stashFilesTableModel.getValueAt(length - 1, 1)).getFileLocation());
        String toolTipFileText = ((JLabel) filesRender.getTableCellRendererComponent(listStashesDialog.getAffectedFilesTable(), stashFilesTableModel.getValueAt(length - 1, 1), true, true, length - 1, 1)).getToolTipText();
        assertEquals(filesNames[0], toolTipFileText);
        toolTipFileText = ((JLabel) filesRender.getTableCellRendererComponent(listStashesDialog.getAffectedFilesTable(), stashFilesTableModel.getValueAt(length, 1), true, true, length, 1)).getToolTipText();
        assertEquals(fileWithLongPathName + " - " + path, toolTipFileText);
        flushAWT();
        stashFilesTableModel = (FilesTableModel) listStashesDialog.getAffectedFilesTable().getModel();
        SwingUtilities.invokeLater(() -> listStashesDialog.getStashesTable().setRowSelectionInterval(0, 0));
        flushAWT();
        assertEquals(GitChangeType.CHANGED, stashFilesTableModel.getValueAt(0, 0));
        assertEquals(filesNames[0], ((FileStatus) stashFilesTableModel.getValueAt(0, 1)).getFileLocation());
        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) FilesTableModel(com.oxygenxml.git.view.stash.FilesTableModel) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) 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) StagingResourcesTableCellRenderer(com.oxygenxml.git.view.staging.StagingResourcesTableCellRenderer) 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)

Aggregations

GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)7 GitController (com.oxygenxml.git.view.event.GitController)7 StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)7 ToolbarPanel (com.oxygenxml.git.view.staging.ToolbarPanel)7 File (java.io.File)7 FileStatus (com.oxygenxml.git.service.entities.FileStatus)6 JButton (javax.swing.JButton)6 JFrame (javax.swing.JFrame)6 JMenuItem (javax.swing.JMenuItem)6 SplitMenuButton (ro.sync.exml.workspace.api.standalone.ui.SplitMenuButton)6 ListStashesDialog (com.oxygenxml.git.view.stash.ListStashesDialog)5 ArrayList (java.util.ArrayList)5 JDialog (javax.swing.JDialog)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 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 JTextField (javax.swing.JTextField)1