SEBSERV-312 as discussed

This commit is contained in:
anhefti 2022-05-31 15:48:00 +02:00
parent 97f174d740
commit 22bbee1117
4 changed files with 19 additions and 7 deletions

View file

@ -34,6 +34,8 @@ import ch.ethz.seb.sebserver.gui.widget.WidgetFactory;
public final class SelectionFieldBuilder extends FieldBuilder<String> { public final class SelectionFieldBuilder extends FieldBuilder<String> {
private static final String TEST_KEY_SUFFIX = ".action";
final Supplier<List<Tuple<String>>> itemsSupplier; final Supplier<List<Tuple<String>>> itemsSupplier;
Consumer<Form> selectionListener = null; Consumer<Form> selectionListener = null;
final Selection.Type type; final Selection.Type type;
@ -69,14 +71,14 @@ public final class SelectionFieldBuilder extends FieldBuilder<String> {
private void buildInput(final FormBuilder builder, final Control titleLabel) { private void buildInput(final FormBuilder builder, final Control titleLabel) {
final Composite fieldGrid = createFieldGrid(builder.formParent, this.spanInput); final Composite fieldGrid = createFieldGrid(builder.formParent, this.spanInput);
final String actionKey = (this.label != null) ? this.label.name + ".action" : null; final String testKey = (this.label != null) ? this.label.name + TEST_KEY_SUFFIX : null;
final Selection selection = builder.widgetFactory.selectionLocalized( final Selection selection = builder.widgetFactory.selectionLocalized(
this.type, this.type,
fieldGrid, fieldGrid,
this.itemsSupplier, this.itemsSupplier,
(builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) ? this.tooltip : null, (builder.pageService.getFormTooltipMode() == PageService.FormTooltipMode.INPUT) ? this.tooltip : null,
null, null,
actionKey, testKey,
builder.i18nSupport.getText(getARIALabel(builder))); builder.i18nSupport.getText(getARIALabel(builder)));
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
@ -161,7 +163,12 @@ public final class SelectionFieldBuilder extends FieldBuilder<String> {
} }
if (this.label != null) { if (this.label != null) {
WidgetFactory.setTestId(label, this.label.name + "_" + valueKey); final String testKey = this.label.name + TEST_KEY_SUFFIX;
if (this.type == Type.MULTI || this.type == Type.MULTI_COMBO || this.type == Type.MULTI_CHECKBOX) {
WidgetFactory.setTestId(label, testKey + "_" + valueKey);
} else {
WidgetFactory.setTestId(label, testKey);
}
} }
return label; return label;

View file

@ -33,6 +33,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;
private final String testKey;
MultiSelectionCheckbox(final Composite parent, final String testKey) { MultiSelectionCheckbox(final Composite parent, final String testKey) {
super(parent, SWT.NONE); super(parent, SWT.NONE);
@ -42,6 +43,7 @@ public final class MultiSelectionCheckbox extends Composite implements Selection
gridLayout.marginHeight = 0; gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0; gridLayout.marginWidth = 0;
setLayout(gridLayout); setLayout(gridLayout);
this.testKey = testKey;
if (testKey != null) { if (testKey != null) {
WidgetFactory.setTestId(this, testKey); WidgetFactory.setTestId(this, testKey);
} }
@ -69,7 +71,7 @@ public final class MultiSelectionCheckbox extends Composite implements Selection
final Button button = new Button(this, SWT.CHECK); final Button button = new Button(this, SWT.CHECK);
button.setText(tuple._2); button.setText(tuple._2);
WidgetFactory.setARIALabel(button, tuple._2); WidgetFactory.setARIALabel(button, tuple._2);
WidgetFactory.setTestId(button, tuple._1); WidgetFactory.setTestId(button, (this.testKey != null) ? this.testKey + "_" + tuple._1 : tuple._1);
final GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, true); final GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, true);
button.setLayoutData(gridData); button.setLayoutData(gridData);
button.setData(OPTION_VALUE, tuple._1); button.setData(OPTION_VALUE, tuple._1);
@ -78,8 +80,6 @@ public final class MultiSelectionCheckbox extends Composite implements Selection
this.listener.handleEvent(event); this.listener.handleEvent(event);
} }
}); });
WidgetFactory.setTestId(button, tuple._1);
WidgetFactory.setARIALabel(button, tuple._2);
this.checkboxes.put(tuple._1, button); this.checkboxes.put(tuple._1, button);
try { try {

View file

@ -48,6 +48,7 @@ public final class MultiSelectionCombo extends Composite implements Selection {
private final Text textInput; private final Text textInput;
private final GridData textCell; private final GridData textCell;
private final Composite updateAnchor; private final Composite updateAnchor;
private final String testKey;
private Listener listener = null; private Listener listener = null;
@ -59,6 +60,7 @@ public final class MultiSelectionCombo extends Composite implements Selection {
super(parent, SWT.NONE); super(parent, SWT.NONE);
this.widgetFactory = widgetFactory; this.widgetFactory = widgetFactory;
this.testKey = locTextPrefix;
final GridLayout gridLayout = new GridLayout(); final GridLayout gridLayout = new GridLayout();
gridLayout.verticalSpacing = 1; gridLayout.verticalSpacing = 1;
@ -175,6 +177,9 @@ public final class MultiSelectionCombo extends Composite implements Selection {
label.addListener(SWT.MouseDoubleClick, this::removeComboSelection); label.addListener(SWT.MouseDoubleClick, this::removeComboSelection);
this.selectionControls.add(label); this.selectionControls.add(label);
WidgetFactory.setARIALabel(label, item._2);
WidgetFactory.setTestId(label, (this.testKey != null) ? this.testKey + "_" + item._1 : item._1);
this.availableValues.remove(item); this.availableValues.remove(item);
PageService.updateScrolledComposite(this); PageService.updateScrolledComposite(this);
this.updateAnchor.layout(true, true); this.updateAnchor.layout(true, true);

View file

@ -75,7 +75,7 @@ public final class RadioSelection extends Composite implements Selection {
this.listener.handleEvent(event); this.listener.handleEvent(event);
} }
}); });
WidgetFactory.setTestId(button, (this.testKey != null) ? this.testKey + tuple._1 : tuple._1); WidgetFactory.setTestId(button, (this.testKey != null) ? this.testKey + "_" + tuple._1 : tuple._1);
WidgetFactory.setARIALabel(button, tuple._2); WidgetFactory.setARIALabel(button, tuple._2);
this.radioButtons.put(tuple._1, button); this.radioButtons.put(tuple._1, button);
} }