Loading packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/interactor/DynamicIconTilesInteractorTest.kt 0 → 100644 +81 −0 Original line number Original line Diff line number Diff line /* * 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.qs.panels.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.testScope import com.android.systemui.lifecycle.activateIn import com.android.systemui.qs.panels.data.repository.DefaultLargeTilesRepository import com.android.systemui.qs.panels.data.repository.defaultLargeTilesRepository import com.android.systemui.qs.panels.data.repository.qsPreferencesRepository import com.android.systemui.qs.pipeline.domain.interactor.currentTilesInteractor import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class DynamicIconTilesInteractorTest : SysuiTestCase() { private val kosmos = testKosmos().apply { defaultLargeTilesRepository = object : DefaultLargeTilesRepository { override val defaultLargeTiles: Set<TileSpec> = setOf(largeTile) } currentTilesInteractor.setTiles(listOf(largeTile, smallTile)) } private lateinit var underTest: DynamicIconTilesInteractor @Before fun setUp() { with(kosmos) { underTest = dynamicIconTilesInteractorFactory.create() underTest.activateIn(testScope) } } @OptIn(ExperimentalCoroutinesApi::class) @Test fun removingTile_updatesSharedPreferences() = with(kosmos) { testScope.runTest { val latest by collectLastValue(qsPreferencesRepository.largeTilesSpecs) runCurrent() // Remove the large tile from the current tiles currentTilesInteractor.removeTiles(listOf(largeTile)) runCurrent() // Assert that it resized to small assertThat(latest).doesNotContain(largeTile) } } private companion object { private val largeTile = TileSpec.create("large") private val smallTile = TileSpec.create("small") } } packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/interactor/IconTilesInteractorTest.kt +0 −17 Original line number Original line Diff line number Diff line Loading @@ -96,23 +96,6 @@ class IconTilesInteractorTest : SysuiTestCase() { } } } } @OptIn(ExperimentalCoroutinesApi::class) @Test fun removingTile_updatesSharedPreferences() = with(kosmos) { testScope.runTest { val latest by collectLastValue(qsPreferencesRepository.largeTilesSpecs) runCurrent() // Remove the large tile from the current tiles currentTilesInteractor.removeTiles(listOf(largeTile)) runCurrent() // Assert that it resized to small assertThat(latest).doesNotContain(largeTile) } } @OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class) @Test @Test fun resizingNonCurrentTile_doesNothing() = fun resizingNonCurrentTile_doesNothing() = Loading packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/interactor/SizedTilesResetInteractorTest.kt 0 → 100644 +82 −0 Original line number Original line Diff line number Diff line /* * 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.qs.panels.domain.interactor import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.testScope import com.android.systemui.qs.panels.data.repository.DefaultLargeTilesRepository import com.android.systemui.qs.panels.data.repository.defaultLargeTilesRepository import com.android.systemui.qs.pipeline.data.repository.FakeDefaultTilesRepository import com.android.systemui.qs.pipeline.data.repository.fakeDefaultTilesRepository import com.android.systemui.qs.pipeline.domain.interactor.currentTilesInteractor import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.testKosmos 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 @SmallTest @RunWith(AndroidJUnit4::class) class SizedTilesResetInteractorTest : SysuiTestCase() { private val kosmos = testKosmos().apply { defaultLargeTilesRepository = object : DefaultLargeTilesRepository { override val defaultLargeTiles: Set<TileSpec> = setOf(largeTile) } fakeDefaultTilesRepository = FakeDefaultTilesRepository(listOf(smallTile, largeTile)) } private val underTest = with(kosmos) { sizedTilesResetInteractor } @OptIn(ExperimentalCoroutinesApi::class) @Test fun changeTiles_resetsCorrectly() { with(kosmos) { testScope.runTest { // Change current tiles and large tiles currentTilesInteractor.setTiles(listOf(largeTile, newTile)) iconTilesInteractor.setLargeTiles(setOf(newTile)) runCurrent() // Assert both current tiles and large tiles changed assertThat(currentTilesInteractor.currentTilesSpecs) .containsExactly(largeTile, newTile) assertThat(iconTilesInteractor.largeTilesSpecs.value).containsExactly(newTile) // Reset to default underTest.reset() runCurrent() // Assert both current tiles and large tiles are back to the initial state assertThat(currentTilesInteractor.currentTilesSpecs) .containsExactly(largeTile, smallTile) assertThat(iconTilesInteractor.largeTilesSpecs.value).containsExactly(largeTile) } } } private companion object { private val largeTile = TileSpec.create("large") private val smallTile = TileSpec.create("small") private val newTile = TileSpec.create("newTile") } } packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/data/repository/TileSpecSettingsRepositoryTest.kt +16 −1 Original line number Original line Diff line number Diff line Loading @@ -91,7 +91,7 @@ class TileSpecSettingsRepositoryTest : SysuiTestCase() { context.resources, context.resources, logger, logger, retailModeRepository, retailModeRepository, userTileSpecRepositoryFactory userTileSpecRepositoryFactory, ) ) } } Loading Loading @@ -218,6 +218,21 @@ class TileSpecSettingsRepositoryTest : SysuiTestCase() { assertThat(loadTilesForUser(user)).isEqualTo(startingTiles) assertThat(loadTilesForUser(user)).isEqualTo(startingTiles) } } @Test fun resetsDefault() = testScope.runTest { val tiles by collectLastValue(underTest.tilesSpecs(0)) val startingTiles = listOf(TileSpec.create("e"), TileSpec.create("f")) underTest.setTiles(0, startingTiles) runCurrent() underTest.resetToDefault(0) assertThat(tiles!!).containsExactlyElementsIn(DEFAULT_TILES.toTileSpecs()) } private fun TestScope.storeTilesForUser(specs: String, forUser: Int) { private fun TestScope.storeTilesForUser(specs: String, forUser: Int) { secureSettings.putStringForUser(SETTING, specs, forUser) secureSettings.putStringForUser(SETTING, specs, forUser) runCurrent() runCurrent() Loading packages/SystemUI/res/values/strings.xml +8 −0 Original line number Original line Diff line number Diff line Loading @@ -3895,4 +3895,12 @@ <string name="qs_edit_mode_category_unknown"> <string name="qs_edit_mode_category_unknown"> Unknown Unknown </string> </string> <!-- Title for the Reset Tiles dialog in QS Edit mode. [CHAR LIMIT=NONE] --> <string name="qs_edit_mode_reset_dialog_title"> Reset tiles </string> <!-- Content of the Reset Tiles dialog in QS Edit mode. [CHAR LIMIT=NONE] --> <string name="qs_edit_mode_reset_dialog_content"> Reset tiles to their original order and sizes? </string> </resources> </resources> Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/interactor/DynamicIconTilesInteractorTest.kt 0 → 100644 +81 −0 Original line number Original line Diff line number Diff line /* * 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.qs.panels.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.testScope import com.android.systemui.lifecycle.activateIn import com.android.systemui.qs.panels.data.repository.DefaultLargeTilesRepository import com.android.systemui.qs.panels.data.repository.defaultLargeTilesRepository import com.android.systemui.qs.panels.data.repository.qsPreferencesRepository import com.android.systemui.qs.pipeline.domain.interactor.currentTilesInteractor import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class DynamicIconTilesInteractorTest : SysuiTestCase() { private val kosmos = testKosmos().apply { defaultLargeTilesRepository = object : DefaultLargeTilesRepository { override val defaultLargeTiles: Set<TileSpec> = setOf(largeTile) } currentTilesInteractor.setTiles(listOf(largeTile, smallTile)) } private lateinit var underTest: DynamicIconTilesInteractor @Before fun setUp() { with(kosmos) { underTest = dynamicIconTilesInteractorFactory.create() underTest.activateIn(testScope) } } @OptIn(ExperimentalCoroutinesApi::class) @Test fun removingTile_updatesSharedPreferences() = with(kosmos) { testScope.runTest { val latest by collectLastValue(qsPreferencesRepository.largeTilesSpecs) runCurrent() // Remove the large tile from the current tiles currentTilesInteractor.removeTiles(listOf(largeTile)) runCurrent() // Assert that it resized to small assertThat(latest).doesNotContain(largeTile) } } private companion object { private val largeTile = TileSpec.create("large") private val smallTile = TileSpec.create("small") } }
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/interactor/IconTilesInteractorTest.kt +0 −17 Original line number Original line Diff line number Diff line Loading @@ -96,23 +96,6 @@ class IconTilesInteractorTest : SysuiTestCase() { } } } } @OptIn(ExperimentalCoroutinesApi::class) @Test fun removingTile_updatesSharedPreferences() = with(kosmos) { testScope.runTest { val latest by collectLastValue(qsPreferencesRepository.largeTilesSpecs) runCurrent() // Remove the large tile from the current tiles currentTilesInteractor.removeTiles(listOf(largeTile)) runCurrent() // Assert that it resized to small assertThat(latest).doesNotContain(largeTile) } } @OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class) @Test @Test fun resizingNonCurrentTile_doesNothing() = fun resizingNonCurrentTile_doesNothing() = Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/interactor/SizedTilesResetInteractorTest.kt 0 → 100644 +82 −0 Original line number Original line Diff line number Diff line /* * 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.qs.panels.domain.interactor import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.testScope import com.android.systemui.qs.panels.data.repository.DefaultLargeTilesRepository import com.android.systemui.qs.panels.data.repository.defaultLargeTilesRepository import com.android.systemui.qs.pipeline.data.repository.FakeDefaultTilesRepository import com.android.systemui.qs.pipeline.data.repository.fakeDefaultTilesRepository import com.android.systemui.qs.pipeline.domain.interactor.currentTilesInteractor import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.testKosmos 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 @SmallTest @RunWith(AndroidJUnit4::class) class SizedTilesResetInteractorTest : SysuiTestCase() { private val kosmos = testKosmos().apply { defaultLargeTilesRepository = object : DefaultLargeTilesRepository { override val defaultLargeTiles: Set<TileSpec> = setOf(largeTile) } fakeDefaultTilesRepository = FakeDefaultTilesRepository(listOf(smallTile, largeTile)) } private val underTest = with(kosmos) { sizedTilesResetInteractor } @OptIn(ExperimentalCoroutinesApi::class) @Test fun changeTiles_resetsCorrectly() { with(kosmos) { testScope.runTest { // Change current tiles and large tiles currentTilesInteractor.setTiles(listOf(largeTile, newTile)) iconTilesInteractor.setLargeTiles(setOf(newTile)) runCurrent() // Assert both current tiles and large tiles changed assertThat(currentTilesInteractor.currentTilesSpecs) .containsExactly(largeTile, newTile) assertThat(iconTilesInteractor.largeTilesSpecs.value).containsExactly(newTile) // Reset to default underTest.reset() runCurrent() // Assert both current tiles and large tiles are back to the initial state assertThat(currentTilesInteractor.currentTilesSpecs) .containsExactly(largeTile, smallTile) assertThat(iconTilesInteractor.largeTilesSpecs.value).containsExactly(largeTile) } } } private companion object { private val largeTile = TileSpec.create("large") private val smallTile = TileSpec.create("small") private val newTile = TileSpec.create("newTile") } }
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/data/repository/TileSpecSettingsRepositoryTest.kt +16 −1 Original line number Original line Diff line number Diff line Loading @@ -91,7 +91,7 @@ class TileSpecSettingsRepositoryTest : SysuiTestCase() { context.resources, context.resources, logger, logger, retailModeRepository, retailModeRepository, userTileSpecRepositoryFactory userTileSpecRepositoryFactory, ) ) } } Loading Loading @@ -218,6 +218,21 @@ class TileSpecSettingsRepositoryTest : SysuiTestCase() { assertThat(loadTilesForUser(user)).isEqualTo(startingTiles) assertThat(loadTilesForUser(user)).isEqualTo(startingTiles) } } @Test fun resetsDefault() = testScope.runTest { val tiles by collectLastValue(underTest.tilesSpecs(0)) val startingTiles = listOf(TileSpec.create("e"), TileSpec.create("f")) underTest.setTiles(0, startingTiles) runCurrent() underTest.resetToDefault(0) assertThat(tiles!!).containsExactlyElementsIn(DEFAULT_TILES.toTileSpecs()) } private fun TestScope.storeTilesForUser(specs: String, forUser: Int) { private fun TestScope.storeTilesForUser(specs: String, forUser: Int) { secureSettings.putStringForUser(SETTING, specs, forUser) secureSettings.putStringForUser(SETTING, specs, forUser) runCurrent() runCurrent() Loading
packages/SystemUI/res/values/strings.xml +8 −0 Original line number Original line Diff line number Diff line Loading @@ -3895,4 +3895,12 @@ <string name="qs_edit_mode_category_unknown"> <string name="qs_edit_mode_category_unknown"> Unknown Unknown </string> </string> <!-- Title for the Reset Tiles dialog in QS Edit mode. [CHAR LIMIT=NONE] --> <string name="qs_edit_mode_reset_dialog_title"> Reset tiles </string> <!-- Content of the Reset Tiles dialog in QS Edit mode. [CHAR LIMIT=NONE] --> <string name="qs_edit_mode_reset_dialog_content"> Reset tiles to their original order and sizes? </string> </resources> </resources>