-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'frontend' into main branch
- Loading branch information
Showing
18 changed files
with
678 additions
and
885 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 67 additions & 3 deletions
70
app/src/androidTest/java/com/example/harmonyhub/components_test/ArtistCardTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
|
Oops, something went wrong.