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

Enable the test to check the added variant #4418

Merged
merged 5 commits into from
Jul 23, 2018
Merged
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,52 @@ public void openDemoPageAndCheckForErrors() {
}

/**
* Verifies variants functionality for the current layout.
* Verifies variants functionality for the current layout with default implementation.
Copy link
Contributor

Choose a reason for hiding this comment

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

with default implementation

Quite confusing addition because of questions:

  • Which default implementation?
  • Implementation of what ?

Please do what's written below and change this sentence to mention the nested class.
Then it will be clear what's the default impl you mean (and please change javadoc to default impl of variant producer).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added the link to the nested class

*
* The test will fail if a specific variant demo is not added first with
* {@link DemoView#addVariantsDemo(Supplier, BiConsumer, BiConsumer, Function, Enum[])}
* method.
*/
protected void verifyThemeVariantsBeingToggled() {
verifyThemeVariantsBeingToggled(defaultProducer);
}

/**
* With current design, the theme variant can be obtained from the button
* attached to the demo
*/
private Function<WebElement, String> defaultProducer = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make this class visible so it can be reused/extended:

  • make the class nested (not anonymous) (and not inner, it should be static).
  • make a static constant DEFAULT_VARIANT_PRODUCER.
  • set DEFAULT_VARIANT_PRODUCER to the instance of the created class
  • pass it as an argument to the verifyThemeVariantsBeingToggled in the above impl.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

WebElement button) -> {
String[] variant = button.getText().split("'");
return variant[1];
};

/**
* Verifies variants functionality for the current layout with customized
* implementation.
*/
protected void verifyThemeVariantsBeingToggled(
Function<WebElement, String> variantProducer) {
List<WebElement> toggleThemeButtons = layout
.findElement(By.id(VARIANT_TOGGLE_BUTTONS_DIV_ID))
.findElements(By.tagName("button"));
Assert.assertFalse(
"Expected at least one toggle theme button in 'buttonDiv', but got none",
toggleThemeButtons.isEmpty());
toggleThemeButtons.forEach(button -> toggleVariantAndCheck(
layout.findElement(By.id(COMPONENT_WITH_VARIANTS_ID)), button));
layout.findElement(By.id(COMPONENT_WITH_VARIANTS_ID)), button,
variantProducer));
}

private void toggleVariantAndCheck(WebElement component,
WebElement button) {
WebElement button, Function<WebElement, String> variantProducer) {
List<String> initialButtonThemes = getComponentThemes(component);
String initialButtonText = button.getText();

button.click();
verifyThemeIsToggled(getComponentThemes(component), button.getText(),
initialButtonThemes, initialButtonText);
initialButtonThemes, initialButtonText,
variantProducer.apply(button));

button.click();
Assert.assertEquals(
Expand All @@ -100,12 +121,12 @@ private void toggleVariantAndCheck(WebElement component,

private void verifyThemeIsToggled(List<String> updatedThemes,
String updatedButtonText, List<String> previousThemes,
String previousButtonText) {
String previousButtonText,
String variantName) {
Assert.assertNotEquals("Button should change its text after toggling",
previousButtonText, updatedButtonText);

boolean shouldAddTheme = previousButtonText.startsWith("Add");
String[] variant = updatedButtonText.split("'");
if (shouldAddTheme) {
Assert.assertTrue(
"When a theme variant got added, toggle button text should start with 'Remove' word",
Expand All @@ -118,9 +139,10 @@ private void verifyThemeIsToggled(List<String> updatedThemes,
updatedThemes.containsAll(previousThemes));

Assert.assertTrue(
"The selected theme variant:" + variant[1]
"The selected theme variant:"
+ variantName
+ " should be added to the component 'theme' attribute.",
updatedThemes.contains(variant[1]));
updatedThemes.contains(variantName));
} else {
Assert.assertTrue(
"When a theme variant got removed, toggle button text should start with 'Add' word",
Expand All @@ -132,9 +154,9 @@ private void verifyThemeIsToggled(List<String> updatedThemes,
"When a theme variant got removed, previous theme variants should contain all theme variants from component 'theme' attribute",
previousThemes.containsAll(updatedThemes));
Assert.assertFalse(
"The selected theme variant:" + variant[1]
"The selected theme variant:" + variantName
+ " should be removed from the component 'theme' attribute.",
updatedThemes.contains(variant[1]));
updatedThemes.contains(variantName));
}
}

Expand Down