<commit_before>/*
 * Copyright 2019 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 androidx.ui.foundation

import androidx.compose.Providers
import androidx.compose.ambientOf
import androidx.compose.state
import androidx.test.filters.MediumTest
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.UiDevice
import androidx.ui.core.Modifier
import androidx.ui.test.assertIsDisplayed
import androidx.ui.test.createComposeRule
import androidx.ui.test.performClick
import androidx.ui.test.onNodeWithText
import androidx.ui.test.runOnIdle
import org.junit.Assert.assertEquals
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@MediumTest
@RunWith(JUnit4::class)
class DialogUiTest {
    @get:Rule
    val composeTestRule = createComposeRule(disableTransitions = true)

    private val defaultText = "dialogText"

    @Test
    fun dialogTest_isShowingContent() {
        composeTestRule.setContent {
            val showDialog = state { true }

            if (showDialog.value) {
                Dialog(onCloseRequest = {}) {
                    Text(defaultText)
                }
            }
        }

        onNodeWithText(defaultText).assertIsDisplayed()
    }

    @Test
    fun dialogTest_isNotDismissed_whenClicked() {
        val textBeforeClick = "textBeforeClick"
        val textAfterClick = "textAfterClick"

        composeTestRule.setContent {
            val showDialog = state { true }
            val text = state { textBeforeClick }

            if (showDialog.value) {
                Dialog(onCloseRequest = {
                    showDialog.value = false
                }) {
                    Text(
                        text = text.value,
                        modifier = Modifier.clickable {
                            text.value = textAfterClick
                        }
                    )
                }
            }
        }

        onNodeWithText(textBeforeClick)
            .assertIsDisplayed()
            // Click inside the dialog
            .performClick()

        // Check that the Clickable was pressed and that the Dialog is still visible, but with
        // the new text<commit_msg>Disable DialogTest due to flakiness<commit_after>/*
 * Copyright 2019 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 androidx.ui.foundation

import androidx.compose.Providers
import androidx.compose.ambientOf
import androidx.compose.state
import androidx.test.filters.FlakyTest
import androidx.test.filters.MediumTest
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.UiDevice
import androidx.ui.core.Modifier
import androidx.ui.test.assertIsDisplayed
import androidx.ui.test.createComposeRule
import androidx.ui.test.performClick
import androidx.ui.test.onNodeWithText
import androidx.ui.test.runOnIdle
import org.junit.Assert.assertEquals
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@MediumTest
@RunWith(JUnit4::class)
class DialogUiTest {
    @get:Rule
    val composeTestRule = createComposeRule(disableTransitions = true)

    private val defaultText = "dialogText"

    @Test
    fun dialogTest_isShowingContent() {
        composeTestRule.setContent {
            val showDialog = state { true }

            if (showDialog.value) {
                Dialog(onCloseRequest = {}) {
                    Text(defaultText)
                }
            }
        }

        onNodeWithText(defaultText).assertIsDisplayed()
    }

    @Test
    @FlakyTest(bugId = 159364185)
    fun dialogTest_isNotDismissed_whenClicked() {
        val textBeforeClick = "textBeforeClick"
        val textAfterClick = "textAfterClick"

        composeTestRule.setContent {
            val showDialog = state { true }
            val text = state { textBeforeClick }

            if (showDialog.value) {
                Dialog(onCloseRequest = {
                    showDialog.value = false
                }) {
                    Text(
                        text = text.value,
                        modifier = Modifier.clickable {
                            text.value = textAfterClick
                        }
                    )
                }
            }
        }

        onNodeWithText(textBeforeClick)
            .assertIsDisplayed()
            // Click inside the dialog
            .performClick()

        // Check that the Clickable was pressed and that the Dialog is still visible, but with
        // the new text
{'fraction_non_alphanumeric': 0.07094535993061578, 'fraction_numerical': 0.005030355594102341, 'mean_word_length': 2.289218482601255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7593999', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1482, 'n_words': 417}