-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Changes from 27 commits
3251843
a31bdb8
aaa66ef
3b7082e
6ffb632
0e95a56
2c41211
b2a310f
f68501c
9ccde54
37e2924
127eb0b
4879f45
60f8e89
976009a
100f800
966cb59
c38a27b
5d2cf54
2507a3e
8182041
7f69a30
267f136
55be52a
14e2527
177d1b8
0abc0be
bd81623
a0278a1
ce0d755
fca5bfc
11badd3
52451e4
84335cb
4a09ca6
0c238b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
||
@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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
* @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(); | ||
} | ||
} |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this link refer to? From There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
||
} | ||
} |
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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we need to accept / use a formatter here as well |
||
} | ||
|
||
} |
There was a problem hiding this comment.
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).There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.