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( this.textInput = TableFilter.this.entityTable.widgetFactory.textInput(
innerComposite, innerComposite,
TableFilter.this.entityTable.getName() + "_" + this.attribute.columnName,
super.attribute.columnName); super.attribute.columnName);
this.textInput.setLayoutData(gridData); this.textInput.setLayoutData(gridData);
return this; return this;
@ -375,7 +376,8 @@ public class TableFilter<ROW> {
.selectionLocalized( .selectionLocalized(
ch.ethz.seb.sebserver.gui.widget.Selection.Type.SINGLE, ch.ethz.seb.sebserver.gui.widget.Selection.Type.SINGLE,
innerComposite, innerComposite,
resourceSupplier); resourceSupplier,
TableFilter.this.entityTable.getName() + "_" + this.attribute.columnName);
this.selector this.selector
.adaptToControl() .adaptToControl()
@ -429,7 +431,9 @@ public class TableFilter<ROW> {
@Override @Override
FilterComponent build(final Composite parent) { FilterComponent build(final Composite parent) {
final Composite innerComposite = createInnerComposite(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; return this;
} }
@ -520,17 +524,18 @@ public class TableFilter<ROW> {
this.innerComposite.setLayout(gridLayout); this.innerComposite.setLayout(gridLayout);
this.innerComposite.setLayoutData(this.rowData); this.innerComposite.setLayoutData(this.rowData);
final String testKey = TableFilter.this.entityTable.getName() + "_" + this.attribute.columnName;
final WidgetFactory wf = TableFilter.this.entityTable.widgetFactory; final WidgetFactory wf = TableFilter.this.entityTable.widgetFactory;
wf.labelLocalized(this.innerComposite, DATE_FROM_TEXT); wf.labelLocalized(this.innerComposite, DATE_FROM_TEXT);
this.fromDateSelector = wf.dateSelector(this.innerComposite); this.fromDateSelector = wf.dateSelector(this.innerComposite, testKey);
if (this.withTime) { if (this.withTime) {
this.fromTimeSelector = wf.timeSelector(this.innerComposite); this.fromTimeSelector = wf.timeSelector(this.innerComposite, testKey);
} }
wf.labelLocalized(this.innerComposite, DATE_TO_TEXT); wf.labelLocalized(this.innerComposite, DATE_TO_TEXT);
this.toDateSelector = wf.dateSelector(this.innerComposite); this.toDateSelector = wf.dateSelector(this.innerComposite, testKey);
if (this.withTime) { if (this.withTime) {
this.toTimeSelector = wf.timeSelector(this.innerComposite); this.toTimeSelector = wf.timeSelector(this.innerComposite, testKey);
} }
return this; return this;

View file

@ -95,6 +95,10 @@ public final class ColorSelection extends Composite implements Selection {
actionCell.widthHint = ACTION_COLUMN_WIDTH; actionCell.widthHint = ACTION_COLUMN_WIDTH;
imageButton.setLayoutData(actionCell); imageButton.setLayoutData(actionCell);
if (tooltipKeyPrefix != null) {
WidgetFactory.setTestId(this, tooltipKeyPrefix);
}
this.addListener(SWT.Resize, this::adaptColumnWidth); this.addListener(SWT.Resize, this::adaptColumnWidth);
} }

View file

@ -36,7 +36,7 @@ public final class MultiSelection extends Composite implements Selection {
private Listener listener = null; private Listener listener = null;
MultiSelection(final Composite parent) { MultiSelection(final Composite parent, final String testKey) {
super(parent, SWT.NONE); super(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout(1, true); final GridLayout gridLayout = new GridLayout(1, true);
gridLayout.verticalSpacing = 1; gridLayout.verticalSpacing = 1;
@ -44,6 +44,9 @@ public final class MultiSelection extends Composite implements Selection {
gridLayout.marginHeight = 0; gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0; gridLayout.marginWidth = 0;
setLayout(gridLayout); setLayout(gridLayout);
if (testKey != null) {
WidgetFactory.setTestId(this, testKey);
}
} }
@Override @Override

View file

@ -8,11 +8,11 @@
package ch.ethz.seb.sebserver.gui.widget; package ch.ethz.seb.sebserver.gui.widget;
import ch.ethz.seb.sebserver.gbl.Constants; import java.util.Arrays;
import ch.ethz.seb.sebserver.gbl.util.Tuple; import java.util.LinkedHashMap;
import ch.ethz.seb.sebserver.gbl.util.Tuple3; import java.util.List;
import ch.ethz.seb.sebserver.gbl.util.Utils; import java.util.Map;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData; 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.Composite;
import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Listener;
import java.util.Arrays; import ch.ethz.seb.sebserver.gbl.Constants;
import java.util.LinkedHashMap; import ch.ethz.seb.sebserver.gbl.util.Tuple;
import java.util.List; import ch.ethz.seb.sebserver.gbl.util.Tuple3;
import java.util.Map; 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 { 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 Listener listener = null;
private final Map<String, Button> checkboxes; private final Map<String, Button> checkboxes;
MultiSelectionCheckbox(final Composite parent) { MultiSelectionCheckbox(final Composite parent, final String testKey) {
super(parent, SWT.NONE); super(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout(1, true); final GridLayout gridLayout = new GridLayout(1, true);
gridLayout.verticalSpacing = 1; gridLayout.verticalSpacing = 1;
@ -41,6 +42,9 @@ public final class MultiSelectionCheckbox extends Composite implements Selection
gridLayout.marginHeight = 0; gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0; gridLayout.marginWidth = 0;
setLayout(gridLayout); setLayout(gridLayout);
if (testKey != null) {
WidgetFactory.setTestId(this, testKey);
}
this.checkboxes = new LinkedHashMap<>(); this.checkboxes = new LinkedHashMap<>();
} }

View file

@ -69,7 +69,7 @@ public final class MultiSelectionCombo extends Composite implements Selection {
setLayout(gridLayout); setLayout(gridLayout);
this.addListener(SWT.Resize, this::adaptColumnWidth); 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.textCell = new GridData(SWT.LEFT, SWT.CENTER, true, true);
this.textInput.setLayoutData(this.textCell); this.textInput.setLayoutData(this.textCell);
this.dropDown = new DropDown(this.textInput, SWT.NONE); 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 Listener listener = null;
private final Map<String, Button> radioButtons; private final Map<String, Button> radioButtons;
RadioSelection(final Composite parent) { RadioSelection(final Composite parent, final String testKey) {
super(parent, SWT.NONE); super(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout(1, true); final GridLayout gridLayout = new GridLayout(1, true);
gridLayout.verticalSpacing = 1; gridLayout.verticalSpacing = 1;
@ -39,6 +39,9 @@ public final class RadioSelection extends Composite implements Selection {
gridLayout.marginHeight = 0; gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0; gridLayout.marginWidth = 0;
setLayout(gridLayout); setLayout(gridLayout);
if (testKey != null) {
WidgetFactory.setTestId(this, testKey);
}
this.radioButtons = new LinkedHashMap<>(); this.radioButtons = new LinkedHashMap<>();
} }
@ -65,6 +68,7 @@ public final class RadioSelection extends Composite implements Selection {
this.listener.handleEvent(event); this.listener.handleEvent(event);
} }
}); });
WidgetFactory.setTestId(button, tuple._1);
this.radioButtons.put(tuple._1, button); 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 List<String> keyMapping;
final boolean isEditable; final boolean isEditable;
SingleSelection(final Composite parent, final int type) { SingleSelection(final Composite parent, final int type, final String testKey) {
super(parent, type); super(parent, type);
this.valueMapping = new ArrayList<>(); this.valueMapping = new ArrayList<>();
this.keyMapping = new ArrayList<>(); this.keyMapping = new ArrayList<>();
this.isEditable = type == SWT.NONE; this.isEditable = type == SWT.NONE;
if (testKey != null) {
WidgetFactory.setTestId(this, testKey);
}
} }
@Override @Override

View file

@ -67,11 +67,12 @@ import ch.ethz.seb.sebserver.gui.service.push.ServerPushService;
public class WidgetFactory { public class WidgetFactory {
private static final String ADD_HTML_ATTR_ARIA_ROLE = "role"; 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"; private static final String SUB_TITLE_TExT_SUFFIX = ".subtitle";
public enum AriaRole { public enum AriaRole {
link link,
button,
} }
private static final Logger log = LoggerFactory.getLogger(WidgetFactory.class); 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) { public Button buttonLocalized(final Composite parent, final String locTextKey) {
final Button button = new Button(parent, SWT.NONE); 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)); this.polyglotPageService.injectI18n(button, new LocTextKey(locTextKey));
return button; return button;
} }
public Button buttonLocalized(final Composite parent, final LocTextKey locTextKey) { public Button buttonLocalized(final Composite parent, final LocTextKey locTextKey) {
final Button button = new Button(parent, SWT.NONE); 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); this.polyglotPageService.injectI18n(button, locTextKey);
return button; return button;
} }
public Button buttonLocalized(final Composite parent, final CustomVariant variant, final String locTextKey) { public Button buttonLocalized(final Composite parent, final CustomVariant variant, final String locTextKey) {
final Button button = new Button(parent, SWT.NONE); 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)); this.polyglotPageService.injectI18n(button, new LocTextKey(locTextKey));
button.setData(RWT.CUSTOM_VARIANT, variant.key); button.setData(RWT.CUSTOM_VARIANT, variant.key);
return button; return button;
@ -394,7 +398,8 @@ public class WidgetFactory {
final LocTextKey toolTipKey) { final LocTextKey toolTipKey) {
final Button button = new Button(parent, type); 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); this.polyglotPageService.injectI18n(button, locTextKey, toolTipKey);
return button; return button;
} }
@ -462,19 +467,19 @@ public class WidgetFactory {
} }
public Text textInput(final Composite content, final LocTextKey label) { 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) { public Text textInput(final Composite content, final String testKey, final String label) {
return textInput(content, false, false, label); return textInput(content, false, false, testKey, label);
} }
public Text passwordInput(final Composite content, final LocTextKey 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) { public Text passwordInput(final Composite content, final String testKey, final String label) {
return textInput(content, true, false, label); return textInput(content, true, false, testKey, label);
} }
public Text textAreaInput( public Text textAreaInput(
@ -505,13 +510,14 @@ public class WidgetFactory {
final boolean readonly, final boolean readonly,
final LocTextKey label) { 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( public Text textInput(
final Composite content, final Composite content,
final boolean password, final boolean password,
final boolean readonly, final boolean readonly,
final String testKey,
final String label) { final String label) {
final Text input = readonly final Text input = readonly
@ -523,6 +529,9 @@ public class WidgetFactory {
if (label != null) { if (label != null) {
WidgetFactory.setAttribute(input, "aria-label", label); WidgetFactory.setAttribute(input, "aria-label", label);
} }
if (testKey != null) {
setTestId(input, testKey);
}
return input; 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); final Text numberInput = new Text(content, (readonly) ? SWT.LEFT | SWT.READ_ONLY : SWT.RIGHT | SWT.BORDER);
if (label != null) { if (label != null) {
WidgetFactory.setAttribute(numberInput, "aria-label", this.i18nSupport.getText(label)); WidgetFactory.setAttribute(numberInput, "aria-label", this.i18nSupport.getText(label));
setTestId(numberInput, label.name);
} }
if (numberCheck != null) { if (numberCheck != null) {
numberInput.addListener(SWT.Verify, event -> { numberInput.addListener(SWT.Verify, event -> {
@ -648,24 +658,28 @@ public class WidgetFactory {
public TreeItem treeItemLocalized(final Tree parent, final String locTextKey) { public TreeItem treeItemLocalized(final Tree parent, final String locTextKey) {
final TreeItem item = new TreeItem(parent, SWT.NONE); final TreeItem item = new TreeItem(parent, SWT.NONE);
this.polyglotPageService.injectI18n(item, new LocTextKey(locTextKey)); this.polyglotPageService.injectI18n(item, new LocTextKey(locTextKey));
setTestId(item, locTextKey);
return item; return item;
} }
public TreeItem treeItemLocalized(final Tree parent, final LocTextKey locTextKey) { public TreeItem treeItemLocalized(final Tree parent, final LocTextKey locTextKey) {
final TreeItem item = new TreeItem(parent, SWT.NONE); final TreeItem item = new TreeItem(parent, SWT.NONE);
this.polyglotPageService.injectI18n(item, locTextKey); this.polyglotPageService.injectI18n(item, locTextKey);
setTestId(item, locTextKey.name);
return item; return item;
} }
public TreeItem treeItemLocalized(final TreeItem parent, final String locTextKey) { public TreeItem treeItemLocalized(final TreeItem parent, final String locTextKey) {
final TreeItem item = new TreeItem(parent, SWT.NONE); final TreeItem item = new TreeItem(parent, SWT.NONE);
this.polyglotPageService.injectI18n(item, new LocTextKey(locTextKey)); this.polyglotPageService.injectI18n(item, new LocTextKey(locTextKey));
setTestId(item, locTextKey);
return item; return item;
} }
public TreeItem treeItemLocalized(final TreeItem parent, final LocTextKey locTextKey) { public TreeItem treeItemLocalized(final TreeItem parent, final LocTextKey locTextKey) {
final TreeItem item = new TreeItem(parent, SWT.NONE); final TreeItem item = new TreeItem(parent, SWT.NONE);
this.polyglotPageService.injectI18n(item, locTextKey); this.polyglotPageService.injectI18n(item, locTextKey);
setTestId(item, locTextKey.name);
return item; return item;
} }
@ -748,15 +762,17 @@ public class WidgetFactory {
if (listener != null) { if (listener != null) {
imageButton.addListener(SWT.MouseDown, listener); imageButton.addListener(SWT.MouseDown, listener);
} }
setTestId(imageButton, toolTip.name);
return imageButton; return imageButton;
} }
public Selection selectionLocalized( public Selection selectionLocalized(
final Selection.Type type, final Selection.Type type,
final Composite parent, 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( public Selection selectionLocalized(
@ -765,7 +781,7 @@ public class WidgetFactory {
final Supplier<List<Tuple<String>>> itemsSupplier, final Supplier<List<Tuple<String>>> itemsSupplier,
final LocTextKey toolTipTextKey) { final LocTextKey toolTipTextKey) {
return this.selectionLocalized(type, parent, itemsSupplier, toolTipTextKey, null); return this.selectionLocalized(type, parent, itemsSupplier, toolTipTextKey, null, toolTipTextKey.name);
} }
public Selection selectionLocalized( public Selection selectionLocalized(
@ -775,7 +791,8 @@ public class WidgetFactory {
final LocTextKey toolTipTextKey, final LocTextKey toolTipTextKey,
final Supplier<List<Tuple<String>>> itemsToolTipSupplier) { 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( public Selection selectionLocalized(
@ -789,16 +806,16 @@ public class WidgetFactory {
final Selection selection; final Selection selection;
switch (type) { switch (type) {
case SINGLE: case SINGLE:
selection = new SingleSelection(parent, SWT.READ_ONLY); selection = new SingleSelection(parent, SWT.READ_ONLY, actionLocTextPrefix);
break; break;
case SINGLE_COMBO: case SINGLE_COMBO:
selection = new SingleSelection(parent, SWT.NONE); selection = new SingleSelection(parent, SWT.NONE, actionLocTextPrefix);
break; break;
case RADIO: case RADIO:
selection = new RadioSelection(parent); selection = new RadioSelection(parent, actionLocTextPrefix);
break; break;
case MULTI: case MULTI:
selection = new MultiSelection(parent); selection = new MultiSelection(parent, actionLocTextPrefix);
break; break;
case MULTI_COMBO: case MULTI_COMBO:
selection = new MultiSelectionCombo( selection = new MultiSelectionCombo(
@ -809,7 +826,7 @@ public class WidgetFactory {
parent.getParent().getParent()); parent.getParent().getParent());
break; break;
case MULTI_CHECKBOX: case MULTI_CHECKBOX:
selection = new MultiSelectionCheckbox(parent); selection = new MultiSelectionCheckbox(parent, actionLocTextPrefix);
break; break;
case COLOR: case COLOR:
selection = new ColorSelection(parent, this, actionLocTextPrefix); selection = new ColorSelection(parent, this, actionLocTextPrefix);
@ -839,25 +856,34 @@ public class WidgetFactory {
return selection; return selection;
} }
public DateTime dateSelector(final Composite parent) { public DateTime dateSelector(final Composite parent, final String testKey) {
RWT.setLocale(Locale.GERMANY); RWT.setLocale(Locale.GERMANY);
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
final DateTime dateTime = new DateTime(parent, SWT.DATE | SWT.BORDER | SWT.DROP_DOWN); final DateTime dateTime = new DateTime(parent, SWT.DATE | SWT.BORDER | SWT.DROP_DOWN);
dateTime.setLayoutData(gridData); dateTime.setLayoutData(gridData);
if (testKey != null) {
setTestId(dateTime, testKey);
}
return dateTime; 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 GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
final DateTime dateTime = new DateTime(parent, SWT.TIME | SWT.BORDER | SWT.SHORT); final DateTime dateTime = new DateTime(parent, SWT.TIME | SWT.BORDER | SWT.SHORT);
dateTime.setLayoutData(gridData); dateTime.setLayoutData(gridData);
if (testKey != null) {
setTestId(dateTime, testKey);
}
return dateTime; 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 GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
final DateTime dateTime = new DateTime(parent, SWT.TIME | SWT.BORDER | SWT.MEDIUM); final DateTime dateTime = new DateTime(parent, SWT.TIME | SWT.BORDER | SWT.MEDIUM);
dateTime.setLayoutData(gridData); dateTime.setLayoutData(gridData);
if (testKey != null) {
setTestId(dateTime, testKey);
}
return dateTime; return dateTime;
} }