Skip to content

Commit

Permalink
Fixed Wizard startup with initial selection but without install page
Browse files Browse the repository at this point in the history
Also fixed all UI tests (at least locally)

Change-Id: Iabc2d05febf3adee3d795a46540f6451dac5da95
  • Loading branch information
creckord committed Sep 1, 2020
1 parent 0d85629 commit 89f7cc9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
Expand Up @@ -12,10 +12,10 @@
*******************************************************************************/
package org.eclipse.epp.mpc.tests.ui.wizard;

import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -64,6 +64,7 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
Expand All @@ -73,6 +74,7 @@
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.junit.ScreenshotCaptureListener;
import org.eclipse.swtbot.swt.finder.matchers.WithRegex;
import org.eclipse.swtbot.swt.finder.results.ArrayResult;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferenceConstants;
Expand Down Expand Up @@ -469,7 +471,8 @@ protected SWTBotText searchField() {

protected SWTBotBrowser marketplaceBrowser() {
SWTWorkbenchBot wbBot = new SWTWorkbenchBot();
Matcher<IEditorReference> marketplaceBrowserMatch = allOf(WidgetMatcherFactory.<IEditorReference> withPartId("org.eclipse.ui.browser.editor"), WidgetMatcherFactory
Matcher<IEditorReference> marketplaceBrowserMatch = Matchers.allOf(WidgetMatcherFactory
.<IEditorReference> withPartId("org.eclipse.ui.browser.editor"), WidgetMatcherFactory
.<IEditorReference> withTitle(containsString("Marketplace")));
SWTBotEditor browserEditor = wbBot.editor(marketplaceBrowserMatch);
SWTBotBrowser browser = browserEditor.bot().browser();
Expand Down Expand Up @@ -598,7 +601,9 @@ protected SWTBotLink selectedSolutionsLink(int count) {
linkText = String.format("%s solutions selected", count);
}
String linkContent = String.format("<a href=\"showSelection\">%s</a>", linkText);
return bot.link(linkContent);

Matcher<Link> matcher = allOf(widgetOfType(Link.class), WithRegex.withRegex("\\Q" + linkContent + "\\E"));
return new SWTBotLink(bot.widget(matcher, 0), matcher);
}

protected void tryWaitForBrowser(SWTBotBrowser browser) {
Expand Down
Expand Up @@ -13,9 +13,14 @@
*******************************************************************************/
package org.eclipse.epp.mpc.tests.ui.wizard;

import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.*;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withId;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withText;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.List;

Expand Down Expand Up @@ -66,6 +71,7 @@ public void testSearch() {
itemBot(NodeMatcher.withNameRegex(".*Snipmatch.*"));
}

@Ignore //Tags are currently disabled in the REST API
@Test
public void testSearchTag() {
Matcher<StyledText> widgetOfType = widgetOfType(StyledText.class);
Expand Down Expand Up @@ -170,7 +176,7 @@ private void checkMarketplaceBrowser() {

@Test
public void testNews() {
bot.tabItemWithId(MarketplacePage.WIDGET_ID_KEY, MarketplacePage.WIDGET_ID_TAB_NEWS).activate();
bot.cTabItemWithId(MarketplacePage.WIDGET_ID_KEY, MarketplacePage.WIDGET_ID_TAB_NEWS).activate();
bot.sleep(500);
tryWaitForBrowser(bot.browser());
String url = bot.browser().getUrl();
Expand All @@ -179,21 +185,24 @@ public void testNews() {

@Test
public void testRecentBackToSearch() {
bot.tabItem("Recent").activate();
bot.cTabItem("Recent").activate();
waitForWizardProgress();
testSearchTag();
bot.cTabItem("Search").activate();
waitForWizardProgress();
searchField();
assertTrue(bot.label("Featured").isVisible());
}

@Test
public void testRecent() {
bot.tabItem("Recent").activate();
bot.cTabItem("Recent").activate();
waitForWizardProgress();
//TODO test something useful
}

@Test
public void testPopular() {
bot.tabItem("Popular").activate();
bot.cTabItem("Popular").activate();
waitForWizardProgress();
//TODO test something useful
}
Expand Down
Expand Up @@ -280,7 +280,8 @@ public void selectionChanged(SelectionChangedEvent event) {
if (!event.getSelection().isEmpty()) {

if (previousSelectionSize == 0 && newSelectionSize > 0
&& selectionModel.computeProvisioningOperationViableForFeatureSelection()) {
&& selectionModel.computeProvisioningOperationViableForFeatureSelection()
&& getWizard().canProceedInstallation()) {
showNextPage();
}
}
Expand Down
Expand Up @@ -214,6 +214,7 @@ public void setProceedWithInstallation(Boolean proceedWithInstallation) {

private Set<CatalogItem> operationNewInstallItems;

private boolean inInitialSelectionInitializer;
private boolean initialSelectionInitialized;

private Set<URI> addedRepositoryLocations;
Expand Down Expand Up @@ -282,21 +283,27 @@ void initializeInitialSelection() throws CoreException {
throw new IllegalStateException();
}
initialSelectionInitialized = true;
initializeCatalog();
if (getConfiguration().getInitialState() != null || getConfiguration().getInitialOperations() != null) {
SelectionModelStateSerializer serializer = new SelectionModelStateSerializer(getCatalog(),
getSelectionModel());
try {
getContainer().run(true, true,
monitor -> serializer.deserialize(getConfiguration().getInitialState(),
getConfiguration().getInitialOperations(), monitor));
} catch (InvocationTargetException e) {
throw new CoreException(MarketplaceClientCore.computeStatus(e, Messages.MarketplaceViewer_unexpectedException));
} catch (InterruptedException e) {
// user canceled
throw new CoreException(Status.CANCEL_STATUS);
inInitialSelectionInitializer = true;
try {
initializeCatalog();
if (getConfiguration().getInitialState() != null || getConfiguration().getInitialOperations() != null) {
SelectionModelStateSerializer serializer = new SelectionModelStateSerializer(getCatalog(),
getSelectionModel());
try {
getContainer().run(true, true,
monitor -> serializer.deserialize(getConfiguration().getInitialState(),
getConfiguration().getInitialOperations(), monitor));
} catch (InvocationTargetException e) {
throw new CoreException(
MarketplaceClientCore.computeStatus(e, Messages.MarketplaceViewer_unexpectedException));
} catch (InterruptedException e) {
// user canceled
throw new CoreException(Status.CANCEL_STATUS);
}
updateSelection(serializer);
}
updateSelection(serializer);
} finally {
inInitialSelectionInitializer = false;
}
}

Expand Down Expand Up @@ -1253,4 +1260,9 @@ public static void resumeWizard(Display display, Object state, boolean proceedWi
IProvisioningPlan getAdditionalVerificationPlan() {
return this.currentJREPlan;
}

protected boolean canProceedInstallation() {
return !inInitialSelectionInitializer || getInitialState() == null
|| !Boolean.FALSE.equals(getInitialState().getProceedWithInstallation());
}
}

0 comments on commit 89f7cc9

Please sign in to comment.