Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new Salesforce element types (closes #12) #14

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3251843
Create new Salesforce element types
jvervaec Apr 9, 2015
a31bdb8
Update darcy-web dependency to 0.2.1-SNAPSHOT
jvervaec Apr 10, 2015
aaa66ef
Make StaticCheckbox work more like the other new Salesforce elements
jvervaec Apr 10, 2015
3b7082e
Unit test fixes
jvervaec Apr 10, 2015
6ffb632
A few elements were missing the copyright comment
jvervaec Apr 10, 2015
0e95a56
Change URLOutputField to UrlOutputField
jvervaec Apr 13, 2015
2c41211
toggle() should also toggle the nested element, rather than clicking
jvervaec Apr 13, 2015
b2a310f
Typos in DateInputField
jvervaec Apr 13, 2015
f68501c
Rename URLOutputField to UrlOutputField
jvervaec Apr 13, 2015
9ccde54
PicklistOutputField should return a collection for getSelectedValues
jvervaec Apr 14, 2015
37e2924
Extra whitespace in RecordType
jvervaec Apr 14, 2015
127eb0b
Clean up import order
jvervaec Apr 14, 2015
4879f45
Add DateTimeFormatter to DateInputField
jvervaec Apr 14, 2015
60f8e89
Convert getSelectedOptions to use a stream
jvervaec Apr 14, 2015
976009a
Rework RequiredInput constructor to take a parent element instead of
jvervaec Apr 14, 2015
100f800
Fix elements that implement RequiredInput set it on the field instead of
jvervaec Apr 14, 2015
966cb59
Add constructors by parent element
jvervaec Apr 14, 2015
c38a27b
Some static method javadocs were on the constructor instead...
jvervaec Apr 14, 2015
5d2cf54
Unused import in DateInputField
jvervaec Apr 14, 2015
2507a3e
Convert Output elements that may not have nested elements to
jvervaec Apr 22, 2015
8182041
Remove unnecessary isPresent and isDisplayed overrides from
jvervaec Apr 22, 2015
7f69a30
Fix locator bug in LookupInputField
jvervaec Apr 22, 2015
267f136
Fix locator bug in StaticCheckbox
jvervaec Apr 22, 2015
55be52a
Fix extra semicolon in PicklistInputField
jvervaec Apr 22, 2015
14e2527
Bump minor version since we have lots of new useful stuff
jvervaec Apr 22, 2015
177d1b8
Fix broken StaticCheckboxTest
jvervaec Apr 22, 2015
0abc0be
Use semver style versioning
jvervaec Apr 23, 2015
bd81623
Use RequireAll and NotRequired instead of Requiring individual elements.
jvervaec Apr 23, 2015
a0278a1
Rework the Required vs RequireAll/NotRequired logic for a few more
jvervaec Apr 24, 2015
ce0d755
Whitespace and import cleanup on Owner
jvervaec Apr 24, 2015
fca5bfc
Add a mthod to check if the Change link is displayed for Owner element
jvervaec Apr 24, 2015
11badd3
Cleanup unnecessary super parent element.
jvervaec Apr 27, 2015
52451e4
TexTOutputField whitespace cleanup
jvervaec Apr 27, 2015
84335cb
Whitespace, import order, redundant isRequired isDisplayed cleanup.
jvervaec Apr 27, 2015
4a09ca6
Make DateOutputField tate a DateTimeFormatter too
jvervaec Apr 27, 2015
0c238b0
Javadoc clarifications about nested elements
jvervaec Apr 28, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>com.redhat.darcy</groupId>
<artifactId>darcy-salesforce</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>com.redhat.darcy</groupId>
<artifactId>darcy-web</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.redhat.synq</groupId>
Expand Down
112 changes: 112 additions & 0 deletions src/main/java/com/redhat/darcy/salesforce/CheckboxInputField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
Copyright 2014 Red Hat, Inc. and/or its affiliates.

This file is part of darcy-salesforce.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.redhat.darcy.salesforce;

import static com.redhat.darcy.salesforce.RequiredInput.requiredInput;
import static com.redhat.darcy.ui.Elements.checkbox;
import static com.redhat.darcy.web.By.htmlTag;

import com.redhat.darcy.ui.AbstractViewElement;
import com.redhat.darcy.ui.annotations.Require;
import com.redhat.darcy.ui.api.Locator;
import com.redhat.darcy.ui.api.elements.Checkbox;
import com.redhat.darcy.ui.api.elements.Element;
import com.redhat.darcy.ui.api.elements.Requireable;

/**
* An HTML input element for a value that corresponds to a checkbox field on
* a Salesforce object.
*/
public class CheckboxInputField extends AbstractViewElement implements Checkbox,
Requireable {

@Require
private Element parent = super.parent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So--and the only reason I'm making a fuss really is because, being the first official library of elements for darcy, I'm cautious about setting the wrong precedent--I think I wouldn't use this pattern unless we explicitly have a reason to @Require the parent element. I also am probably going to go ahead and require it by default anyway, and then instead allow you to @NotRequire it if you absolutely have to for some reason, but I'll add that on an as-needed basis if it comes to it. (Actually I'm starting to lean towards requiring all element fields by default).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have just left @RequireAll and @NotRequired the element for required input rather than marking everything else @required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, either way is fine with me. Explicitly having to annotated non-required elements may become a requirement at some point however.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyhow, if I wasn't clear (sorry if I'm being redundant, but I realized I rambled a bit), what I meant by my comment is to not have a private Element parent = super.parent field anymore basically.


@Require
private Checkbox nestedCheckbox = checkbox(byInner(htmlTag("input")));

private RequiredInput requiredInput = requiredInput(parent);

/**
* An HTML input element for a value that corresponds to a checkbox field
* on a Salesforce object. Takes the locator returned from BySalesforce
* and finds the input tag nested below.
*
* @param locator Locator returned from BySalesforce
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be more specific to the dom here. This helps when even implementing things in BySalesforce. For instance, if we say, "Accepts a locator for the parent element of the checkbox image," then that influences what locator code we write in BySalesforce. Otherwise, if we say, "uses what BySalesforce returns" it's a kind of chicken and egg problem :) (plus BySalesforce is intended to house as many locators as make sense). Looking at BySalesforce, I think we need to similarly improve the documentation: what exactly is being located from a DOM point of view?

* @return CheckboxInputField
*/
public static CheckboxInputField checkboxInputField(Locator locator) {
return new CheckboxInputField(locator);
}

public CheckboxInputField(Locator parent) {
super(parent);
}

public CheckboxInputField(Element parent) {
super(parent);
}

@Override
public void check() {
nestedCheckbox.check();
}

@Override
public void uncheck() {
nestedCheckbox.uncheck();
}

@Override
public boolean isChecked() {
return nestedCheckbox.isChecked();
}

@Override
public void toggle() {
nestedCheckbox.toggle();
}

@Override
public void click() {
nestedCheckbox.click();
}

@Override
public boolean isEnabled() {
return nestedCheckbox.isEnabled();
}

@Override
public boolean isDisplayed() {
return nestedCheckbox.isDisplayed();
}

@Override
public boolean isPresent() {
return nestedCheckbox.isPresent();
}

@Override
public boolean isRequired() {
return requiredInput.isDisplayed();
}
}
149 changes: 149 additions & 0 deletions src/main/java/com/redhat/darcy/salesforce/DateInputField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
Copyright 2014 Red Hat, Inc. and/or its affiliates.

This file is part of darcy-salesforce.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.redhat.darcy.salesforce;

import static com.redhat.darcy.salesforce.RequiredInput.requiredInput;
import static com.redhat.darcy.ui.By.xpath;
import static com.redhat.darcy.ui.Elements.link;
import static com.redhat.darcy.ui.Elements.textInput;
import static com.redhat.darcy.web.By.htmlTag;

import com.redhat.darcy.ui.AbstractViewElement;
import com.redhat.darcy.ui.annotations.Require;
import com.redhat.darcy.ui.api.Locator;
import com.redhat.darcy.ui.api.elements.DateInput;
import com.redhat.darcy.ui.api.elements.Element;
import com.redhat.darcy.ui.api.elements.Link;
import com.redhat.darcy.ui.api.elements.Requireable;
import com.redhat.darcy.ui.api.elements.TextInput;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
* An ViewElement for a value that corresponds to a Date field on
* a Salesforce object.
*/
public class DateInputField extends AbstractViewElement implements TextInput,
DateInput, Link, Requireable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of the various "role interfaces" here.


private DateTimeFormatter formatter;

@Require
private Element parent = super.parent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


@Require
private TextInput nestedTextInput = textInput(byInner(
xpath("//span[contains(@class,'dateInput')]"),
htmlTag("input")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice formatting with these; very easy to follow


@Require
private Link nestedLink = link(byInner(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this link refer to? From today() seems like this link is a shortcut to set the date to today? If so, please name this todayLink or something of the sort.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's a little wonky. The link has today's date [4/13/2015], rather than the word 'Today'. Clicking it just puts that value into the date input field. Naming things is hard :(

xpath("//span[contains(@class,'dateInput')]"),
htmlTag("span"), htmlTag("a")));

private RequiredInput requiredInput = requiredInput(parent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will still work without the parent field above of course


/**
* A ViewElement that corresponds to a Date field on
* a Salesforce object. Takes the locator returned from BySalesforce and
* finds the elements for the date text input and the [today] link.
*
* @param locator Locator returned from BySalesforce
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above (and for rest).

* @return DateInputField
*/
public static DateInputField dateInputField(Locator locator,
DateTimeFormatter formatter) {
return new DateInputField(locator, formatter);
}

public DateInputField(Locator parent, DateTimeFormatter formatter) {
super(parent);
this.formatter = formatter;
}

public DateInputField(Element parent, DateTimeFormatter formatter) {
super(parent);
this.formatter = formatter;
}

@Override
public void clearAndType(CharSequence... keysToType) {
nestedTextInput.clearAndType(keysToType);
}

@Override
public void type(CharSequence... keysToType) {
nestedTextInput.type(keysToType);
}

@Override
public void clear() {
nestedTextInput.clear();
}

/** Click the date input field. @see todayLink() for the [today] link. */
@Override
public void click() {
nestedTextInput.click();
}

@Override
public boolean isEnabled() {
return nestedTextInput.isEnabled();
}

@Override
public String getValue() {
return nestedTextInput.getValue();
}

@Override
public void setDate(LocalDate date) {
nestedTextInput.clearAndType(date.format(formatter));
}

@Override
public LocalDate getDate() {
return LocalDate.parse(nestedTextInput.getValue(), formatter);
}

@Override
public boolean isRequired() {
return requiredInput.isDisplayed();
}

/** Click the [today] link next to the date input field. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[today] isn't valid javadoc syntax AFAIK I wish it were. Dart's doc syntax uses that format and it's great. You'll have to do {@link #today} though I'm pretty sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not supposed to be javadoc syntax. The brackets are how it appears on the page in Salesforce. I supposed I could spell out "in brackets" :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see :). Thought you were trying to link to the today link field :). In that case, ignore my comment!

public void todayLink() {
nestedLink.click();
}

@Override
public String getText() {
return nestedLink.getText();

}

@Override
public String getLinkText() {
return nestedLink.getLinkText();

}
}
74 changes: 74 additions & 0 deletions src/main/java/com/redhat/darcy/salesforce/DateOutputField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2014 Red Hat, Inc. and/or its affiliates.

This file is part of darcy-salesforce.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.redhat.darcy.salesforce;

import static com.redhat.darcy.ui.Elements.text;

import com.redhat.darcy.ui.AbstractView;
import com.redhat.darcy.ui.annotations.RequireAll;
import com.redhat.darcy.ui.api.Locator;
import com.redhat.darcy.ui.api.elements.Text;

import java.time.LocalDate;

/**
* The text output of a Date field on a Salesforce object.
*/
@RequireAll
public class DateOutputField extends AbstractView implements Text {

private Text nestedDate;

/**
* Text which corresponds to a Date field on a Salesforce object. Takes
* the locator returned from BySalesforce and finds the text nested
* below.
*
* @param locator Locator returned from BySalesforce
* @return DateOutputField
*/
public static DateOutputField dateOutputField(Locator locator) {
return new DateOutputField(locator);
}

public DateOutputField(Locator locator) {
nestedDate = text(locator);
}

@Override
public boolean isDisplayed() {
return nestedDate.isDisplayed();
}

@Override
public boolean isPresent() {
return nestedDate.isDisplayed();
}

@Override
public String getText() {
return nestedDate.getText();
}

public LocalDate getDate() {
return LocalDate.parse(nestedDate.getText());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we need to accept / use a formatter here as well

}

}
Loading