Skip to content

Commit

Permalink
Add default settings to Build Monitor Views (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcendents authored Feb 15, 2022
1 parent 05e851a commit d9a599c
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks;

import com.smartcodeltd.jenkinsci.plugins.build_monitor.user_interface.BuildMonitorDashboard;

import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.UncheckCheckbox;
import net.serenitybdd.screenplay.waits.WaitUntil;
import net.thucydides.core.annotations.Step;

import static net.serenitybdd.screenplay.Tasks.instrumented;
import static net.serenitybdd.screenplay.matchers.WebElementStateMatchers.isVisible;

public class HideBadges implements Task {
public static Task onTheDashboard() {
return instrumented(HideBadges.class);
}

@Step("{0} decides to hide the badges on the dashboard")
@Override
public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(
WaitUntil.the(BuildMonitorDashboard.Show_Badges, isVisible()),
UncheckCheckbox.of(BuildMonitorDashboard.Show_Badges)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Click;
import net.serenitybdd.screenplay.actions.CheckCheckbox;
import net.serenitybdd.screenplay.waits.WaitUntil;
import net.thucydides.core.annotations.Step;

Expand All @@ -21,7 +21,7 @@ public static Task onTheDashboard() {
public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(
WaitUntil.the(BuildMonitorDashboard.Show_Badges, isVisible()),
Click.on(BuildMonitorDashboard.Show_Badges)
CheckCheckbox.of(BuildMonitorDashboard.Show_Badges)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.configuration;

import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.CheckCheckbox;
import net.serenitybdd.screenplay.actions.Enter;
import net.serenitybdd.screenplay.actions.UncheckCheckbox;
import net.serenitybdd.screenplay.jenkins.user_interface.ViewConfigurationPage;
import net.serenitybdd.screenplay.targets.Target;
import net.serenitybdd.screenplayx.actions.Scroll;
import net.thucydides.core.annotations.Step;

import static net.serenitybdd.screenplay.Tasks.instrumented;

public class ConfigureViewSettings implements Task {

public static Task showBadges() {
return instrumented(ConfigureViewSettings.class, ViewConfigurationPage.Enable_Show_Badges, true);
}

public static Task doNotShowBadges() {
return instrumented(ConfigureViewSettings.class, ViewConfigurationPage.Enable_Show_Badges, false);
}

@Step("{0} configures the view settings")
@Override
public <T extends Actor> void performAs(T actor) {
if (value instanceof Boolean) {
actor.attemptsTo(
Scroll.to(target),
((Boolean) value).booleanValue() ? CheckCheckbox.of(target) : UncheckCheckbox.of(target)
);
} else {
actor.attemptsTo(
Scroll.to(target),
Enter.theValue(value.toString()).into(target)
);
}
}

public ConfigureViewSettings(Target target, Object value) {
this.target = target;
this.value = value;
}

private final Target target;
private final Object value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.jenkins.actions.Choose;
import net.serenitybdd.screenplay.actions.CheckCheckbox;
import net.serenitybdd.screenplay.jenkins.user_interface.ViewConfigurationPage;
import net.serenitybdd.screenplayx.actions.Scroll;
import net.thucydides.core.annotations.Step;
Expand All @@ -19,7 +19,7 @@ public static Task bars() {
public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(
Scroll.to(ViewConfigurationPage.Display_JUnit_Realtime_Progress),
Choose.the(ViewConfigurationPage.Display_JUnit_Realtime_Progress)
CheckCheckbox.of(ViewConfigurationPage.Display_JUnit_Realtime_Progress)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class ViewConfigurationPage {
public static final Target Recurse_In_Subfolders = Target.the("the 'Recurse in subfolders' option").locatedBy("#recurse");
public static final Target Use_Regular_Expression = Checkbox.withLabel("Use a regular expression to include jobs into the view");
public static final Target Regular_Expression = Target.the("the 'Regular expression' field").located(By.name("includeRegex"));
public static final Target Enable_Show_Badges = Target.the("the 'Enable Show badges' option").locatedBy("#showBadges");
public static final Target Display_Badges = Target.the("the 'Display badges' field").located(By.name("displayBadges"));
public static final Target Display_Badges_From = Target.the("the 'Display badges from' field").located(By.name("displayBadgesFrom"));
public static final Target Display_JUnit_Realtime_Progress = Target.the("the 'Display JUnit Realtime progress' option").locatedBy("#displayJUnitProgress");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.smartcodeltd.jenkinsci.plugins.build_monitor.questions.ProjectWidget;
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.CreateABuildMonitorView;
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.HideBadges;
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.ModifyControlPanelOptions;
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.ShowBadges;
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.configuration.ConfigureViewSettings;
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.configuration.DisplayAllProjects;
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.configuration.DisplayBadges;
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.configuration.DisplayBadgesFrom;
Expand Down Expand Up @@ -66,6 +68,7 @@ public void user_displaying_build_badges() {
ScheduleABuild.of("My App"),
CreateABuildMonitorView.called("Build Monitor").andConfigureItTo(
DisplayAllProjects.usingARegularExpression(),
ConfigureViewSettings.doNotShowBadges(),
DisplayBadges.asAUserSetting(),
DisplayBadgesFrom.theLastBuild()
)
Expand All @@ -85,14 +88,16 @@ public void always_displaying_build_badges() {
HaveAPipelineProjectCreated.called("My App").andConfiguredTo(
SetPipelineDefinition.asFollows(Adds_A_Badge.code())
),
ScheduleABuild.of("My App")
ScheduleABuild.of("My App"),
CreateABuildMonitorView.called("Build Monitor").andConfigureItTo(
DisplayAllProjects.usingARegularExpression(),
ConfigureViewSettings.showBadges(),
DisplayBadges.always(),
DisplayBadgesFrom.theLastBuild()
)
);

when(paul).attemptsTo(CreateABuildMonitorView.called("Build Monitor").andConfigureItTo(
DisplayAllProjects.usingARegularExpression(),
DisplayBadges.always(),
DisplayBadgesFrom.theLastBuild()
));
when(paul).attemptsTo(ModifyControlPanelOptions.to(HideBadges.onTheDashboard()));

then(paul).should(seeThat(ProjectWidget.of("My App").badges(),
isCurrentlyVisible()
Expand All @@ -109,6 +114,7 @@ public void never_displaying_build_badges() {
ScheduleABuild.of("My App"),
CreateABuildMonitorView.called("Build Monitor").andConfigureItTo(
DisplayAllProjects.usingARegularExpression(),
ConfigureViewSettings.doNotShowBadges(),
DisplayBadges.never(),
DisplayBadgesFrom.theLastBuild()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,34 @@ public boolean getPermissionToCollectAnonymousUsageStatistics() {
public void setPermissionToCollectAnonymousUsageStatistics(boolean collect) {
this.permissionToCollectAnonymousUsageStatistics = collect;
}

public FormValidation doCheckMaxColumns(@QueryParameter String value) {
try {
int intValue = Integer.parseInt(value);
if(intValue > 0) {
return FormValidation.ok();
} else {
return FormValidation.error("Must be an integer, greater than 0.");
}
} catch (NullPointerException npe) {
return FormValidation.error("Cannot be null.");
} catch (NumberFormatException nfe) {
return FormValidation.error("Must be an integer.");
}
}

public FormValidation doCheckTextScale(@QueryParameter String value) {
try {
double doubleValue = Double.parseDouble(value);
if(doubleValue > 0.0) {
return FormValidation.ok();
} else {
return FormValidation.error("Must be a double, greater than 0.0.");
}
} catch (NullPointerException npe) {
return FormValidation.error("Cannot be null.");
} catch (NumberFormatException nfe) {
return FormValidation.error("Must be a double.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,36 @@ public boolean isDisplayCommitters() {
return currentConfig().shouldDisplayCommitters();
}

// used in the configure-entries.jelly and main-settings.jelly forms
@SuppressWarnings("unused")
public double getTextScale() {
return currentConfig().getTextScale();
}

// used in the configure-entries.jelly and main-settings.jelly forms
@SuppressWarnings("unused")
public int getMaxColumns() {
return currentConfig().getMaxColumns();
}

// used in the configure-entries.jelly and main-settings.jelly forms
@SuppressWarnings("unused")
public boolean isColourBlindMode() {
return currentConfig().colourBlindMode();
}

// used in the configure-entries.jelly and main-settings.jelly forms
@SuppressWarnings("unused")
public boolean isReduceMotion() {
return currentConfig().reduceMotion();
}

// used in the configure-entries.jelly and main-settings.jelly forms
@SuppressWarnings("unused")
public boolean isShowBadges() {
return currentConfig().showBadges();
}

@SuppressWarnings("unused") // used in the configure-entries.jelly form
public String currentDisplayBadges() {
return currentConfig().getDisplayBadges().name();
Expand Down Expand Up @@ -138,7 +168,12 @@ protected void submit(StaplerRequest req) throws ServletException, IOException,
String requestedOrdering = req.getParameter("order");
String displayBadgesFrom = req.getParameter("displayBadgesFrom");
title = req.getParameter("title");
String maxColumns = req.getParameter("maxColumns");
String textScale = req.getParameter("textScale");

currentConfig().setColourBlindMode(json.optBoolean("colourBlindMode", false));
currentConfig().setReduceMotion(json.optBoolean("reduceMotion", false));
currentConfig().setShowBadges(json.optBoolean("showBadges", true));
currentConfig().setDisplayBadges(req.getParameter("displayBadges"));
currentConfig().setDisplayCommitters(json.optBoolean("displayCommitters", true));
currentConfig().setBuildFailureAnalyzerDisplayedField(req.getParameter("buildFailureAnalyzerDisplayedField"));
Expand All @@ -150,6 +185,18 @@ protected void submit(StaplerRequest req) throws ServletException, IOException,
throw new FormException("Can't order projects by " + requestedOrdering, "order");
}

try {
currentConfig().setMaxColumns(Integer.parseInt(maxColumns));
} catch (Exception e) {
throw new FormException("Invalid value of 'Maximum number of columns': '" + maxColumns + "' (should be double).", maxColumns);
}

try {
currentConfig().setTextScale(Double.parseDouble(textScale));
} catch (Exception e) {
throw new FormException("Invalid value of 'Text scale': '" + textScale + "' (should be double).", textScale);
}

try {
currentConfig().setDisplayBadgesFrom(getBuildViewModelIn(displayBadgesFrom));
} catch (Exception e) {
Expand Down Expand Up @@ -178,13 +225,13 @@ private List<JobView> jobViews() {
JobViews views = new JobViews(new StaticJenkinsAPIs(), currentConfig());

//A little bit of evil to make the type system happy.
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
List<Job<?, ?>> projects = new ArrayList(filter(super.getItems(), Job.class));
List<JobView> jobs = new ArrayList<>();

projects.sort(currentConfig().getOrder());

for (Job project : projects) {
for (Job<?, ?> project : projects) {
jobs.add(views.viewOf(project));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@

public class Config {

private boolean displayCommitters;
private Boolean colourBlindMode;
private Boolean displayCommitters;
private Boolean reduceMotion;
private Integer maxColumns;
private Double textScale;
private Boolean showBadges;
private DisplayOptions displayBadges;
private GetBuildViewModel displayBadgesFrom;
private BuildFailureAnalyzerDisplayedField buildFailureAnalyzerDisplayedField;
private boolean displayJUnitProgress;
private Boolean displayJUnitProgress;

public static Config defaultConfig() {
return new Config();
Expand Down Expand Up @@ -43,6 +48,14 @@ public BuildFailureAnalyzerDisplayedField getBuildFailureAnalyzerDisplayedField(
public void setBuildFailureAnalyzerDisplayedField(String buildFailureAnalyzerDisplayedField) {
this.buildFailureAnalyzerDisplayedField = BuildFailureAnalyzerDisplayedField.valueOf(buildFailureAnalyzerDisplayedField);
}

public boolean colourBlindMode() {
return Optional.ofNullable(colourBlindMode).orElse(false);
}

public void setColourBlindMode(boolean flag) {
this.colourBlindMode = flag;
}

public boolean shouldDisplayCommitters() {
return Optional.ofNullable(displayCommitters).orElse(true);
Expand All @@ -51,6 +64,22 @@ public boolean shouldDisplayCommitters() {
public void setDisplayCommitters(boolean flag) {
this.displayCommitters = flag;
}

public boolean reduceMotion() {
return Optional.ofNullable(reduceMotion).orElse(false);
}

public void setReduceMotion(boolean flag) {
this.reduceMotion = flag;
}

public boolean showBadges() {
return Optional.ofNullable(showBadges).orElse(true);
}

public void setShowBadges(boolean flag) {
this.showBadges = flag;
}

public DisplayOptions getDisplayBadges() {
return Optional.ofNullable(displayBadges).orElse(DisplayOptions.UserSetting);
Expand All @@ -69,13 +98,29 @@ public void setDisplayBadgesFrom(GetBuildViewModel displayBadgesFrom) {
}

public boolean shouldDisplayJUnitProgress() {
return Optional.of(displayJUnitProgress).orElse(true);
return Optional.ofNullable(displayJUnitProgress).orElse(true);
}

public void setDisplayJUnitProgress(boolean flag) {
this.displayJUnitProgress = flag;
}

public int getMaxColumns() {
return Optional.ofNullable(maxColumns).orElse(2);
}

public void setMaxColumns(int maxColumns) {
this.maxColumns = maxColumns;
}

public double getTextScale() {
return Optional.ofNullable(textScale).orElse(1.0);
}

public void setTextScale(double scale) {
this.textScale = scale;
}

@Override
public String toString() {
return String.format("Config{order=%s}", order.getClass().getSimpleName());
Expand Down
Loading

0 comments on commit d9a599c

Please sign in to comment.