Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
80ab5a3
enhance UI tests for admin registration flow
yasserahmed10 May 19, 2025
35facd7
add UI tests for login functionality
yasserahmed10 May 19, 2025
59cec78
add UI tests for project creation functionality
yasserahmed10 May 19, 2025
f146b7e
add UI tests for project retrieval based on user roles
yasserahmed10 May 19, 2025
121f3ad
refactor UI tests to improve clarity and error handling for project m…
yasserahmed10 May 19, 2025
ea4b1d0
refactor UI tests for updating project name to enhance user role hand…
yasserahmed10 May 19, 2025
131df6d
refactor UI tests for assigning projects to users to improve error ha…
yasserahmed10 May 19, 2025
0d1a7ef
add UI tests for user creation functionality with input validation an…
yasserahmed10 May 19, 2025
9497a07
add UI tests for user deletion functionality with role validation and…
yasserahmed10 May 19, 2025
ad40c7d
add UI tests for fetching all users with role handling and error mana…
yasserahmed10 May 19, 2025
d404caa
add UI tests for user interface interactions with menu navigation and…
yasserahmed10 May 19, 2025
83c0216
add UI tests for creating task states with validation and error handling
yasserahmed10 May 19, 2025
3650911
add UI tests for deleting task states with validation and error handling
yasserahmed10 May 19, 2025
12f441c
add UI tests for editing task states with validation and error handling
yasserahmed10 May 19, 2025
5c86d19
add UI tests for fetching all task states with validation and error h…
yasserahmed10 May 19, 2025
406c600
add UI tests for calculating subtask completion percentage with valid…
yasserahmed10 May 19, 2025
626c60d
add UI tests for creating sub tasks with validation and error handling
yasserahmed10 May 19, 2025
1fcfb8b
add UI tests for deleting sub-tasks with validation and error handling
yasserahmed10 May 19, 2025
b0514eb
add UI tests for editing sub-tasks with validation and error handling
yasserahmed10 May 19, 2025
dc5e7f3
add UI tests for fetching sub tasks by task ID with validation and er…
yasserahmed10 May 19, 2025
41f9d22
add UI tests for sub-task operations with validation and error handling
yasserahmed10 May 19, 2025
80be059
add UI tests for creating tasks with validation and error handling
yasserahmed10 May 19, 2025
df2abaa
add UI tests for deleting tasks with validation and error handling
yasserahmed10 May 19, 2025
ff778c1
add UI tests for editing tasks with validation and error handling
yasserahmed10 May 19, 2025
79c0b0f
add UI tests for fetching all tasks with validation and error handling
yasserahmed10 May 19, 2025
4665121
add UI tests for task management with validation and error handling
yasserahmed10 May 19, 2025
b40ebb8
add UI tests for task state management with navigation and error hand…
yasserahmed10 May 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions src/test/kotlin/presentation/auth/LoginUserUITest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package presentation.auth

import domain.usecases.auth.LoginUseCase
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.coVerifySequence
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import presentation.io.ConsoleIO

class LoginUserUITest {
private lateinit var loginUseCase: LoginUseCase
private lateinit var consoleIO: ConsoleIO
private lateinit var loginUserUI: LoginUserUI

@BeforeEach
fun setUp() {
loginUseCase = mockk(relaxed = true)
consoleIO = mockk(relaxed = true)
loginUserUI = LoginUserUI(loginUseCase, consoleIO)
}

@Test
fun `should login successfully on first attempt`() = runTest {
// Given
val username = "testUser"
val password = "testPassword"

coEvery { consoleIO.read() } returnsMany listOf(username, password)
coEvery { loginUseCase(username, password) } returns mockk()
coEvery { consoleIO.write(any()) } just runs

// When
loginUserUI()

// Then
coVerifySequence {
consoleIO.write("🔐 Login")
consoleIO.write("Enter username: ")
consoleIO.read()
consoleIO.write("Enter password: 🔑")
consoleIO.read()
loginUseCase(username, password)
consoleIO.write("✅ Logged in successfully! Welcome back, $username.")
}
}

@Test
fun `should retry login after failure and then succeed`() = runTest {
// Given
val failedUsername = "invalidUser"
val failedPassword = "invalidPass"
val successUsername = "validUser"
val successPassword = "validPass"
val errorMessage = "Invalid credentials"

coEvery { consoleIO.read() } returnsMany listOf(
failedUsername, failedPassword,
successUsername, successPassword
)
coEvery { loginUseCase(failedUsername, failedPassword) } throws Exception(errorMessage)
coEvery { loginUseCase(successUsername, successPassword) } returns mockk()
coEvery { consoleIO.write(any()) } just runs

// When
loginUserUI()

// Then
coVerifySequence {
consoleIO.write("🔐 Login")
consoleIO.write("Enter username: ")
consoleIO.read()
consoleIO.write("Enter password: 🔑")
consoleIO.read()
loginUseCase(failedUsername, failedPassword)
consoleIO.write("Login failed. $errorMessage 😞")
consoleIO.write("Enter username: ")
consoleIO.read()
consoleIO.write("Enter password: 🔑")
consoleIO.read()
loginUseCase(successUsername, successPassword)
consoleIO.write("✅ Logged in successfully! Welcome back, $successUsername.")
}

coVerify {
loginUseCase(failedUsername, failedPassword)
loginUseCase(successUsername, successPassword)
consoleIO.write("Login failed. $errorMessage 😞")
consoleIO.write("✅ Logged in successfully! Welcome back, $successUsername.")
}
}

@Test
fun `should handle multiple login failures before success`() = runTest {
// Given
val inputs = listOf(
"user1", "pass1",
"user2", "pass2",
"user3", "pass3"
)
val errors = listOf("Invalid username", "Password incorrect")

coEvery { consoleIO.read() } returnsMany inputs
coEvery { loginUseCase("user1", "pass1") } throws Exception(errors[0])
coEvery { loginUseCase("user2", "pass2") } throws Exception(errors[1])
coEvery { loginUseCase("user3", "pass3") } returns mockk()
coEvery { consoleIO.write(any()) } just runs

// When
loginUserUI()

// Then
coVerifySequence {
consoleIO.write("🔐 Login")

consoleIO.write("Enter username: ")
consoleIO.read()
consoleIO.write("Enter password: 🔑")
consoleIO.read()
loginUseCase("user1", "pass1")
consoleIO.write("Login failed. ${errors[0]} 😞")

consoleIO.write("Enter username: ")
consoleIO.read()
consoleIO.write("Enter password: 🔑")
consoleIO.read()
loginUseCase("user2", "pass2")
consoleIO.write("Login failed. ${errors[1]} 😞")

consoleIO.write("Enter username: ")
consoleIO.read()
consoleIO.write("Enter password: 🔑")
consoleIO.read()
loginUseCase("user3", "pass3")
consoleIO.write("✅ Logged in successfully! Welcome back, user3.")
}
}
}
Loading
Loading