Skip to content

Commit

Permalink
Add InputDialog and tests for it (fixes #2084)
Browse files Browse the repository at this point in the history
Signed-off-by: Josef Kopriva <jkopriva@redhat.com>
  • Loading branch information
jkopriva authored and odockal committed Oct 26, 2020
1 parent 8de6002 commit 1669a3b
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.eclipse.reddeer.jface.dialogs;

import org.eclipse.reddeer.common.util.Display;
import org.eclipse.reddeer.swt.impl.button.CancelButton;
import org.eclipse.reddeer.swt.impl.button.OkButton;
import org.eclipse.reddeer.swt.impl.shell.DefaultShell;
import org.eclipse.reddeer.swt.impl.text.DefaultText;

/**
* {@link org.eclipse.jface.dialogs.InputDialog}
*
* @author Radoslav Rabara, jkopriva@redhat.com
*
*/
public class InputDialog extends DefaultShell {

/**
* Represents the InputDialog.
*/
public InputDialog() {
super();
}

/**
* Represents InputDialog with the specified <var>title</var>.
*
* @param title InputDialog title
*/
public InputDialog(String title) {
super(title);
}

/**
* Click on the OK button.
*/
public void ok() {
new OkButton().click();
}

/**
* Click on the cancel button.
*/
public void cancel() {
new CancelButton().click();
}

/**
* Returns text from input text field.
*
* @return input text
*/
public String getInputText() {
return new DefaultText().getText();
}

/**
* Returns text from input text field.
*
* @return input text
*/
public String getTitleText() {
return Display.syncExec(() -> this.getText());
}

/**
* Sets the specified <var>text</var> into input text field.
*
* @param text text to be set
*/
public void setInputText(String text) {
new DefaultText().setText(text);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.eclipse.reddeer.jface.test.dialogs;

import static org.junit.Assert.assertEquals;

import org.eclipse.reddeer.common.util.Display;
import org.eclipse.reddeer.jface.dialogs.InputDialog;
import org.eclipse.reddeer.jface.test.dialogs.impl.TestingInputDialog;
import org.eclipse.swt.widgets.Shell;
import org.junit.After;
import org.junit.Test;

/**
*
* @author jkopriva@redhat.com
*
*/
public class InputDialogTest {

private static TestingInputDialog inputDialog;
private Shell s;

@Test
public void inputDialogMessagesTest() {
openInputDialog();
InputDialog dialog = new InputDialog(TestingInputDialog.TITLE);
assertEquals(TestingInputDialog.TITLE, dialog.getTitleText());
assertEquals(TestingInputDialog.INITIAL_TEXT, dialog.getInputText());
}

@Test
public void inputDialogCancelTest() {
openInputDialog();
InputDialog dialog = new InputDialog(TestingInputDialog.TITLE);
dialog.cancel();
}

@Test
public void inputDialogOkTest() {
openInputDialog();
InputDialog dialog = new InputDialog(TestingInputDialog.TITLE);
dialog.ok();
}

@Test
public void inputDialogSetTextGetTextTest() {
openInputDialog();
InputDialog dialog = new InputDialog(TestingInputDialog.TITLE);
dialog.setInputText("something");
assertEquals("something", dialog.getInputText());
dialog.cancel();
}

public void openInputDialog() {
Display.asyncExec(new Runnable() {

@Override
public void run() {
inputDialog = new TestingInputDialog();
inputDialog.create();
inputDialog.open();

}
});

}

@After
public void closeShell() {
Display.syncExec(new Runnable() {

@Override
public void run() {
if (s != null) {
s.dispose();
}
if (inputDialog != null) {
inputDialog.close();
}
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
*******************************************************************************/
package org.eclipse.reddeer.jface.test.dialogs;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.reddeer.common.util.Display;
import org.eclipse.reddeer.core.exception.CoreLayerException;
import org.eclipse.reddeer.eclipse.selectionwizard.NewMenuWizard;
Expand All @@ -25,6 +25,7 @@
import org.eclipse.reddeer.jface.test.dialogs.impl.TestingNewWizard;
import org.eclipse.reddeer.jface.test.dialogs.impl.TestingTitleAreaDialog;
import org.eclipse.reddeer.swt.impl.button.PushButton;
import org.eclipse.swt.widgets.Shell;
import org.junit.After;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.eclipse.reddeer.jface.test.dialogs.impl;

import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
*
* @author jkopriva@redhat.com
*
*/
public class TestingInputDialog extends InputDialog {

public static final String TEXT = "InputDialog info message";
public static final String INITIAL_TEXT = "InputDialog initial text";
public static final String TITLE = "InputDialog title";

public TestingInputDialog() {
super(null, TITLE, TEXT, INITIAL_TEXT, null);
}

@Override
public void create() {
super.create();
getShell().setText(TITLE);
}

@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout layout = new GridLayout(2, false);
container.setLayout(layout);

return area;
}

}

0 comments on commit 1669a3b

Please sign in to comment.