-
Notifications
You must be signed in to change notification settings - Fork 108
[MBL-19452][Student] Dashboard Redesign Infrastructure #3372
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
90 changes: 90 additions & 0 deletions
90
...tudent/src/androidTest/java/com/instructure/student/ui/rendertests/DashboardScreenTest.kt
This file contains hidden or 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,90 @@ | ||
| package com.instructure.student.ui.rendertests | ||
|
|
||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.instructure.student.features.dashboard.compose.DashboardScreenContent | ||
| import com.instructure.student.features.dashboard.compose.DashboardUiState | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class DashboardScreenTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| @Test | ||
| fun testDashboardScreenShowsLoadingState() { | ||
| val mockUiState = DashboardUiState( | ||
| loading = true, | ||
| error = null, | ||
| refreshing = false, | ||
| onRefresh = {}, | ||
| onRetry = {} | ||
| ) | ||
|
|
||
| composeTestRule.setContent { | ||
| DashboardScreenContent(uiState = mockUiState) | ||
| } | ||
|
|
||
| composeTestRule.waitForIdle() | ||
hermannakos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| composeTestRule.onNodeWithTag("loading").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun testDashboardScreenShowsErrorState() { | ||
| val mockUiState = DashboardUiState( | ||
| loading = false, | ||
| error = "An error occurred", | ||
| refreshing = false, | ||
| onRefresh = {}, | ||
| onRetry = {} | ||
| ) | ||
|
|
||
| composeTestRule.setContent { | ||
| DashboardScreenContent(uiState = mockUiState) | ||
| } | ||
|
|
||
| composeTestRule.waitForIdle() | ||
| composeTestRule.onNodeWithTag("errorContent").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun testDashboardScreenShowsEmptyState() { | ||
| val mockUiState = DashboardUiState( | ||
| loading = false, | ||
| error = null, | ||
| refreshing = false, | ||
| onRefresh = {}, | ||
| onRetry = {} | ||
| ) | ||
|
|
||
| composeTestRule.setContent { | ||
| DashboardScreenContent(uiState = mockUiState) | ||
| } | ||
|
|
||
| composeTestRule.waitForIdle() | ||
| composeTestRule.onNodeWithTag("emptyContent").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun testDashboardScreenShowsRefreshIndicator() { | ||
| val mockUiState = DashboardUiState( | ||
| loading = false, | ||
| error = null, | ||
| refreshing = true, | ||
| onRefresh = {}, | ||
| onRetry = {} | ||
| ) | ||
|
|
||
| composeTestRule.setContent { | ||
| DashboardScreenContent(uiState = mockUiState) | ||
| } | ||
|
|
||
| composeTestRule.waitForIdle() | ||
| composeTestRule.onNodeWithTag("dashboardPullRefreshIndicator").assertIsDisplayed() | ||
| } | ||
| } | ||
This file contains hidden or 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
64 changes: 64 additions & 0 deletions
64
...ent/src/main/java/com/instructure/student/features/dashboard/compose/DashboardFragment.kt
This file contains hidden or 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,64 @@ | ||
| /* | ||
| * Copyright (C) 2024 - present Instructure, Inc. | ||
| * | ||
| * 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, version 3 of the License. | ||
| * | ||
| * 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.instructure.student.features.dashboard.compose | ||
|
|
||
| import android.os.Bundle | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import androidx.compose.ui.platform.ComposeView | ||
| import com.instructure.canvasapi2.models.CanvasContext | ||
| import com.instructure.interactions.router.Route | ||
| import com.instructure.pandautils.compose.CanvasTheme | ||
| import com.instructure.student.fragment.ParentFragment | ||
| import dagger.hilt.android.AndroidEntryPoint | ||
|
|
||
| @AndroidEntryPoint | ||
| class DashboardFragment : ParentFragment() { | ||
hermannakos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| override fun onCreateView( | ||
| inflater: LayoutInflater, | ||
| container: ViewGroup?, | ||
| savedInstanceState: Bundle? | ||
| ): View { | ||
| applyTheme() | ||
| return ComposeView(requireContext()).apply { | ||
| setContent { | ||
| CanvasTheme { | ||
| DashboardScreen() | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun title(): String = "" | ||
|
|
||
| override fun applyTheme() { | ||
| navigation?.attachNavigationDrawer(this, null) | ||
| } | ||
|
|
||
| companion object { | ||
| fun makeRoute(canvasContext: CanvasContext?) = | ||
| Route(DashboardFragment::class.java, canvasContext) | ||
|
|
||
| fun newInstance(route: Route): DashboardFragment { | ||
| val fragment = DashboardFragment() | ||
| fragment.arguments = route.arguments | ||
| return fragment | ||
| } | ||
| } | ||
| } | ||
117 changes: 117 additions & 0 deletions
117
...udent/src/main/java/com/instructure/student/features/dashboard/compose/DashboardScreen.kt
This file contains hidden or 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,117 @@ | ||
| /* | ||
| * Copyright (C) 2024 - present Instructure, Inc. | ||
| * | ||
| * 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, version 3 of the License. | ||
| * | ||
| * 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.instructure.student.features.dashboard.compose | ||
|
|
||
| import androidx.activity.compose.LocalActivity | ||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.material.ExperimentalMaterialApi | ||
| import androidx.compose.material.pullrefresh.PullRefreshIndicator | ||
| import androidx.compose.material.pullrefresh.pullRefresh | ||
| import androidx.compose.material.pullrefresh.rememberPullRefreshState | ||
| import androidx.compose.material3.Scaffold | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.collectAsState | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.testTag | ||
| import androidx.compose.ui.res.colorResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel | ||
| import com.instructure.pandautils.compose.composables.CanvasThemedAppBar | ||
| import com.instructure.pandautils.compose.composables.EmptyContent | ||
| import com.instructure.pandautils.compose.composables.ErrorContent | ||
| import com.instructure.pandautils.compose.composables.Loading | ||
| import com.instructure.student.R | ||
| import com.instructure.student.activity.NavigationActivity | ||
|
|
||
| @Composable | ||
| fun DashboardScreen() { | ||
| val viewModel: DashboardViewModel = hiltViewModel() | ||
| val uiState by viewModel.uiState.collectAsState() | ||
|
|
||
| DashboardScreenContent(uiState = uiState) | ||
| } | ||
|
|
||
| @OptIn(ExperimentalMaterialApi::class) | ||
| @Composable | ||
| fun DashboardScreenContent(uiState: DashboardUiState) { | ||
| val activity = LocalActivity.current | ||
| val pullRefreshState = rememberPullRefreshState( | ||
| refreshing = uiState.refreshing, | ||
| onRefresh = uiState.onRefresh | ||
| ) | ||
|
|
||
| Scaffold( | ||
| modifier = Modifier.background(colorResource(R.color.backgroundLightest)), | ||
| topBar = { | ||
| CanvasThemedAppBar( | ||
| title = stringResource(id = R.string.dashboard), | ||
| navIconRes = R.drawable.ic_hamburger, | ||
| navIconContentDescription = stringResource(id = R.string.navigation_drawer_open), | ||
| navigationActionClick = { (activity as? NavigationActivity)?.openNavigationDrawer() } | ||
| ) | ||
| } | ||
| ) { paddingValues -> | ||
| Box( | ||
| modifier = Modifier | ||
| .background(colorResource(R.color.backgroundLightest)) | ||
| .padding(paddingValues) | ||
| .pullRefresh(pullRefreshState) | ||
| .fillMaxSize() | ||
| ) { | ||
| when { | ||
| uiState.error != null -> { | ||
| ErrorContent( | ||
| errorMessage = uiState.error, | ||
| retryClick = uiState.onRetry, | ||
| modifier = Modifier | ||
| .fillMaxSize() | ||
| .testTag("errorContent") | ||
| ) | ||
| } | ||
|
|
||
| uiState.loading -> { | ||
| Loading(modifier = Modifier | ||
| .fillMaxSize() | ||
| .testTag("loading")) | ||
| } | ||
|
|
||
| else -> { | ||
| EmptyContent( | ||
hermannakos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| emptyMessage = stringResource(id = R.string.noCoursesSubtext), | ||
| imageRes = R.drawable.ic_panda_nocourses, | ||
| modifier = Modifier | ||
| .fillMaxSize() | ||
| .testTag("emptyContent") | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| PullRefreshIndicator( | ||
| refreshing = uiState.refreshing, | ||
| state = pullRefreshState, | ||
| modifier = Modifier | ||
| .align(Alignment.TopCenter) | ||
| .testTag("dashboardPullRefreshIndicator") | ||
| ) | ||
| } | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
...dent/src/main/java/com/instructure/student/features/dashboard/compose/DashboardUiState.kt
This file contains hidden or 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,25 @@ | ||
| /* | ||
| * Copyright (C) 2024 - present Instructure, Inc. | ||
| * | ||
| * 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, version 3 of the License. | ||
| * | ||
| * 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.instructure.student.features.dashboard.compose | ||
|
|
||
| data class DashboardUiState( | ||
hermannakos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val loading: Boolean = true, | ||
| val error: String? = null, | ||
| val refreshing: Boolean = false, | ||
| val onRefresh: () -> Unit = {}, | ||
| val onRetry: () -> Unit = {} | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.