Skip to content

Commit

Permalink
test: add test to label formatter used in drilldown (#4215) (#4317)
Browse files Browse the repository at this point in the history
Co-authored-by: Diego Cardoso <diego@vaadin.com>
Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
  • Loading branch information
3 people committed Dec 8, 2022
1 parent 0fe01f9 commit 7d6b3d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.vaadin.flow.component.charts.model.DataSeriesItem;
import com.vaadin.flow.component.charts.model.DrilldownCallback;
import com.vaadin.flow.component.charts.model.PlotOptionsColumn;
import com.vaadin.flow.component.charts.model.PlotOptionsSeries;
import com.vaadin.flow.component.charts.model.Series;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.ListItem;
Expand Down Expand Up @@ -93,6 +94,13 @@ private void log(String newStringValue) {
private Series getPointDrilldown(DataSeriesItem point) {
String prefix = point.getId() + "_";
DataSeries series = new DataSeries(prefix + "drill");

final PlotOptionsSeries plotOptions = new PlotOptionsSeries();
series.setPlotOptions(plotOptions);
DataLabels dataLabels = new DataLabels(true);
dataLabels.setFormatter("return this.key.toUpperCase();");
plotOptions.setDataLabels(dataLabels);

createItems(prefix).forEach(series::addItemWithDrilldown);
return series;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.vaadin.flow.component.charts.examples.AbstractChartExample;
import com.vaadin.flow.component.charts.examples.column.ColumnWithLazyMultiLevelDrilldownCallbackTests;
import com.vaadin.flow.component.charts.testbench.ChartElement;
import com.vaadin.testbench.TestBenchElement;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -64,6 +65,21 @@ public void test() throws AssertionError {
assertLastLogText("ChartDrillupEvent");
}

@Test
public void drilldownSeriesWithLabelFormatter_formatterCallbackIsCalled() {
ChartElement chart = $(ChartElement.class).first();

// Set new callback
findElement(By.id("setNew")).click();
// Showing nested drilldowns
clickDrilldownPoint(chart, 0);

// Get the first label
TestBenchElement label = getElementFromShadowRoot(chart,
".highcharts-data-labels.highcharts-series-0 tspan");
assertEquals("ITEM1_1", label.getText());
}

private void clickDrilldownPoint(ChartElement chart, int index) {
getElementFromShadowRoot(chart, ".highcharts-drilldown-point", index)
.click();
Expand Down

0 comments on commit 7d6b3d6

Please sign in to comment.