Skip to content

Commit 028f4c8

Browse files
committed
Merge branch 'main' of https://github.com/FlodCoding/Weather-Challenge into main
2 parents 6e4b930 + 201c276 commit 028f4c8

File tree

7 files changed

+141
-3
lines changed

7 files changed

+141
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ A simple and beautiful weather app, intuitively and dynamically show the current
2424

2525
<img src="/results/screenshot_5.png" width="260">
2626

27+
28+
## Something Found
29+
- when start Ui testing, should stop Layout Inspector, seems conflict
30+
- can not add semantics inside Canvas, Canvas is the smallest unit
2731
## License
2832
```
2933
Copyright 2020 The Android Open Source Project
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.flod.androiddevchallenge
17+
18+
import androidx.compose.ui.test.junit4.createComposeRule
19+
import com.flod.androiddevchallenge.ui.component.TemperatureChart
20+
import org.junit.Ignore
21+
import org.junit.Rule
22+
import org.junit.Test
23+
24+
class CurveChartTest {
25+
26+
@get:Rule
27+
val composeTestRule = createComposeRule()
28+
29+
@Test
30+
@Ignore("Can not find Canvas content")
31+
fun loadData() {
32+
33+
val list = List(50) {
34+
Pair(it.toString(), (10..50).random())
35+
}
36+
composeTestRule.setContent {
37+
TemperatureChart(list = list)
38+
}
39+
}
40+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.flod.androiddevchallenge
17+
18+
import androidx.compose.ui.test.assertIsDisplayed
19+
import androidx.compose.ui.test.junit4.createComposeRule
20+
import androidx.compose.ui.test.onNodeWithContentDescription
21+
import androidx.compose.ui.test.onNodeWithTag
22+
import androidx.compose.ui.test.performClick
23+
import androidx.compose.ui.test.performGesture
24+
import androidx.compose.ui.test.swipeLeft
25+
import org.junit.Before
26+
import org.junit.Ignore
27+
import org.junit.Rule
28+
import org.junit.Test
29+
30+
class MainTest {
31+
32+
@get:Rule
33+
val composeTestRule = createComposeRule()
34+
35+
@Before
36+
fun setUp() {
37+
composeTestRule.launchApp()
38+
}
39+
40+
@Test
41+
@Ignore("passes locally but fail on CI")
42+
fun testDrawer() {
43+
// Open it
44+
composeTestRule.onNodeWithContentDescription("select location")
45+
.assertIsDisplayed().performClick()
46+
47+
composeTestRule.onNodeWithTag("LocationList").assertIsDisplayed()
48+
49+
// close Drawer using Gesture
50+
composeTestRule.onNodeWithTag("LocationList").performGesture {
51+
swipeLeft()
52+
}
53+
composeTestRule.onNodeWithContentDescription("select location").assertIsDisplayed()
54+
}
55+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.flod.androiddevchallenge
17+
18+
import androidx.compose.ui.test.junit4.ComposeContentTestRule
19+
20+
fun ComposeContentTestRule.launchApp() {
21+
setContent {
22+
MyApp()
23+
}
24+
}

app/src/main/java/com/flod/androiddevchallenge/ui/component/TemperatureChart.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import android.graphics.Paint
1919
import androidx.compose.foundation.Canvas
2020
import androidx.compose.foundation.horizontalScroll
2121
import androidx.compose.foundation.layout.fillMaxSize
22+
import androidx.compose.foundation.layout.padding
2223
import androidx.compose.foundation.rememberScrollState
2324
import androidx.compose.material.LocalContentColor
2425
import androidx.compose.material.MaterialTheme
@@ -34,8 +35,10 @@ import androidx.compose.ui.graphics.toArgb
3435
import androidx.compose.ui.layout.Layout
3536
import androidx.compose.ui.platform.LocalDensity
3637
import androidx.compose.ui.text.TextStyle
38+
import androidx.compose.ui.tooling.preview.Preview
3739
import androidx.compose.ui.unit.Dp
3840
import androidx.compose.ui.unit.dp
41+
import com.flod.androiddevchallenge.ui.theme.MyThemedPreview
3942

4043
/**
4144
* unfinished, maybe can more flexible
@@ -161,3 +164,14 @@ fun TemperatureChart(
161164
}
162165
}
163166
}
167+
168+
@Preview
169+
@Composable
170+
fun ChartLightPreview() {
171+
MyThemedPreview {
172+
val list = List(10) {
173+
Pair(it.toString(), (10..20).random())
174+
}
175+
TemperatureChart(Modifier.padding(30.dp), list)
176+
}
177+
}

app/src/main/java/com/flod/androiddevchallenge/ui/view/LocationList.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import androidx.compose.ui.res.painterResource
3636
import androidx.compose.ui.res.stringResource
3737
import androidx.compose.ui.semantics.contentDescription
3838
import androidx.compose.ui.semantics.semantics
39+
import androidx.compose.ui.semantics.testTag
3940
import androidx.compose.ui.tooling.preview.Preview
4041
import androidx.compose.ui.unit.dp
4142
import androidx.compose.ui.unit.sp
@@ -51,6 +52,7 @@ fun LocationList(list: List<Simple>, selected: Int = 0, onSelected: (Int, Simple
5152
Column(
5253
modifier = Modifier
5354
.padding(top = 50.dp)
55+
.semantics { testTag = "LocationList" }
5456
.selectableGroup(),
5557
horizontalAlignment = Alignment.CenterHorizontally
5658
) {

app/src/main/java/com/flod/androiddevchallenge/ui/view/Main.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ fun Main(viewModel: MainViewModel) {
8989
Modifier
9090
.padding(top = 40.dp, start = 20.dp, end = 20.dp)
9191
.fillMaxWidth(),
92-
data,
93-
coroutineScope,
94-
drawerState
92+
data, coroutineScope, drawerState
9593
)
9694

9795
Header(data, scrollState.value)
@@ -110,6 +108,7 @@ fun Title(modifier: Modifier, detail: Detail, coroutineScope: CoroutineScope, dr
110108

111109
Box(modifier = modifier) {
112110
// drawer open button
111+
113112
IconButton(
114113
modifier = Modifier.align(Alignment.CenterStart),
115114
onClick = {

0 commit comments

Comments
 (0)