From 1ed4b23dab59715edfd9aa1c53660cbb1348a81b Mon Sep 17 00:00:00 2001 From: lucian Date: Wed, 11 Dec 2019 14:18:06 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-24826=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E6=97=B6=E7=82=B9=E5=87=BB=E4=BA=A7=E5=93=81=E6=BC=94?= =?UTF-8?q?=E7=A4=BA=EF=BC=8C=E8=BF=9C=E7=A8=8B=E8=AE=BE=E8=AE=A1=E6=96=AD?= =?UTF-8?q?=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/toolbar/ToolBarMenuDock.java | 4 +- .../toolbar/ToolBarMenuDockTest.java | 129 ++++++++++++++++++ 2 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 designer-base/src/test/java/com/fr/design/mainfarme/toolbar/ToolBarMenuDockTest.java diff --git a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java index d916d967f..cdafa8c41 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java @@ -528,14 +528,14 @@ public abstract class ToolBarMenuDock { */ public ShortCut[] createHelpShortCuts() { final java.util.List shortCuts = new ArrayList(); - shortCuts.add(new WebDemoAction()); // 英文,把 video 和帮助文档放到 Help 下面 if (GeneralContext.getLocale().equals(Locale.US)) { shortCuts.add(new VideoAction()); shortCuts.add(new TutorialAction()); } - //远程不使用更新升级 + //远程不使用更新升级,产品演示 if (WorkContext.getCurrent().isLocal()) { + shortCuts.add(new WebDemoAction()); shortCuts.add(new SoftwareUpdateAction()); } if (AlphaFineConfigManager.isALPHALicAvailable()) { diff --git a/designer-base/src/test/java/com/fr/design/mainfarme/toolbar/ToolBarMenuDockTest.java b/designer-base/src/test/java/com/fr/design/mainfarme/toolbar/ToolBarMenuDockTest.java new file mode 100644 index 000000000..c5f9f0a70 --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/mainfarme/toolbar/ToolBarMenuDockTest.java @@ -0,0 +1,129 @@ +package com.fr.design.mainfarme.toolbar; + +import java.util.Locale; + +import com.fr.design.DesignerEnvManager; +import com.fr.design.actions.community.VideoAction; +import com.fr.design.actions.help.AboutAction; +import com.fr.design.actions.help.FineUIAction; +import com.fr.design.actions.help.TutorialAction; +import com.fr.design.actions.help.WebDemoAction; +import com.fr.design.actions.help.alphafine.AlphaFineAction; +import com.fr.design.actions.help.alphafine.AlphaFineConfigManager; +import com.fr.design.mainframe.toolbar.ToolBarMenuDock; +import com.fr.design.menu.SeparatorDef; +import com.fr.design.menu.ShortCut; +import com.fr.design.os.impl.SupportOSImpl; +import com.fr.design.update.actions.SoftwareUpdateAction; +import com.fr.general.GeneralContext; +import com.fr.workspace.WorkContext; +import com.fr.workspace.Workspace; +import org.easymock.EasyMock; +import org.easymock.Mock; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.reflect.Whitebox; + + +/** + * @author Lucian.Chen + * @version 10.0 + * Created by Lucian.Chen on 2019/12/11 + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({ + ToolBarMenuDock.class, + GeneralContext.class, + Locale.class, + WorkContext.class, + DesignerEnvManager.class, + AlphaFineConfigManager.class}) +public class ToolBarMenuDockTest { + + @Mock + VideoAction videoAction; + @Mock + TutorialAction tutorialAction; + @Mock + WebDemoAction webDemoAction; + @Mock + SoftwareUpdateAction softwareUpdateAction; + @Mock + AlphaFineAction alphaFineAction; + @Mock + FineUIAction fineUIAction; + @Mock + AboutAction aboutAction; + + @Before + public void testCreateHelpShortCutsBefore() { + try { + PowerMock.expectNew(VideoAction.class).andReturn(videoAction).anyTimes(); + PowerMock.expectNew(TutorialAction.class).andReturn(tutorialAction).anyTimes(); + PowerMock.expectNew(WebDemoAction.class).andReturn(webDemoAction).anyTimes(); + PowerMock.expectNew(SoftwareUpdateAction.class).andReturn(softwareUpdateAction).anyTimes(); + PowerMock.expectNew(AlphaFineAction.class).andReturn(alphaFineAction).anyTimes(); + PowerMock.expectNew(FineUIAction.class).andReturn(fineUIAction).anyTimes(); + PowerMock.expectNew(AboutAction.class).andReturn(aboutAction).anyTimes(); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testCreateHelpShortCuts() { + + // 处理判断条件 + GeneralContext context = EasyMock.createMock(GeneralContext.class); + PowerMock.mockStatic(GeneralContext.class); + EasyMock.expect(GeneralContext.getLocale()).andReturn(Locale.CHINA).once(); + EasyMock.expect(GeneralContext.getLocale()).andReturn(Locale.US).once(); + + Workspace workspace = EasyMock.createMock(Workspace.class); + PowerMock.mockStatic(WorkContext.class); + EasyMock.expect(WorkContext.getCurrent()).andReturn(workspace).anyTimes(); + + EasyMock.expect(workspace.isLocal()).andReturn(false).once(); + EasyMock.expect(workspace.isLocal()).andReturn(true).once(); + + DesignerEnvManager envManager = EasyMock.createMock(DesignerEnvManager.class); + PowerMock.mockStatic(DesignerEnvManager.class); + EasyMock.expect(DesignerEnvManager.getEnvManager()).andReturn(envManager).anyTimes(); + + EasyMock.expect(envManager.isOpenDebug()).andReturn(false).once(); + EasyMock.expect(envManager.isOpenDebug()).andReturn(true).once(); + + AlphaFineConfigManager configManager = EasyMock.createMock(AlphaFineConfigManager.class); + PowerMock.mockStatic(AlphaFineConfigManager.class); + EasyMock.expect(AlphaFineConfigManager.isALPHALicAvailable()).andReturn(false).once(); + EasyMock.expect(AlphaFineConfigManager.isALPHALicAvailable()).andReturn(true).once(); + + SupportOSImpl osImpl = EasyMock.createMock(SupportOSImpl.class); + Whitebox.setInternalState(SupportOSImpl.class, "FINEUI", osImpl); + EasyMock.expect(osImpl.support()).andReturn(false).anyTimes(); + + EasyMock.replay(context, workspace, envManager, configManager, osImpl); + PowerMock.replayAll(); + + + ToolBarMenuDock menuDock = new ToolBarMenuDock() { + @Override + public ShortCut[] createNewFileShortCuts() { + return new ShortCut[0]; + } + }; + + ShortCut[] shortCuts1 = new ShortCut[] {SeparatorDef.DEFAULT, aboutAction}; + ShortCut[] shortCuts2 = new ShortCut[] {videoAction, tutorialAction, webDemoAction, + softwareUpdateAction, alphaFineAction, SeparatorDef.DEFAULT, aboutAction}; + + Assert.assertEquals(menuDock.createHelpShortCuts(), shortCuts1); + Assert.assertEquals(menuDock.createHelpShortCuts(), shortCuts2); + + } +}