added test id attributes

This commit is contained in:
anhefti 2021-11-09 16:47:39 +01:00
parent 814fa84730
commit 70c4fe1571
8 changed files with 94 additions and 45 deletions

View file

@ -323,6 +323,7 @@ public class TableFilter<ROW> {
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<ROW> {
.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<ROW> {
@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<ROW> {
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;

View file

@ -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);
}

View file

@ -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

View file

@ -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<String, Button> 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<>();
}

View file

@ -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);

View file

@ -31,7 +31,7 @@ public final class RadioSelection extends Composite implements Selection {
private Listener listener = null;
private final Map<String, Button> 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);
}

View file

@ -29,11 +29,14 @@ public final class SingleSelection extends Combo implements Selection {
final List<String> 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

View file

@ -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<List<Tuple<String>>> itemsSupplier) {
final Supplier<List<Tuple<String>>> 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<List<Tuple<String>>> 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<List<Tuple<String>>> 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;
}