Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 926e0132 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Reuse runTestWithSnapshots() for ResizableItemFrameViewModelTest" into main

parents 0b27ec80 2aeb307e
Loading
Loading
Loading
Loading
+98 −101
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@
package com.android.systemui.communal.ui.viewmodel

import androidx.compose.foundation.gestures.DraggableAnchors
import androidx.compose.runtime.snapshots.Snapshot
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.compose.runTestWithSnapshots
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.lifecycle.activateIn
@@ -229,7 +229,8 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        }

    @Test
    fun testTwoSpanGrid_expandElementFromBottom() = runTestWithSnapshots {
    fun testTwoSpanGrid_expandElementFromBottom() =
        testScope.runTestWithSnapshots {
            val resizeInfo by collectLastValue(underTest.resizeInfo)

            val adjustedGridLayout = singleSpanGrid.copy(resizeMultiple = 1, totalSpans = 2)
@@ -242,7 +243,8 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        }

    @Test
    fun testThreeSpanGrid_expandMiddleElementUpwards() = runTestWithSnapshots {
    fun testThreeSpanGrid_expandMiddleElementUpwards() =
        testScope.runTestWithSnapshots {
            val resizeInfo by collectLastValue(underTest.resizeInfo)
            updateGridLayout(singleSpanGrid.copy(currentRow = 1, totalSpans = 3))

@@ -251,7 +253,8 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        }

    @Test
    fun testThreeSpanGrid_expandTopElementDownBy2Spans() = runTestWithSnapshots {
    fun testThreeSpanGrid_expandTopElementDownBy2Spans() =
        testScope.runTestWithSnapshots {
            val resizeInfo by collectLastValue(underTest.resizeInfo)
            updateGridLayout(singleSpanGrid.copy(totalSpans = 3))

@@ -261,7 +264,8 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        }

    @Test
    fun testTwoSpanGrid_shrinkElementFromBottom() = runTestWithSnapshots {
    fun testTwoSpanGrid_shrinkElementFromBottom() =
        testScope.runTestWithSnapshots {
            val resizeInfo by collectLastValue(underTest.resizeInfo)
            updateGridLayout(singleSpanGrid.copy(totalSpans = 2, currentSpan = 2))

@@ -434,16 +438,19 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        }

    @Test
    fun testCanShrink_atFullSize_checksBottomDragState() = runTestWithSnapshots {
    fun testCanShrink_atFullSize_checksBottomDragState() =
        testScope.runTestWithSnapshots {
            val twoSpanGrid = singleSpanGrid.copy(totalSpans = 2, currentSpan = 2, currentRow = 0)
            updateGridLayout(twoSpanGrid)

            assertThat(underTest.canShrink()).isTrue()
        assertThat(underTest.bottomDragState.anchors.toList()).containsAtLeast(0 to 0f, -1 to -45f)
            assertThat(underTest.bottomDragState.anchors.toList())
                .containsAtLeast(0 to 0f, -1 to -45f)
        }

    @Test
    fun testResizeByAccessibility_expandFromBottom_usesTopDragState() = runTestWithSnapshots {
    fun testResizeByAccessibility_expandFromBottom_usesTopDragState() =
        testScope.runTestWithSnapshots {
            val resizeInfo by collectLastValue(underTest.resizeInfo)

            val twoSpanGrid = singleSpanGrid.copy(totalSpans = 2, currentSpan = 1, currentRow = 1)
@@ -455,7 +462,8 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        }

    @Test
    fun testResizeByAccessibility_expandFromTop_usesBottomDragState() = runTestWithSnapshots {
    fun testResizeByAccessibility_expandFromTop_usesBottomDragState() =
        testScope.runTestWithSnapshots {
            val resizeInfo by collectLastValue(underTest.resizeInfo)

            val twoSpanGrid = singleSpanGrid.copy(totalSpans = 2, currentSpan = 1, currentRow = 0)
@@ -467,7 +475,8 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        }

    @Test
    fun testResizeByAccessibility_shrinkFromFull_usesBottomDragState() = runTestWithSnapshots {
    fun testResizeByAccessibility_shrinkFromFull_usesBottomDragState() =
        testScope.runTestWithSnapshots {
            val resizeInfo by collectLastValue(underTest.resizeInfo)

            val twoSpanGrid = singleSpanGrid.copy(totalSpans = 2, currentSpan = 2, currentRow = 0)
@@ -479,7 +488,8 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        }

    @Test
    fun testResizeByAccessibility_cannotResizeAtMinSize() = runTestWithSnapshots {
    fun testResizeByAccessibility_cannotResizeAtMinSize() =
        testScope.runTestWithSnapshots {
            val resizeInfo by collectLastValue(underTest.resizeInfo)

            // Set up grid at minimum size
@@ -512,7 +522,8 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        testScope.runTest { updateGridLayout(singleSpanGrid.copy(resizeMultiple = 0)) }

    @Test
    fun testZeroHeights_cannotResize() = runTestWithSnapshots {
    fun testZeroHeights_cannotResize() =
        testScope.runTestWithSnapshots {
            val zeroHeightGrid =
                singleSpanGrid.copy(
                    totalSpans = 2,
@@ -550,20 +561,6 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() {
        }
    }

    private fun runTestWithSnapshots(testBody: suspend TestScope.() -> Unit) {
        val globalWriteObserverHandle =
            Snapshot.registerGlobalWriteObserver {
                // This is normally done by the compose runtime.
                Snapshot.sendApplyNotifications()
            }

        try {
            testScope.runTest(testBody = testBody)
        } finally {
            globalWriteObserverHandle.dispose()
        }
    }

    private data class GridLayout(
        val verticalItemSpacingPx: Float,
        val verticalContentPaddingPx: Float,