Skip to content

Commit

Permalink
Merge branch 'frontend' into main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
thebeo2004 committed Dec 16, 2024
2 parents d7eb3a2 + 2aa9781 commit 7f856bc
Show file tree
Hide file tree
Showing 18 changed files with 678 additions and 885 deletions.
111 changes: 111 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dependencies {
implementation(libs.firebase.auth)
implementation(libs.firebase.auth.ktx)
implementation(libs.firebase.firestore)
implementation(libs.androidx.navigation.testing)
testImplementation(libs.junit)
androidTestImplementation("org.mockito:mockito-core:4.9.0")
androidTestImplementation(libs.androidx.junit)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,86 @@
package com.example.harmonyhub.components_test

import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.harmonyhub.ui.components.ArtistsCard
import com.example.harmonyhub.ui.theme.HarmonyHubTheme
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
class ArtistsCardTest {

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun artistsCard_DisplaysArtistInfoCorrectly() {
// Arrange: Khởi tạo dữ liệu giả
val artistName = "Taylor Swift"
val artistImg = "https://example.com/taylor_swift.jpg"

composeTestRule.setContent {
HarmonyHubTheme {
ArtistsCard(
artistName = artistName,
artistImg = artistImg,
onArtistCardClick = {}
)
}
}

// Act & Assert: Kiểm tra tên nghệ sĩ hiển thị chính xác
composeTestRule.onNodeWithText(artistName).assertIsDisplayed()

// Act & Assert: Kiểm tra hình ảnh có mô tả đúng
composeTestRule.onNodeWithContentDescription("Photo").assertIsDisplayed()
}

@Test
fun artistsCard_HandlesClickAction() {
// Arrange: Biến để kiểm tra sự kiện click
var clicked = false

composeTestRule.setContent {
HarmonyHubTheme {
ArtistsCard(
artistName = "Ed Sheeran",
artistImg = "https://example.com/ed_sheeran.jpg",
onArtistCardClick = { clicked = true }
)
}
}

// Act: Nhấn vào thẻ nghệ sĩ
composeTestRule.onNodeWithContentDescription("Photo").performClick()

// Assert: Kiểm tra biến `clicked` thay đổi sau khi click
assert(clicked)
}

@Test
fun artistsCard_ShowsPlaceholderWhenImageFailsToLoad() {
// Arrange: Dùng một đường dẫn hình ảnh không hợp lệ
val artistName = "Adele"
val invalidArtistImg = "https://example.com/invalid_image.jpg"

composeTestRule.setContent {
HarmonyHubTheme {
ArtistsCard(
artistName = artistName,
artistImg = invalidArtistImg,
onArtistCardClick = {}
)
}
}

// Act & Assert: Kiểm tra hiển thị hình ảnh lỗi
composeTestRule.onNodeWithContentDescription("Photo").assertIsDisplayed()
}
}

Loading

0 comments on commit 7f856bc

Please sign in to comment.