-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from AkYML/feature/merge_experiments
merge from experiments
- Loading branch information
Showing
45 changed files
with
4,480 additions
and
674 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
YChartsLib/src/androidTest/java/co/yml/charts/barchart/StackedBarChartTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
package co.yml.charts.barchart | ||
|
||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.test.* | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.unit.dp | ||
import co.yml.charts.axis.AxisData | ||
import co.yml.charts.common.extensions.getMaxElementInYAxis | ||
import co.yml.charts.common.model.Point | ||
import co.yml.charts.ui.barchart.StackedBarChart | ||
import co.yml.charts.ui.barchart.models.* | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class StackedBarChartTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
private val barSize = 3 | ||
private val listSize = 5 | ||
private val groupBarData = getGroupBarChartTestData(listSize, barSize) | ||
private val yStepSize = 10 | ||
|
||
private val xAxisData = AxisData.Builder() | ||
.axisStepSize(30.dp) | ||
.steps(listSize - 1) | ||
.startDrawPadding(48.dp) | ||
.labelData { index -> "C $index" } | ||
.build() | ||
|
||
private val yAxisData = AxisData.Builder() | ||
.steps(yStepSize) | ||
.labelAndAxisLinePadding(20.dp) | ||
.axisOffset(20.dp) | ||
.labelData { index -> | ||
val valueList = mutableListOf<Float>() | ||
groupBarData.map { groupBar -> | ||
var yMax = 0f | ||
groupBar.barList.forEach { | ||
yMax += it.point.y | ||
} | ||
valueList.add(yMax) | ||
} | ||
val maxElementInYAxis = getMaxElementInYAxis(valueList.maxOrNull() ?: 0f, yStepSize) | ||
|
||
(index * (maxElementInYAxis / yStepSize)).toString() | ||
} | ||
.topPadding(36.dp) | ||
.build() | ||
|
||
private val colorPaletteList = listOf(Color.Black, Color.Yellow, Color.Blue) | ||
private val groupBarPlotData = BarPlotData( | ||
groupBarList = groupBarData, | ||
barStyle = BarStyle( | ||
barWidth = 35.dp, | ||
selectionHighlightData = SelectionHighlightData( | ||
isHighlightFullBar = true, | ||
groupBarPopUpLabel = { name, value -> | ||
"Name" | ||
} | ||
) | ||
), | ||
barColorPaletteList = colorPaletteList | ||
) | ||
private val groupBarChartData = GroupBarChartData( | ||
barPlotData = groupBarPlotData, | ||
xAxisData = xAxisData, | ||
yAxisData = yAxisData, | ||
paddingBetweenStackedBars = 4.dp | ||
) | ||
|
||
private fun startStackedBarChart(isTalkBackEnabled: Boolean = false) { | ||
composeTestRule.setContent { | ||
StackedBarChart( | ||
modifier = Modifier, | ||
groupBarChartData = groupBarChartData, | ||
isTalkBackEnabled | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun assertIfStackedBarChartIsDisplayed() { | ||
|
||
startStackedBarChart() | ||
composeTestRule.onNodeWithTag("stacked_bar_chart", useUnmergedTree = true) | ||
.assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun assertIfCanvasIsDisplayed() { | ||
startStackedBarChart() | ||
|
||
composeTestRule.onNodeWithTag("chart_canvas", useUnmergedTree = true) | ||
.assertExists() | ||
} | ||
|
||
@Test | ||
fun assertIfXAxisIsDisplayed() { | ||
startStackedBarChart() | ||
|
||
composeTestRule.onNodeWithTag("x_axis", useUnmergedTree = true) | ||
.assertExists() | ||
} | ||
|
||
@Test | ||
fun assertIfYAxisIsDisplayed() { | ||
startStackedBarChart() | ||
|
||
composeTestRule.onNodeWithTag("y_axis", useUnmergedTree = true) | ||
.assertExists() | ||
} | ||
|
||
|
||
@Test | ||
fun assertIfStackedBarClicked() { | ||
startStackedBarChart() | ||
|
||
composeTestRule.onNode(hasAnyChild(hasClickAction()), useUnmergedTree = true) | ||
.onChildren() | ||
.onFirst() | ||
.performClick() | ||
} | ||
|
||
@Test | ||
fun assertIfStackedBarChartHasCorrectBarData() { | ||
startStackedBarChart(isTalkBackEnabled = true) | ||
|
||
composeTestRule.onNodeWithText("Bar at 0 with label B0 has value 20.00") | ||
.assertExists() | ||
} | ||
|
||
|
||
@Test | ||
fun assertIfStackedBarHasChartHasCorrectXAxisLabel() { | ||
startStackedBarChart(isTalkBackEnabled = true) | ||
|
||
composeTestRule.onNodeWithText("X Axis label C 0") | ||
.assertExists() | ||
} | ||
|
||
@Test | ||
fun assertIfStackedBarHasChartHasCorrectPrimaryCategoryData() { | ||
startStackedBarChart(isTalkBackEnabled = true) | ||
|
||
composeTestRule.onNodeWithTag("AccessibilityBottomSheet List") | ||
.onChildren() | ||
.assertCountEquals(5) | ||
} | ||
|
||
@Test | ||
fun assertIfPrimaryCategoryHasCorrectSecondaryVariableData() { | ||
startStackedBarChart(isTalkBackEnabled = true) | ||
|
||
composeTestRule.onNodeWithText("X Axis label C 0") | ||
.onSiblings() | ||
.assertCountEquals(4) | ||
|
||
} | ||
} | ||
|
||
|
||
fun getGroupBarChartTestData(listSize: Int, barSize: Int): List<GroupBar> { | ||
val list = mutableListOf<GroupBar>() | ||
for (index in 0 until listSize) { | ||
val barList = mutableListOf<BarData>() | ||
for (i in 0 until barSize) { | ||
val barValue = (((i + 1) * 10) + ((index + 1) * 10)).toFloat() | ||
barList.add( | ||
BarData( | ||
Point( | ||
index.toFloat(), | ||
barValue | ||
), | ||
label = "B$i", | ||
description = "Bar at $index with label B$i has value ${ | ||
String.format( | ||
"%.2f", barValue | ||
) | ||
}" | ||
) | ||
) | ||
} | ||
list.add(GroupBar(index.toString(), barList)) | ||
} | ||
return list | ||
} |
120 changes: 120 additions & 0 deletions
120
YChartsLib/src/androidTest/java/co/yml/charts/wavechart/WaveChartTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package co.yml.charts.wavechart | ||
|
||
import android.graphics.Typeface | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.drawscope.Stroke | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.unit.dp | ||
import co.yml.charts.axis.AxisData | ||
import co.yml.charts.common.extensions.formatToSinglePrecision | ||
import co.yml.charts.common.model.Point | ||
import co.yml.charts.ui.linechart.getMappingPointsToGraph | ||
import co.yml.charts.ui.linechart.model.LineStyle | ||
import co.yml.charts.ui.linechart.model.LineType | ||
import co.yml.charts.ui.linechart.model.SelectionHighlightPoint | ||
import co.yml.charts.ui.linechart.model.SelectionHighlightPopUp | ||
import co.yml.charts.ui.linechart.model.ShadowUnderLine | ||
import co.yml.charts.ui.wavechart.WaveChart | ||
import co.yml.charts.ui.wavechart.model.Wave | ||
import co.yml.charts.ui.wavechart.model.WaveChartData | ||
import co.yml.charts.ui.wavechart.model.WavePlotData | ||
import org.junit.Assert | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class WaveChartTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
private val pointsData = listOf( | ||
Point(0f, 0f), | ||
Point(1f, -3f), | ||
Point(2f, -5f), | ||
Point(3f, -2f), | ||
Point(4f, 2f), | ||
Point(5f, 5f), | ||
Point(6f, 4f), | ||
Point(7f, 0f), | ||
Point(8f, -1f), | ||
Point(9f, -3f), | ||
Point(10f, 0f), | ||
) | ||
private val steps = 10 | ||
private val xAxisData = AxisData.Builder() | ||
.axisStepSize(40.dp) | ||
.steps(pointsData.size - 1) | ||
.labelData { i -> i.toString() } | ||
.labelAndAxisLinePadding(15.dp) | ||
.axisLineColor(Color.Red) | ||
.build() | ||
private val yAxisData = AxisData.Builder() | ||
.steps(steps) | ||
.labelData { i -> | ||
val yMin = pointsData.minOf { it.y } | ||
val yMax = pointsData.maxOf { it.y } | ||
val yScale = (yMax - yMin) / steps | ||
((i * yScale) + yMin).formatToSinglePrecision() | ||
} | ||
.axisLineColor(Color.Red) | ||
.labelAndAxisLinePadding(20.dp) | ||
.bottomPadding(15.dp) | ||
.build() | ||
private val data = WaveChartData( | ||
wavePlotData = WavePlotData( | ||
lines = listOf( | ||
Wave( | ||
dataPoints = pointsData, | ||
waveStyle = LineStyle( | ||
lineType = LineType.SmoothCurve(isDotted = true), | ||
color = Color.Green | ||
), | ||
shadowUnderLine = ShadowUnderLine(), | ||
selectionHighlightPoint = SelectionHighlightPoint( | ||
color = Color.Green | ||
), | ||
selectionHighlightPopUp = SelectionHighlightPopUp( | ||
backgroundColor = Color.Black, | ||
backgroundStyle = Stroke(2f), | ||
labelColor = Color.Red, | ||
labelTypeface = Typeface.DEFAULT_BOLD | ||
) | ||
) | ||
) | ||
), | ||
xAxisData = xAxisData, | ||
yAxisData = yAxisData | ||
) | ||
|
||
@Test | ||
fun assertIfWaveChartIsDisplayed() { | ||
composeTestRule.setContent { | ||
WaveChart(modifier = Modifier, waveChartData = data) | ||
} | ||
composeTestRule.onNodeWithTag("wave_chart").assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun assertIfScrollableContainerIsDisplayed() { | ||
composeTestRule.setContent { | ||
WaveChart(modifier = Modifier, waveChartData = data) | ||
} | ||
composeTestRule.onNodeWithTag("scrollable_container").assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun getMappingPointsToGraphTest() { | ||
val mappedPoints = getMappingPointsToGraph( | ||
pointsData, 0f, 1f, 0f, 0f, 0f, 10f, 1f | ||
) | ||
val expectedResult = mutableListOf<Offset>() | ||
pointsData.forEach { | ||
expectedResult.add(Offset(it.x, (10f - it.y))) | ||
} | ||
Assert.assertEquals(expectedResult, mappedPoints) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="co.yml.charts.components"/> | ||
<manifest/> |
Oops, something went wrong.