package com.example.tasks.screens

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.example.tasks.navigation.Screen
import com.example.tasks.ui.theme.TasksTheme
import org.junit.Assert.*
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class AddTaskAndTaskChiefTest {
    @get:Rule(order = 0)
    var testRule = createComposeRule()

    @Before
    fun setup() {
        testRule.setContent {
            val navController = rememberNavController()
            TasksTheme {
                NavHost(
                    navController = navController,
                    startDestination = Screen.TasksChief.route
                ) {
                    composable(route = Screen.TasksChief.route) {
                        TasksChief(
                            surname = "Бобарик",
                            name = "Кристина",
                            patronymic = "Евгеньевна",
                            division = "Отдел информационных технологий",
                            navController2 = navController
                        )
                    }
                    composable(
                        route = Screen.AddTask.route + "/{division}/{surname}/{name}/{patronymic}",
                        arguments = listOf(
                            navArgument("surname") {
                                type = NavType.StringType
                            },
                            navArgument("name") {
                                type = NavType.StringType
                            },
                            navArgument("patronymic") {
                                type = NavType.StringType
                            },
                            navArgument("division") {
                                type = NavType.StringType
                            }
                        ))
                    {
                        val surname = it.arguments!!.getString("surname")
                        val name = it.arguments!!.getString("name")
                        val patronymic = it.arguments!!.getString("patronymic")
                        val division = it.arguments!!.getString("division")
                        AddTask(
                            name = name!!,
                            surname = surname!!,
                            patronymic = patronymic!!,
                            division = division!!,
                            navController = navController
                        )

                    }
                }
            }


        }
    }


    @Test
    fun testAddTask_createTask() {
        testRule.onNodeWithTag("add_task").performClick()
        testRule.onNodeWithTag("menu").performClick()
        testRule.onNodeWithTag("staff").performClick()
        testRule.onNodeWithTag("CustomText").performTextInput("1")
        testRule.onNodeWithText("1").assertIsDisplayed()
        testRule.onNodeWithTag("button_add").performClick()
        testRule.onNodeWithText("Иванов И.И.").assertIsDisplayed()
        testRule.onNodeWithText("1").assertIsDisplayed()

    }
}