Search in sources :

Example 1 with RenameProblemsDialog

use of net.heartsome.cat.ts.test.ui.dialogs.RenameProblemsDialog in project translationstudio8 by heartsome.

the class ProjectRename method renamePrj.

/**
	 * 重命名项目
	 * @param oldName
	 *            旧项目名称
	 * @param newName
	 *            新项目名称
	 */
private void renamePrj(Entry from, String oldName, String newName, ExpectedResult expectedResult, String invalidChar, boolean overwrite) {
    // 先取消选中项目,避免后面没有找到匹配项目时仍有之前选中的项目被误操作
    treePrj.unselect();
    Waits.prjExistOnTree(oldName);
    // 选择项目并重命名
    treePrj.select(oldName);
    switch(from) {
        case CONTEXT_MENU:
            {
                viewPrjTree.ctxMenuRename().click();
                break;
            }
        case SHORTCUT:
            {
                treePrj.pressShortcut(Keystrokes.F2);
                break;
            }
        default:
            {
                assertTrue("错误的入口参数:" + from, false);
            }
    }
    // 进入重命名状态
    SWTBotText txtPrjName = viewPrjTree.bot().text(oldName);
    // 输入新名称并回车确认
    txtPrjName.typeText(newName + "\n");
    // 不同步的问题暂不考虑——若要解决,思路是判断是否出现不同步的信息,若有则刷新后重试重命名,直到达到最大重试次数后放弃。
    if (HSBot.bot().shells().length > 1) {
        // FIXME: 可能需要修改这种判断方式,试试 activeShell()?
        Waits.progressFinished();
        String title = HSBot.bot().activeShell().getText();
        String errMsg = "重命名出错。对话框标题:" + title;
        switch(expectedResult) {
            case SUCCESS:
                {
                    // 验证结果
                    assertRenamed(oldName, newName);
                    break;
                }
            case INVALID_NAME:
                {
                    if (title.equals(TsUIConstants.getString("dlgTitleRenameProblems"))) {
                        RenameProblemsDialog rpd = new RenameProblemsDialog(newName, invalidChar);
                        assertTrue("未正确显示项目名非法的信息。", rpd.isInvalidMsgVisible());
                        assertTrue(rpd.btnOK().isEnabled());
                        rpd.btnOK().click();
                        Waits.shellClosed(rpd);
                        assertNotRenamed(oldName, newName);
                    } else {
                        assertTrue(errMsg, false);
                    }
                    break;
                }
            case DUPLICATED_NAME:
                {
                    if (title.equals(TsUIConstants.getString("dlgTitleProjectExists"))) {
                        ProjectExistsDialog ped = new ProjectExistsDialog(newName);
                        assertTrue("未正确显示项目名称已存在的信息。", ped.isProjectExistsMsgVisible());
                        assertTrue(ped.btnYes().isEnabled());
                        assertTrue(ped.btnNo().isEnabled());
                        if (overwrite) {
                            ped.btnYes().click();
                            Waits.shellClosed(ped);
                            Waits.progressFinished();
                            assertRenamed(oldName, newName);
                        } else {
                            ped.btnNo().click();
                            Waits.shellClosed(ped);
                            Waits.progressFinished();
                            assertNotOverwritten(oldName, newName);
                        }
                    } else {
                        assertTrue(errMsg, false);
                    }
                    break;
                }
            default:
                {
                    assertTrue(errMsg, false);
                }
        }
    } else {
        // 重命名正常,验证结果
        assertRenamed(oldName, newName);
    }
}
Also used : RenameProblemsDialog(net.heartsome.cat.ts.test.ui.dialogs.RenameProblemsDialog) ProjectExistsDialog(net.heartsome.cat.ts.test.ui.dialogs.ProjectExistsDialog) SWTBotText(org.eclipse.swtbot.swt.finder.widgets.SWTBotText)

Aggregations

ProjectExistsDialog (net.heartsome.cat.ts.test.ui.dialogs.ProjectExistsDialog)1 RenameProblemsDialog (net.heartsome.cat.ts.test.ui.dialogs.RenameProblemsDialog)1 SWTBotText (org.eclipse.swtbot.swt.finder.widgets.SWTBotText)1