Search in sources :

Example 1 with TagDetailsDialog

use of com.oxygenxml.git.view.tags.TagDetailsDialog 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

GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)1 GitController (com.oxygenxml.git.view.event.GitController)1 CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)1 StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)1 GitTag (com.oxygenxml.git.view.tags.GitTag)1 TagDetailsDialog (com.oxygenxml.git.view.tags.TagDetailsDialog)1 TagsDialog (com.oxygenxml.git.view.tags.TagsDialog)1 TagsTableModel (com.oxygenxml.git.view.tags.TagsTableModel)1 JDialog (javax.swing.JDialog)1 JFrame (javax.swing.JFrame)1 JTable (javax.swing.JTable)1 JTextArea (javax.swing.JTextArea)1