summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/bottombar/ui/viewmodel/BottomBarViewModelTest.kt90
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/domain/interactor/ComponentsInteractorImplTest.kt122
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/composable/ComponentsFactoryTest.kt63
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/viewmodel/DefaultComponentsLayoutManagerTest.kt75
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/viewmodel/VolumePanelViewModelTest.kt117
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/ConfigurationControllerKosmos.kt2
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/VolumePanelKosmos.kt72
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/dagger/factory/KosmosVolumePanelComponentFactory.kt45
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/domain/TestComponentAvailabilityCriteria.kt (renamed from packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/domain/interactor/ComponentsInteractorTest.kt)11
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/ui/layout/FakeComponentsLayoutManager.kt37
10 files changed, 626 insertions, 8 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/bottombar/ui/viewmodel/BottomBarViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/bottombar/ui/viewmodel/BottomBarViewModelTest.kt
new file mode 100644
index 000000000000..471c8d851879
--- /dev/null
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/bottombar/ui/viewmodel/BottomBarViewModelTest.kt
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.volume.panel.component.bottombar.ui.viewmodel
+
+import android.content.Intent
+import android.provider.Settings
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.plugins.activityStarter
+import com.android.systemui.testKosmos
+import com.android.systemui.util.mockito.capture
+import com.android.systemui.util.mockito.eq
+import com.android.systemui.volume.panel.volumePanelViewModel
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.runTest
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentCaptor
+import org.mockito.Captor
+import org.mockito.Mockito.verify
+import org.mockito.junit.MockitoJUnit
+
+@OptIn(ExperimentalCoroutinesApi::class)
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class BottomBarViewModelTest : SysuiTestCase() {
+
+ @JvmField @Rule var mockitoRule = MockitoJUnit.rule()
+
+ @Captor private lateinit var intentCaptor: ArgumentCaptor<Intent>
+
+ private val kosmos = testKosmos()
+
+ private lateinit var underTest: BottomBarViewModel
+
+ private fun initUnderTest() {
+ underTest = with(kosmos) { BottomBarViewModel(activityStarter, volumePanelViewModel) }
+ }
+
+ @Test
+ fun onDoneClicked_hidesPanel() {
+ with(kosmos) {
+ testScope.runTest {
+ initUnderTest()
+ underTest.onDoneClicked()
+ runCurrent()
+
+ val volumePanelState by collectLastValue(volumePanelViewModel.volumePanelState)
+ assertThat(volumePanelState!!.isVisible).isFalse()
+ }
+ }
+ }
+
+ @Test
+ fun onSettingsClicked_dismissesPanelAndNavigatesToSettings() {
+ with(kosmos) {
+ testScope.runTest {
+ initUnderTest()
+ underTest.onSettingsClicked()
+
+ runCurrent()
+
+ val volumePanelState by collectLastValue(volumePanelViewModel.volumePanelState)
+ assertThat(volumePanelState!!.isVisible).isFalse()
+ verify(activityStarter).startActivity(capture(intentCaptor), eq(true))
+ assertThat(intentCaptor.value.action).isEqualTo(Settings.ACTION_SOUND_SETTINGS)
+ }
+ }
+ }
+}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/domain/interactor/ComponentsInteractorImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/domain/interactor/ComponentsInteractorImplTest.kt
new file mode 100644
index 000000000000..6256eece65dd
--- /dev/null
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/domain/interactor/ComponentsInteractorImplTest.kt
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.volume.panel.domain.interactor
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.volume.panel.availableCriteria
+import com.android.systemui.volume.panel.criteriaByKey
+import com.android.systemui.volume.panel.defaultCriteria
+import com.android.systemui.volume.panel.domain.model.ComponentModel
+import com.android.systemui.volume.panel.enabledComponents
+import com.android.systemui.volume.panel.shared.model.VolumePanelComponentKey
+import com.android.systemui.volume.panel.unavailableCriteria
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.test.runTest
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class ComponentsInteractorImplTest : SysuiTestCase() {
+
+ private val kosmos = Kosmos()
+
+ private lateinit var underTest: ComponentsInteractor
+
+ private fun initUnderTest() {
+ underTest =
+ with(kosmos) {
+ ComponentsInteractorImpl(
+ enabledComponents,
+ defaultCriteria,
+ testScope.backgroundScope,
+ criteriaByKey,
+ )
+ }
+ }
+
+ @Test
+ fun componentsAvailability_checked() {
+ with(kosmos) {
+ testScope.runTest {
+ enabledComponents =
+ setOf(
+ BOTTOM_BAR,
+ COMPONENT_1,
+ COMPONENT_2,
+ )
+ criteriaByKey =
+ mapOf(
+ BOTTOM_BAR to availableCriteria,
+ COMPONENT_1 to unavailableCriteria,
+ COMPONENT_2 to availableCriteria,
+ )
+ initUnderTest()
+
+ val components by collectLastValue(underTest.components)
+
+ assertThat(components)
+ .containsExactly(
+ ComponentModel(BOTTOM_BAR, true),
+ ComponentModel(COMPONENT_1, false),
+ ComponentModel(COMPONENT_2, true),
+ )
+ }
+ }
+ }
+
+ @Test
+ fun noCriteria_fallbackToDefaultCriteria() {
+ with(kosmos) {
+ testScope.runTest {
+ enabledComponents =
+ setOf(
+ BOTTOM_BAR,
+ COMPONENT_1,
+ COMPONENT_2,
+ )
+ criteriaByKey =
+ mapOf(
+ BOTTOM_BAR to availableCriteria,
+ COMPONENT_2 to availableCriteria,
+ )
+ defaultCriteria = unavailableCriteria
+ initUnderTest()
+
+ val components by collectLastValue(underTest.components)
+
+ assertThat(components)
+ .containsExactly(
+ ComponentModel(BOTTOM_BAR, true),
+ ComponentModel(COMPONENT_1, false),
+ ComponentModel(COMPONENT_2, true),
+ )
+ }
+ }
+ }
+
+ private companion object {
+ const val BOTTOM_BAR: VolumePanelComponentKey = "test_bottom_bar"
+ const val COMPONENT_1: VolumePanelComponentKey = "test_component:1"
+ const val COMPONENT_2: VolumePanelComponentKey = "test_component:2"
+ }
+}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/composable/ComponentsFactoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/composable/ComponentsFactoryTest.kt
new file mode 100644
index 000000000000..3dbf23e3dc58
--- /dev/null
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/composable/ComponentsFactoryTest.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.volume.panel.ui.composable
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.testKosmos
+import com.android.systemui.volume.panel.componentByKey
+import com.android.systemui.volume.panel.mockVolumePanelUiComponentProvider
+import com.android.systemui.volume.panel.shared.model.VolumePanelComponentKey
+import com.google.common.truth.Truth
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class ComponentsFactoryTest : SysuiTestCase() {
+
+ private val kosmos = testKosmos()
+
+ private lateinit var underTest: ComponentsFactory
+
+ private fun initUnderTest() {
+ underTest = ComponentsFactory(kosmos.componentByKey)
+ }
+
+ @Test
+ fun existingComponent_created() {
+ kosmos.componentByKey = mapOf(TEST_COMPONENT to kosmos.mockVolumePanelUiComponentProvider)
+ initUnderTest()
+
+ val component = underTest.createComponent(TEST_COMPONENT)
+
+ Truth.assertThat(component).isNotNull()
+ }
+
+ @Test(expected = IllegalArgumentException::class)
+ fun componentAbsence_throws() {
+ kosmos.componentByKey = emptyMap()
+ initUnderTest()
+
+ underTest.createComponent(TEST_COMPONENT)
+ }
+
+ private companion object {
+ const val TEST_COMPONENT: VolumePanelComponentKey = "test_component"
+ }
+}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/viewmodel/DefaultComponentsLayoutManagerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/viewmodel/DefaultComponentsLayoutManagerTest.kt
index e5fb9426e8e2..35d96989e35d 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/viewmodel/DefaultComponentsLayoutManagerTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/viewmodel/DefaultComponentsLayoutManagerTest.kt
@@ -16,7 +16,78 @@
package com.android.systemui.volume.panel.ui.viewmodel
-class DefaultComponentsLayoutManagerTest {
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.testKosmos
+import com.android.systemui.volume.panel.mockVolumePanelUiComponent
+import com.android.systemui.volume.panel.shared.model.VolumePanelComponentKey
+import com.android.systemui.volume.panel.ui.layout.ComponentsLayoutManager
+import com.android.systemui.volume.panel.ui.layout.DefaultComponentsLayoutManager
+import com.google.common.truth.Truth
+import org.junit.Test
+import org.junit.runner.RunWith
- // TODO(b/318080198) Write tests
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class DefaultComponentsLayoutManagerTest : SysuiTestCase() {
+
+ private val kosmos = testKosmos()
+ private val underTest: ComponentsLayoutManager = DefaultComponentsLayoutManager()
+
+ @Test
+ fun bottomBar_isSet() {
+ val bottomBarComponentState =
+ ComponentState(BOTTOM_BAR, kosmos.mockVolumePanelUiComponent, false)
+ val layout =
+ underTest.layout(
+ VolumePanelState(0, false),
+ setOf(
+ bottomBarComponentState,
+ ComponentState(COMPONENT_1, kosmos.mockVolumePanelUiComponent, false),
+ ComponentState(COMPONENT_2, kosmos.mockVolumePanelUiComponent, false),
+ )
+ )
+
+ Truth.assertThat(layout.bottomBarComponent).isEqualTo(bottomBarComponentState)
+ }
+
+ @Test
+ fun componentsAreInOrder() {
+ val bottomBarComponentState =
+ ComponentState(BOTTOM_BAR, kosmos.mockVolumePanelUiComponent, false)
+ val component1State = ComponentState(COMPONENT_1, kosmos.mockVolumePanelUiComponent, false)
+ val component2State = ComponentState(COMPONENT_2, kosmos.mockVolumePanelUiComponent, false)
+ val layout =
+ underTest.layout(
+ VolumePanelState(0, false),
+ setOf(
+ bottomBarComponentState,
+ component1State,
+ component2State,
+ )
+ )
+
+ Truth.assertThat(layout.contentComponents[0]).isEqualTo(component1State)
+ Truth.assertThat(layout.contentComponents[1]).isEqualTo(component2State)
+ }
+
+ @Test(expected = IllegalStateException::class)
+ fun bottomBarAbsence_throwsException() {
+ val component1State = ComponentState(COMPONENT_1, kosmos.mockVolumePanelUiComponent, false)
+ val component2State = ComponentState(COMPONENT_2, kosmos.mockVolumePanelUiComponent, false)
+ underTest.layout(
+ VolumePanelState(0, false),
+ setOf(
+ component1State,
+ component2State,
+ )
+ )
+ }
+
+ private companion object {
+ const val BOTTOM_BAR: VolumePanelComponentKey = "bottom_bar"
+ const val COMPONENT_1: VolumePanelComponentKey = "test_component:1"
+ const val COMPONENT_2: VolumePanelComponentKey = "test_component:2"
+ }
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/viewmodel/VolumePanelViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/viewmodel/VolumePanelViewModelTest.kt
index 9795237a3e7e..c4c9cc608afa 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/viewmodel/VolumePanelViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/ui/viewmodel/VolumePanelViewModelTest.kt
@@ -16,7 +16,120 @@
package com.android.systemui.volume.panel.ui.viewmodel
-class VolumePanelViewModelTest {
+import android.content.res.Configuration
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.statusbar.policy.fakeConfigurationController
+import com.android.systemui.testKosmos
+import com.android.systemui.volume.panel.componentByKey
+import com.android.systemui.volume.panel.componentsLayoutManager
+import com.android.systemui.volume.panel.criteriaByKey
+import com.android.systemui.volume.panel.dagger.factory.KosmosVolumePanelComponentFactory
+import com.android.systemui.volume.panel.mockVolumePanelUiComponentProvider
+import com.android.systemui.volume.panel.shared.model.VolumePanelComponentKey
+import com.android.systemui.volume.panel.ui.layout.FakeComponentsLayoutManager
+import com.android.systemui.volume.panel.unavailableCriteria
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.runTest
+import org.junit.Test
+import org.junit.runner.RunWith
- // TODO(b/318080198) Write tests
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+@OptIn(ExperimentalCoroutinesApi::class)
+class VolumePanelViewModelTest : SysuiTestCase() {
+
+ private val kosmos =
+ testKosmos().apply {
+ componentsLayoutManager = FakeComponentsLayoutManager { it.key == BOTTOM_BAR }
+ }
+
+ private val testableResources = context.orCreateTestableResources
+
+ private lateinit var underTest: VolumePanelViewModel
+
+ private fun initUnderTest() {
+ underTest =
+ VolumePanelViewModel(
+ testableResources.resources,
+ KosmosVolumePanelComponentFactory(kosmos),
+ kosmos.fakeConfigurationController,
+ )
+ }
+
+ @Test
+ fun dismissingPanel_changesVisibility() {
+ with(kosmos) {
+ testScope.runTest {
+ initUnderTest()
+ assertThat(underTest.volumePanelState.value.isVisible).isTrue()
+
+ underTest.dismissPanel()
+ runCurrent()
+
+ assertThat(underTest.volumePanelState.value.isVisible).isFalse()
+ }
+ }
+ }
+
+ @Test
+ fun orientationChanges_panelOrientationChanges() {
+ with(kosmos) {
+ testScope.runTest {
+ initUnderTest()
+ val volumePanelState by collectLastValue(underTest.volumePanelState)
+ testableResources.overrideConfiguration(
+ Configuration().apply { orientation = Configuration.ORIENTATION_PORTRAIT }
+ )
+ assertThat(volumePanelState!!.orientation)
+ .isEqualTo(Configuration.ORIENTATION_PORTRAIT)
+
+ fakeConfigurationController.onConfigurationChanged(
+ Configuration().apply { orientation = Configuration.ORIENTATION_LANDSCAPE }
+ )
+ runCurrent()
+
+ assertThat(volumePanelState!!.orientation)
+ .isEqualTo(Configuration.ORIENTATION_LANDSCAPE)
+ }
+ }
+ }
+
+ @Test
+ fun components_areReturned() {
+ with(kosmos) {
+ testScope.runTest {
+ componentByKey =
+ mapOf(
+ COMPONENT_1 to mockVolumePanelUiComponentProvider,
+ COMPONENT_2 to mockVolumePanelUiComponentProvider,
+ BOTTOM_BAR to mockVolumePanelUiComponentProvider,
+ )
+ criteriaByKey = mapOf(COMPONENT_2 to unavailableCriteria)
+ initUnderTest()
+
+ val componentsLayout by collectLastValue(underTest.componentsLayout)
+ runCurrent()
+
+ assertThat(componentsLayout!!.contentComponents).hasSize(2)
+ assertThat(componentsLayout!!.contentComponents[0].key).isEqualTo(COMPONENT_1)
+ assertThat(componentsLayout!!.contentComponents[0].isVisible).isTrue()
+ assertThat(componentsLayout!!.contentComponents[1].key).isEqualTo(COMPONENT_2)
+ assertThat(componentsLayout!!.contentComponents[1].isVisible).isFalse()
+ assertThat(componentsLayout!!.bottomBarComponent.key).isEqualTo(BOTTOM_BAR)
+ assertThat(componentsLayout!!.bottomBarComponent.isVisible).isTrue()
+ }
+ }
+ }
+
+ private companion object {
+ const val BOTTOM_BAR: VolumePanelComponentKey = "test_bottom_bar"
+ const val COMPONENT_1: VolumePanelComponentKey = "test_component:1"
+ const val COMPONENT_2: VolumePanelComponentKey = "test_component:2"
+ }
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/ConfigurationControllerKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/ConfigurationControllerKosmos.kt
index 18a2f9482df8..33ed7e61de4d 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/ConfigurationControllerKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/ConfigurationControllerKosmos.kt
@@ -20,3 +20,5 @@ import com.android.systemui.kosmos.Kosmos
import com.android.systemui.util.mockito.mock
val Kosmos.configurationController by Kosmos.Fixture { mock<ConfigurationController>() }
+val Kosmos.fakeConfigurationController: FakeConfigurationController by
+ Kosmos.Fixture { FakeConfigurationController() }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/VolumePanelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/VolumePanelKosmos.kt
new file mode 100644
index 000000000000..d3410737a432
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/VolumePanelKosmos.kt
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.volume.panel
+
+import android.content.res.mainResources
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.statusbar.policy.fakeConfigurationController
+import com.android.systemui.util.mockito.mock
+import com.android.systemui.volume.panel.dagger.factory.KosmosVolumePanelComponentFactory
+import com.android.systemui.volume.panel.domain.ComponentAvailabilityCriteria
+import com.android.systemui.volume.panel.domain.TestComponentAvailabilityCriteria
+import com.android.systemui.volume.panel.domain.interactor.ComponentsInteractor
+import com.android.systemui.volume.panel.domain.interactor.ComponentsInteractorImpl
+import com.android.systemui.volume.panel.shared.model.VolumePanelComponentKey
+import com.android.systemui.volume.panel.shared.model.VolumePanelUiComponent
+import com.android.systemui.volume.panel.ui.composable.ComponentsFactory
+import com.android.systemui.volume.panel.ui.layout.ComponentsLayoutManager
+import com.android.systemui.volume.panel.ui.viewmodel.VolumePanelViewModel
+import javax.inject.Provider
+
+val Kosmos.mockVolumePanelUiComponent: VolumePanelUiComponent by Kosmos.Fixture { mock {} }
+val Kosmos.mockVolumePanelUiComponentProvider: Provider<VolumePanelUiComponent> by
+ Kosmos.Fixture { Provider { mockVolumePanelUiComponent } }
+var Kosmos.componentByKey: Map<VolumePanelComponentKey, Provider<VolumePanelUiComponent>> by
+ Kosmos.Fixture { emptyMap() }
+val Kosmos.componentsFactory: ComponentsFactory by
+ Kosmos.Fixture { ComponentsFactory(componentByKey) }
+
+var Kosmos.componentsLayoutManager: ComponentsLayoutManager by Kosmos.Fixture()
+var Kosmos.enabledComponents: Collection<VolumePanelComponentKey> by
+ Kosmos.Fixture { componentByKey.keys }
+val Kosmos.unavailableCriteria: Provider<ComponentAvailabilityCriteria> by
+ Kosmos.Fixture { Provider { TestComponentAvailabilityCriteria(false) } }
+val Kosmos.availableCriteria: Provider<ComponentAvailabilityCriteria> by
+ Kosmos.Fixture { Provider { TestComponentAvailabilityCriteria(true) } }
+var Kosmos.defaultCriteria: Provider<ComponentAvailabilityCriteria> by
+ Kosmos.Fixture { availableCriteria }
+var Kosmos.criteriaByKey: Map<VolumePanelComponentKey, Provider<ComponentAvailabilityCriteria>> by
+ Kosmos.Fixture { emptyMap() }
+var Kosmos.componentsInteractor: ComponentsInteractor by
+ Kosmos.Fixture {
+ ComponentsInteractorImpl(
+ enabledComponents,
+ defaultCriteria,
+ testScope.backgroundScope,
+ criteriaByKey,
+ )
+ }
+
+var Kosmos.volumePanelViewModel: VolumePanelViewModel by
+ Kosmos.Fixture {
+ VolumePanelViewModel(
+ mainResources,
+ KosmosVolumePanelComponentFactory(this),
+ fakeConfigurationController,
+ )
+ }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/dagger/factory/KosmosVolumePanelComponentFactory.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/dagger/factory/KosmosVolumePanelComponentFactory.kt
new file mode 100644
index 000000000000..49041ed0d652
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/dagger/factory/KosmosVolumePanelComponentFactory.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.volume.panel.dagger.factory
+
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.volume.panel.componentsFactory
+import com.android.systemui.volume.panel.componentsInteractor
+import com.android.systemui.volume.panel.componentsLayoutManager
+import com.android.systemui.volume.panel.dagger.VolumePanelComponent
+import com.android.systemui.volume.panel.domain.interactor.ComponentsInteractor
+import com.android.systemui.volume.panel.ui.composable.ComponentsFactory
+import com.android.systemui.volume.panel.ui.layout.ComponentsLayoutManager
+import com.android.systemui.volume.panel.ui.viewmodel.VolumePanelViewModel
+import kotlinx.coroutines.CoroutineScope
+
+class KosmosVolumePanelComponentFactory(private val kosmos: Kosmos) : VolumePanelComponentFactory {
+
+ override fun create(viewModel: VolumePanelViewModel): VolumePanelComponent =
+ object : VolumePanelComponent {
+
+ override fun coroutineScope(): CoroutineScope = kosmos.testScope.backgroundScope
+
+ override fun componentsInteractor(): ComponentsInteractor = kosmos.componentsInteractor
+
+ override fun componentsFactory(): ComponentsFactory = kosmos.componentsFactory
+
+ override fun componentsLayoutManager(): ComponentsLayoutManager =
+ kosmos.componentsLayoutManager
+ }
+}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/domain/interactor/ComponentsInteractorTest.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/domain/TestComponentAvailabilityCriteria.kt
index dbff63f355c8..5ab92745ae69 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/domain/interactor/ComponentsInteractorTest.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/domain/TestComponentAvailabilityCriteria.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2023 The Android Open Source Project
+ * Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,9 +14,12 @@
* limitations under the License.
*/
-package com.android.systemui.volume.panel.domain.interactor
+package com.android.systemui.volume.panel.domain
-class ComponentsInteractorTest {
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.flowOf
- // TODO(b/318080198) Write tests
+class TestComponentAvailabilityCriteria(val isAvailable: Boolean) : ComponentAvailabilityCriteria {
+
+ override fun isAvailable(): Flow<Boolean> = flowOf(isAvailable)
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/ui/layout/FakeComponentsLayoutManager.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/ui/layout/FakeComponentsLayoutManager.kt
new file mode 100644
index 000000000000..655d8f7ad952
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/ui/layout/FakeComponentsLayoutManager.kt
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.volume.panel.ui.layout
+
+import com.android.systemui.volume.panel.ui.viewmodel.ComponentState
+import com.android.systemui.volume.panel.ui.viewmodel.VolumePanelState
+
+class FakeComponentsLayoutManager(
+ private val isBottomBar: (components: ComponentState) -> Boolean
+) : ComponentsLayoutManager {
+
+ override fun layout(
+ volumePanelState: VolumePanelState,
+ components: Collection<ComponentState>
+ ): ComponentsLayout {
+ return ComponentsLayout(
+ components
+ .filter { componentState -> !isBottomBar(componentState) }
+ .sortedBy { it.key },
+ components.find(isBottomBar)!!,
+ )
+ }
+}