Search in sources :

Example 11 with StagingPanel

use of com.oxygenxml.git.view.staging.StagingPanel 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 12 with StagingPanel

use of com.oxygenxml.git.view.staging.StagingPanel 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)

Example 13 with StagingPanel

use of com.oxygenxml.git.view.staging.StagingPanel 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)

Example 14 with StagingPanel

use of com.oxygenxml.git.view.staging.StagingPanel 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)

Example 15 with StagingPanel

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

the class TagsVisualTests method testTagsDialog.

/**
 * <p><b>Description:</b> Tests the "Show Tags" button basic characteristics and the "Show details" functionality.</p>
 * <p><b>Bug ID:</b> EXM-46109</p>
 *
 * @author gabriel_nedianu
 *
 * @throws Exception
 */
public void testTagsDialog() throws Exception {
    createCommits(4);
    // Make 3 tags ( 2nd tag will be pushed )
    List<CommitCharacteristics> commitsCharacteristics = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String commitIdForTag1 = commitsCharacteristics.get(0).getCommitId();
    gitAccess.tagCommit("Tag1", "MesajTag1", commitIdForTag1);
    sleep(1000);
    String commitIdForTag2 = commitsCharacteristics.get(2).getCommitId();
    gitAccess.tagCommit("Tag2", "MesajTag2", commitIdForTag2);
    gitAccess.pushTag("Tag2");
    sleep(1000);
    String commitIdForTag3 = commitsCharacteristics.get(3).getCommitId();
    gitAccess.tagCommit("Tag3", "", commitIdForTag3);
    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);
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        flushAWT();
        refreshSupport.call();
        flushAWT();
        gitActionsManager.getShowTagsAction().actionPerformed(null);
        sleep(50);
        flushAWT();
        JDialog tagsDialog = findDialog(Tags.TAGS_DIALOG);
        assertNotNull(tagsDialog);
        TagsDialog showTagsJDialog = null;
        if (tagsDialog instanceof TagsDialog) {
            showTagsJDialog = (TagsDialog) tagsDialog;
        }
        assertNotNull(showTagsJDialog);
        JTable tagsTable = showTagsJDialog.getTagsTable();
        // Should have 3 tags
        assertEquals(3, tagsTable.getModel().getRowCount());
        // Get the model of the tags table and verify the tags
        TagsTableModel tableModel = (TagsTableModel) tagsTable.getModel();
        // Verify 1st tag that should be the last in the table
        GitTag tag1 = tableModel.getItemAt(2);
        assertEquals(commitIdForTag1, tag1.getCommitID());
        assertEquals("Tag1", tag1.getName());
        assertEquals("MesajTag1", tag1.getMessage());
        assertFalse(tag1.isPushed());
        // 2nd tag in the table should be pushed
        GitTag tag2 = tableModel.getItemAt(1);
        assertEquals(commitIdForTag2, tag2.getCommitID());
        assertEquals("Tag2", tag2.getName());
        assertEquals("MesajTag2", tag2.getMessage());
        assertTrue(tag2.isPushed());
        // Verify 3rd tag added (the most recent so it s first in the tags table)
        GitTag tag3 = tableModel.getItemAt(0);
        assertEquals(commitIdForTag3, tag3.getCommitID());
        assertEquals("Tag3", tag3.getName());
        assertEquals("", tag3.getMessage());
        assertFalse(tag3.isPushed());
        // Select first row and verify if the push and delete buttons are enabled
        tagsTable.setRowSelectionInterval(0, 0);
        assertTrue(showTagsJDialog.getPushButton().isEnabled());
        assertTrue(showTagsJDialog.getDeleteButton().isEnabled());
        // Select 2nd row and verify if the buttons are not enabled
        tagsTable.setRowSelectionInterval(1, 1);
        assertFalse(showTagsJDialog.getPushButton().isEnabled());
        assertFalse(showTagsJDialog.getDeleteButton().isEnabled());
        // Select first row and push the tag and verify if the buttons are not enabled and the tag was pushed
        tagsTable.setRowSelectionInterval(0, 0);
        showTagsJDialog.getPushButton().doClick();
        assertFalse(showTagsJDialog.getPushButton().isEnabled());
        assertFalse(showTagsJDialog.getDeleteButton().isEnabled());
        assertTrue(tag3.isPushed());
        final TagsDialog tagsFinalJDialog = showTagsJDialog;
        // Select last row and delete the tag and verify if the tag doesn't exist
        tagsTable.setRowSelectionInterval(2, 2);
        SwingUtilities.invokeLater(() -> tagsFinalJDialog.getDeleteButton().doClick());
        flushAWT();
        JDialog deleteDialog = findDialog(Tags.DELETE_TAG_DIALOG_TITLE);
        assertNotNull(deleteDialog);
        findFirstButton(deleteDialog, Tags.YES).doClick();
        flushAWT();
        assertFalse(gitAccess.existsTag("Tag1"));
        // Verify how many rows has the table left
        assertEquals(2, tagsTable.getRowCount());
        // Verify the tagDetails Dialog
        new TagDetailsDialog(tag3).setVisible(true);
        flushAWT();
        JDialog tagDetailsDialog = findDialog(Tags.TAG_DETAILS_DIALOG_TITLE);
        assertNotNull(tagDetailsDialog);
        JTextArea tagMessageArea = findFirstTextArea(tagDetailsDialog);
        // Tag doesn't have a message
        assertEquals("", tagMessageArea.getText());
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : TagDetailsDialog(com.oxygenxml.git.view.tags.TagDetailsDialog) JTextArea(javax.swing.JTextArea) GitController(com.oxygenxml.git.view.event.GitController) TagsDialog(com.oxygenxml.git.view.tags.TagsDialog) GitTag(com.oxygenxml.git.view.tags.GitTag) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager) TagsTableModel(com.oxygenxml.git.view.tags.TagsTableModel) JFrame(javax.swing.JFrame) JTable(javax.swing.JTable) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) JDialog(javax.swing.JDialog)

Aggregations

StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)15 GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)14 GitController (com.oxygenxml.git.view.event.GitController)14 JFrame (javax.swing.JFrame)13 File (java.io.File)10 JButton (javax.swing.JButton)10 FileStatus (com.oxygenxml.git.service.entities.FileStatus)9 JDialog (javax.swing.JDialog)8 ToolbarPanel (com.oxygenxml.git.view.staging.ToolbarPanel)7 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 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 JTextField (javax.swing.JTextField)3 RemotesRepositoryDialog (com.oxygenxml.git.view.remotes.RemotesRepositoryDialog)2 RemotesTableModel (com.oxygenxml.git.view.remotes.RemotesTableModel)2 BranchSelectionCombo (com.oxygenxml.git.view.staging.BranchSelectionCombo)2 JTable (javax.swing.JTable)2 Repository (org.eclipse.jgit.lib.Repository)2