From 70c4fe1571269b3c36d06a9ca2ee3e81f8c02b8c Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 9 Nov 2021 16:47:39 +0100 Subject: [PATCH 1/2] added test id attributes --- .../seb/sebserver/gui/table/TableFilter.java | 17 +++-- .../sebserver/gui/widget/ColorSelection.java | 4 + .../sebserver/gui/widget/MultiSelection.java | 5 +- .../gui/widget/MultiSelectionCheckbox.java | 24 +++--- .../gui/widget/MultiSelectionCombo.java | 2 +- .../sebserver/gui/widget/RadioSelection.java | 6 +- .../sebserver/gui/widget/SingleSelection.java | 5 +- .../sebserver/gui/widget/WidgetFactory.java | 76 +++++++++++++------ 8 files changed, 94 insertions(+), 45 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/table/TableFilter.java b/src/main/java/ch/ethz/seb/sebserver/gui/table/TableFilter.java index ff8dfdd5..7b81ef05 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/table/TableFilter.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/table/TableFilter.java @@ -323,6 +323,7 @@ public class TableFilter { this.textInput = TableFilter.this.entityTable.widgetFactory.textInput( innerComposite, + TableFilter.this.entityTable.getName() + "_" + this.attribute.columnName, super.attribute.columnName); this.textInput.setLayoutData(gridData); return this; @@ -375,7 +376,8 @@ public class TableFilter { .selectionLocalized( ch.ethz.seb.sebserver.gui.widget.Selection.Type.SINGLE, innerComposite, - resourceSupplier); + resourceSupplier, + TableFilter.this.entityTable.getName() + "_" + this.attribute.columnName); this.selector .adaptToControl() @@ -429,7 +431,9 @@ public class TableFilter { @Override FilterComponent build(final Composite parent) { final Composite innerComposite = createInnerComposite(parent); - this.selector = TableFilter.this.entityTable.widgetFactory.dateSelector(innerComposite); + this.selector = TableFilter.this.entityTable.widgetFactory.dateSelector( + innerComposite, + TableFilter.this.entityTable.getName() + "_" + this.attribute.columnName); return this; } @@ -520,17 +524,18 @@ public class TableFilter { this.innerComposite.setLayout(gridLayout); this.innerComposite.setLayoutData(this.rowData); + final String testKey = TableFilter.this.entityTable.getName() + "_" + this.attribute.columnName; final WidgetFactory wf = TableFilter.this.entityTable.widgetFactory; wf.labelLocalized(this.innerComposite, DATE_FROM_TEXT); - this.fromDateSelector = wf.dateSelector(this.innerComposite); + this.fromDateSelector = wf.dateSelector(this.innerComposite, testKey); if (this.withTime) { - this.fromTimeSelector = wf.timeSelector(this.innerComposite); + this.fromTimeSelector = wf.timeSelector(this.innerComposite, testKey); } wf.labelLocalized(this.innerComposite, DATE_TO_TEXT); - this.toDateSelector = wf.dateSelector(this.innerComposite); + this.toDateSelector = wf.dateSelector(this.innerComposite, testKey); if (this.withTime) { - this.toTimeSelector = wf.timeSelector(this.innerComposite); + this.toTimeSelector = wf.timeSelector(this.innerComposite, testKey); } return this; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java index d49479e6..1bbaf4cd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java @@ -95,6 +95,10 @@ public final class ColorSelection extends Composite implements Selection { actionCell.widthHint = ACTION_COLUMN_WIDTH; imageButton.setLayoutData(actionCell); + if (tooltipKeyPrefix != null) { + WidgetFactory.setTestId(this, tooltipKeyPrefix); + } + this.addListener(SWT.Resize, this::adaptColumnWidth); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelection.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelection.java index c464b904..1e9444a1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelection.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelection.java @@ -36,7 +36,7 @@ public final class MultiSelection extends Composite implements Selection { private Listener listener = null; - MultiSelection(final Composite parent) { + MultiSelection(final Composite parent, final String testKey) { super(parent, SWT.NONE); final GridLayout gridLayout = new GridLayout(1, true); gridLayout.verticalSpacing = 1; @@ -44,6 +44,9 @@ public final class MultiSelection extends Composite implements Selection { gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; setLayout(gridLayout); + if (testKey != null) { + WidgetFactory.setTestId(this, testKey); + } } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCheckbox.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCheckbox.java index b4d25663..90e770fe 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCheckbox.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCheckbox.java @@ -8,11 +8,11 @@ package ch.ethz.seb.sebserver.gui.widget; -import ch.ethz.seb.sebserver.gbl.Constants; -import ch.ethz.seb.sebserver.gbl.util.Tuple; -import ch.ethz.seb.sebserver.gbl.util.Tuple3; -import ch.ethz.seb.sebserver.gbl.util.Utils; -import ch.ethz.seb.sebserver.gui.service.page.PageService; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + import org.apache.commons.lang3.StringUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -21,10 +21,11 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Listener; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import ch.ethz.seb.sebserver.gbl.Constants; +import ch.ethz.seb.sebserver.gbl.util.Tuple; +import ch.ethz.seb.sebserver.gbl.util.Tuple3; +import ch.ethz.seb.sebserver.gbl.util.Utils; +import ch.ethz.seb.sebserver.gui.service.page.PageService; public final class MultiSelectionCheckbox extends Composite implements Selection { @@ -33,7 +34,7 @@ public final class MultiSelectionCheckbox extends Composite implements Selection private Listener listener = null; private final Map checkboxes; - MultiSelectionCheckbox(final Composite parent) { + MultiSelectionCheckbox(final Composite parent, final String testKey) { super(parent, SWT.NONE); final GridLayout gridLayout = new GridLayout(1, true); gridLayout.verticalSpacing = 1; @@ -41,6 +42,9 @@ public final class MultiSelectionCheckbox extends Composite implements Selection gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; setLayout(gridLayout); + if (testKey != null) { + WidgetFactory.setTestId(this, testKey); + } this.checkboxes = new LinkedHashMap<>(); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java index 4f1628b8..fd65a4fa 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java @@ -69,7 +69,7 @@ public final class MultiSelectionCombo extends Composite implements Selection { setLayout(gridLayout); this.addListener(SWT.Resize, this::adaptColumnWidth); - this.textInput = widgetFactory.textInput(this, "selection"); + this.textInput = widgetFactory.textInput(this, locTextPrefix, "selection"); this.textCell = new GridData(SWT.LEFT, SWT.CENTER, true, true); this.textInput.setLayoutData(this.textCell); this.dropDown = new DropDown(this.textInput, SWT.NONE); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/RadioSelection.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/RadioSelection.java index db0f9204..e9c419e6 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/RadioSelection.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/RadioSelection.java @@ -31,7 +31,7 @@ public final class RadioSelection extends Composite implements Selection { private Listener listener = null; private final Map radioButtons; - RadioSelection(final Composite parent) { + RadioSelection(final Composite parent, final String testKey) { super(parent, SWT.NONE); final GridLayout gridLayout = new GridLayout(1, true); gridLayout.verticalSpacing = 1; @@ -39,6 +39,9 @@ public final class RadioSelection extends Composite implements Selection { gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; setLayout(gridLayout); + if (testKey != null) { + WidgetFactory.setTestId(this, testKey); + } this.radioButtons = new LinkedHashMap<>(); } @@ -65,6 +68,7 @@ public final class RadioSelection extends Composite implements Selection { this.listener.handleEvent(event); } }); + WidgetFactory.setTestId(button, tuple._1); this.radioButtons.put(tuple._1, button); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/SingleSelection.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/SingleSelection.java index d9eb875e..aa5d1196 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/SingleSelection.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/SingleSelection.java @@ -29,11 +29,14 @@ public final class SingleSelection extends Combo implements Selection { final List keyMapping; final boolean isEditable; - SingleSelection(final Composite parent, final int type) { + SingleSelection(final Composite parent, final int type, final String testKey) { super(parent, type); this.valueMapping = new ArrayList<>(); this.keyMapping = new ArrayList<>(); this.isEditable = type == SWT.NONE; + if (testKey != null) { + WidgetFactory.setTestId(this, testKey); + } } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java index b60d9732..540e3cb3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java @@ -67,11 +67,12 @@ import ch.ethz.seb.sebserver.gui.service.push.ServerPushService; public class WidgetFactory { private static final String ADD_HTML_ATTR_ARIA_ROLE = "role"; - private static final String ADD_HTML_ATTR_TEST_ID = "test-id"; + private static final String ADD_HTML_ATTR_TEST_ID = "data-test"; private static final String SUB_TITLE_TExT_SUFFIX = ".subtitle"; public enum AriaRole { - link + link, + button, } private static final Logger log = LoggerFactory.getLogger(WidgetFactory.class); @@ -367,21 +368,24 @@ public class WidgetFactory { public Button buttonLocalized(final Composite parent, final String locTextKey) { final Button button = new Button(parent, SWT.NONE); - setAttribute(button, "role", "button"); + setARIARole(button, AriaRole.button); + setTestId(button, locTextKey); this.polyglotPageService.injectI18n(button, new LocTextKey(locTextKey)); return button; } public Button buttonLocalized(final Composite parent, final LocTextKey locTextKey) { final Button button = new Button(parent, SWT.NONE); - setAttribute(button, "role", "button"); + setARIARole(button, AriaRole.button); + setTestId(button, locTextKey.name); this.polyglotPageService.injectI18n(button, locTextKey); return button; } public Button buttonLocalized(final Composite parent, final CustomVariant variant, final String locTextKey) { final Button button = new Button(parent, SWT.NONE); - setAttribute(button, "role", "button"); + setARIARole(button, AriaRole.button); + setTestId(button, locTextKey); this.polyglotPageService.injectI18n(button, new LocTextKey(locTextKey)); button.setData(RWT.CUSTOM_VARIANT, variant.key); return button; @@ -394,7 +398,8 @@ public class WidgetFactory { final LocTextKey toolTipKey) { final Button button = new Button(parent, type); - setAttribute(button, "role", "button"); + setARIARole(button, AriaRole.button); + setTestId(button, locTextKey.name); this.polyglotPageService.injectI18n(button, locTextKey, toolTipKey); return button; } @@ -462,19 +467,19 @@ public class WidgetFactory { } public Text textInput(final Composite content, final LocTextKey label) { - return textInput(content, false, false, this.i18nSupport.getText(label)); + return textInput(content, false, false, label.name, this.i18nSupport.getText(label)); } - public Text textInput(final Composite content, final String label) { - return textInput(content, false, false, label); + public Text textInput(final Composite content, final String testKey, final String label) { + return textInput(content, false, false, testKey, label); } public Text passwordInput(final Composite content, final LocTextKey label) { - return textInput(content, true, false, this.i18nSupport.getText(label)); + return textInput(content, true, false, label.name, this.i18nSupport.getText(label)); } - public Text passwordInput(final Composite content, final String label) { - return textInput(content, true, false, label); + public Text passwordInput(final Composite content, final String testKey, final String label) { + return textInput(content, true, false, testKey, label); } public Text textAreaInput( @@ -505,13 +510,14 @@ public class WidgetFactory { final boolean readonly, final LocTextKey label) { - return textInput(content, password, readonly, this.i18nSupport.getText(label)); + return textInput(content, password, readonly, label.name, this.i18nSupport.getText(label)); } public Text textInput( final Composite content, final boolean password, final boolean readonly, + final String testKey, final String label) { final Text input = readonly @@ -523,6 +529,9 @@ public class WidgetFactory { if (label != null) { WidgetFactory.setAttribute(input, "aria-label", label); } + if (testKey != null) { + setTestId(input, testKey); + } return input; } @@ -539,6 +548,7 @@ public class WidgetFactory { final Text numberInput = new Text(content, (readonly) ? SWT.LEFT | SWT.READ_ONLY : SWT.RIGHT | SWT.BORDER); if (label != null) { WidgetFactory.setAttribute(numberInput, "aria-label", this.i18nSupport.getText(label)); + setTestId(numberInput, label.name); } if (numberCheck != null) { numberInput.addListener(SWT.Verify, event -> { @@ -648,24 +658,28 @@ public class WidgetFactory { public TreeItem treeItemLocalized(final Tree parent, final String locTextKey) { final TreeItem item = new TreeItem(parent, SWT.NONE); this.polyglotPageService.injectI18n(item, new LocTextKey(locTextKey)); + setTestId(item, locTextKey); return item; } public TreeItem treeItemLocalized(final Tree parent, final LocTextKey locTextKey) { final TreeItem item = new TreeItem(parent, SWT.NONE); this.polyglotPageService.injectI18n(item, locTextKey); + setTestId(item, locTextKey.name); return item; } public TreeItem treeItemLocalized(final TreeItem parent, final String locTextKey) { final TreeItem item = new TreeItem(parent, SWT.NONE); this.polyglotPageService.injectI18n(item, new LocTextKey(locTextKey)); + setTestId(item, locTextKey); return item; } public TreeItem treeItemLocalized(final TreeItem parent, final LocTextKey locTextKey) { final TreeItem item = new TreeItem(parent, SWT.NONE); this.polyglotPageService.injectI18n(item, locTextKey); + setTestId(item, locTextKey.name); return item; } @@ -748,15 +762,17 @@ public class WidgetFactory { if (listener != null) { imageButton.addListener(SWT.MouseDown, listener); } + setTestId(imageButton, toolTip.name); return imageButton; } public Selection selectionLocalized( final Selection.Type type, final Composite parent, - final Supplier>> itemsSupplier) { + final Supplier>> itemsSupplier, + final String actionLocTextPrefix) { - return this.selectionLocalized(type, parent, itemsSupplier, null, null); + return this.selectionLocalized(type, parent, itemsSupplier, null, null, actionLocTextPrefix); } public Selection selectionLocalized( @@ -765,7 +781,7 @@ public class WidgetFactory { final Supplier>> itemsSupplier, final LocTextKey toolTipTextKey) { - return this.selectionLocalized(type, parent, itemsSupplier, toolTipTextKey, null); + return this.selectionLocalized(type, parent, itemsSupplier, toolTipTextKey, null, toolTipTextKey.name); } public Selection selectionLocalized( @@ -775,7 +791,8 @@ public class WidgetFactory { final LocTextKey toolTipTextKey, final Supplier>> itemsToolTipSupplier) { - return selectionLocalized(type, parent, itemsSupplier, toolTipTextKey, itemsToolTipSupplier, null); + return selectionLocalized(type, parent, itemsSupplier, toolTipTextKey, itemsToolTipSupplier, + toolTipTextKey.name); } public Selection selectionLocalized( @@ -789,16 +806,16 @@ public class WidgetFactory { final Selection selection; switch (type) { case SINGLE: - selection = new SingleSelection(parent, SWT.READ_ONLY); + selection = new SingleSelection(parent, SWT.READ_ONLY, actionLocTextPrefix); break; case SINGLE_COMBO: - selection = new SingleSelection(parent, SWT.NONE); + selection = new SingleSelection(parent, SWT.NONE, actionLocTextPrefix); break; case RADIO: - selection = new RadioSelection(parent); + selection = new RadioSelection(parent, actionLocTextPrefix); break; case MULTI: - selection = new MultiSelection(parent); + selection = new MultiSelection(parent, actionLocTextPrefix); break; case MULTI_COMBO: selection = new MultiSelectionCombo( @@ -809,7 +826,7 @@ public class WidgetFactory { parent.getParent().getParent()); break; case MULTI_CHECKBOX: - selection = new MultiSelectionCheckbox(parent); + selection = new MultiSelectionCheckbox(parent, actionLocTextPrefix); break; case COLOR: selection = new ColorSelection(parent, this, actionLocTextPrefix); @@ -839,25 +856,34 @@ public class WidgetFactory { return selection; } - public DateTime dateSelector(final Composite parent) { + public DateTime dateSelector(final Composite parent, final String testKey) { RWT.setLocale(Locale.GERMANY); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); final DateTime dateTime = new DateTime(parent, SWT.DATE | SWT.BORDER | SWT.DROP_DOWN); dateTime.setLayoutData(gridData); + if (testKey != null) { + setTestId(dateTime, testKey); + } return dateTime; } - public DateTime timeSelector(final Composite parent) { + public DateTime timeSelector(final Composite parent, final String testKey) { final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); final DateTime dateTime = new DateTime(parent, SWT.TIME | SWT.BORDER | SWT.SHORT); dateTime.setLayoutData(gridData); + if (testKey != null) { + setTestId(dateTime, testKey); + } return dateTime; } - public DateTime timeSelectorWithSeconds(final Composite parent) { + public DateTime timeSelectorWithSeconds(final Composite parent, final String testKey) { final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); final DateTime dateTime = new DateTime(parent, SWT.TIME | SWT.BORDER | SWT.MEDIUM); dateTime.setLayoutData(gridData); + if (testKey != null) { + setTestId(dateTime, testKey); + } return dateTime; } From 6a989f50b21f1669c1f1661d11574f2bc2e73106 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 1 Dec 2021 14:54:11 +0100 Subject: [PATCH 2/2] fixed errors --- .../sebserver/gui/widget/WidgetFactory.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java index 540e3cb3..7206ddbc 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java @@ -399,7 +399,11 @@ public class WidgetFactory { final Button button = new Button(parent, type); setARIARole(button, AriaRole.button); - setTestId(button, locTextKey.name); + if (locTextKey != null) { + setTestId(button, locTextKey.name); + } else if (toolTipKey != null) { + setTestId(button, toolTipKey.name); + } this.polyglotPageService.injectI18n(button, locTextKey, toolTipKey); return button; } @@ -781,7 +785,13 @@ public class WidgetFactory { final Supplier>> itemsSupplier, final LocTextKey toolTipTextKey) { - return this.selectionLocalized(type, parent, itemsSupplier, toolTipTextKey, null, toolTipTextKey.name); + return this.selectionLocalized( + type, + parent, + itemsSupplier, + toolTipTextKey, + null, + (toolTipTextKey != null) ? toolTipTextKey.name : null); } public Selection selectionLocalized( @@ -791,8 +801,13 @@ public class WidgetFactory { final LocTextKey toolTipTextKey, final Supplier>> itemsToolTipSupplier) { - return selectionLocalized(type, parent, itemsSupplier, toolTipTextKey, itemsToolTipSupplier, - toolTipTextKey.name); + return selectionLocalized( + type, + parent, + itemsSupplier, + toolTipTextKey, + itemsToolTipSupplier, + (toolTipTextKey != null) ? toolTipTextKey.name : null); } public Selection selectionLocalized(