|
| 1 | +package com.gravatar.app.homeUi.presentation.home.share |
| 2 | + |
| 3 | +import com.gravatar.restapi.models.Profile |
| 4 | +import com.gravatar.restapi.models.ProfileContactInfo |
| 5 | +import org.junit.Assert.assertFalse |
| 6 | +import org.junit.Assert.assertTrue |
| 7 | +import org.junit.Test |
| 8 | +import java.net.URI |
| 9 | + |
| 10 | +class ShareUiStateTest { |
| 11 | + |
| 12 | + @Test |
| 13 | + fun `when ShareUiState has complete profile and shared contact info then vCardQrCodeData contains all information`() { |
| 14 | + // Given |
| 15 | + val profile = createCompleteProfile() |
| 16 | + val privateContactInfo = PrivateContactInfo( |
| 17 | + emailValue = "test@example.com", |
| 18 | + isEmailShared = true, |
| 19 | + phoneValue = "123-456-7890", |
| 20 | + isPhoneShared = true |
| 21 | + ) |
| 22 | + |
| 23 | + // When |
| 24 | + val shareUiState = ShareUiState( |
| 25 | + profile = profile, |
| 26 | + avatarUrl = "https://www.gravatar.com/avatar/test-hash", |
| 27 | + privateContactInfo = privateContactInfo |
| 28 | + ) |
| 29 | + |
| 30 | + // Then |
| 31 | + val vCardData = shareUiState.vCardQrCodeData |
| 32 | + |
| 33 | + // Verify vCard structure |
| 34 | + assertTrue(vCardData.startsWith("BEGIN:VCARD")) |
| 35 | + assertTrue(vCardData.endsWith("END:VCARD")) |
| 36 | + assertTrue(vCardData.contains("VERSION:3.0")) |
| 37 | + |
| 38 | + // Verify profile information |
| 39 | + assertTrue(vCardData.contains("N:User;Test;;;")) |
| 40 | + assertTrue(vCardData.contains("FN:Test User")) |
| 41 | + assertTrue(vCardData.contains("NICKNAME:Test User")) |
| 42 | + assertTrue(vCardData.contains("ORG:Test Company")) |
| 43 | + assertTrue(vCardData.contains("TITLE:Software Engineer")) |
| 44 | + assertTrue(vCardData.contains("URL:https://www.gravatar.com/test-hash")) |
| 45 | + assertTrue(vCardData.contains("NOTE:Test description")) |
| 46 | + |
| 47 | + // Verify contact information |
| 48 | + assertTrue(vCardData.contains("TEL;TYPE=cell:123-456-7890")) |
| 49 | + assertTrue(vCardData.contains("EMAIL:test@example.com")) |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + fun `when ShareUiState has minimal profile data then vCardQrCodeData contains only available information`() { |
| 54 | + // Given |
| 55 | + val profile = createMinimalProfile() |
| 56 | + |
| 57 | + // When |
| 58 | + val shareUiState = ShareUiState( |
| 59 | + profile = profile, |
| 60 | + avatarUrl = null, |
| 61 | + privateContactInfo = PrivateContactInfo() |
| 62 | + ) |
| 63 | + |
| 64 | + // Then |
| 65 | + var vCardData = shareUiState.vCardQrCodeData |
| 66 | + |
| 67 | + // Verify vCard structure |
| 68 | + assertTrue(vCardData.startsWith("BEGIN:VCARD")) |
| 69 | + assertTrue(vCardData.endsWith("END:VCARD")) |
| 70 | + |
| 71 | + // Remove BEGIN:VCARD and VERSION lines for easier verification |
| 72 | + vCardData = vCardData.replace("BEGIN:VCARD\n", "") |
| 73 | + .replace("END:VCARD\n", "") |
| 74 | + .replace("VERSION:3.0\n", "") |
| 75 | + |
| 76 | + // Verify minimal profile information is included |
| 77 | + assertTrue(vCardData.contains("URL:https://www.gravatar.com/minimal-hash")) |
| 78 | + |
| 79 | + // Verify that optional fields are not included |
| 80 | + assertFalse("vCard should not contain N:", vCardData.contains("N:")) |
| 81 | + assertFalse("vCard should not contain FN:", vCardData.contains("FN:")) |
| 82 | + assertFalse("vCard should not contain NICKNAME:", vCardData.contains("NICKNAME:")) |
| 83 | + assertFalse("vCard should not contain ORG:", vCardData.contains("ORG:")) |
| 84 | + assertFalse("vCard should not contain TITLE:", vCardData.contains("TITLE:")) |
| 85 | + assertFalse("vCard should not contain NOTE:", vCardData.contains("NOTE:")) |
| 86 | + assertFalse("vCard should not contain TEL;", vCardData.contains("TEL;")) |
| 87 | + assertFalse("vCard should not contain EMAIL:", vCardData.contains("EMAIL:")) |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + fun `when ShareUiState has unshared contact info then vCardQrCodeData does not include private contact info`() { |
| 92 | + // Given |
| 93 | + val profile = createCompleteProfile() |
| 94 | + val privateContactInfo = PrivateContactInfo( |
| 95 | + emailValue = "test@example.com", |
| 96 | + isEmailShared = false, |
| 97 | + phoneValue = "123-456-7890", |
| 98 | + isPhoneShared = false |
| 99 | + ) |
| 100 | + |
| 101 | + // When |
| 102 | + val shareUiState = ShareUiState( |
| 103 | + profile = profile, |
| 104 | + avatarUrl = "https://www.gravatar.com/avatar/test-hash", |
| 105 | + privateContactInfo = privateContactInfo |
| 106 | + ) |
| 107 | + |
| 108 | + // Then |
| 109 | + val vCardData = shareUiState.vCardQrCodeData |
| 110 | + |
| 111 | + // Verify profile information is included |
| 112 | + assertTrue(vCardData.contains("N:User;Test;;;")) |
| 113 | + assertTrue(vCardData.contains("FN:Test User")) |
| 114 | + |
| 115 | + // Verify private contact info is not included |
| 116 | + assertFalse("vCard should not contain TEL;", vCardData.contains("TEL;")) |
| 117 | + assertFalse("vCard should not contain EMAIL:", vCardData.contains("EMAIL:")) |
| 118 | + } |
| 119 | + |
| 120 | + private fun createCompleteProfile() = Profile { |
| 121 | + hash = "test-hash" |
| 122 | + displayName = "Test User" |
| 123 | + profileUrl = URI("https://www.gravatar.com/test-hash") |
| 124 | + avatarUrl = URI("https://www.gravatar.com/avatar/test-hash") |
| 125 | + avatarAltText = "Avatar for Test User" |
| 126 | + description = "Test description" |
| 127 | + pronouns = "They/Them" |
| 128 | + pronunciation = "Test pronunciation" |
| 129 | + location = "Test Location" |
| 130 | + jobTitle = "Software Engineer" |
| 131 | + company = "Test Company" |
| 132 | + firstName = "Test" |
| 133 | + lastName = "User" |
| 134 | + verifiedAccounts = emptyList() |
| 135 | + contactInfo = ProfileContactInfo { |
| 136 | + cellPhone = "123-456-7890" |
| 137 | + email = "test@example.com" |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + private fun createMinimalProfile() = Profile { |
| 142 | + hash = "minimal-hash" |
| 143 | + displayName = "" |
| 144 | + profileUrl = URI("https://www.gravatar.com/minimal-hash") |
| 145 | + avatarUrl = URI("https://www.gravatar.com/avatar/minimal-hash") |
| 146 | + avatarAltText = "" |
| 147 | + description = "" |
| 148 | + pronouns = "" |
| 149 | + pronunciation = "" |
| 150 | + location = "" |
| 151 | + jobTitle = "" |
| 152 | + company = "" |
| 153 | + firstName = "" |
| 154 | + lastName = "" |
| 155 | + verifiedAccounts = emptyList() |
| 156 | + contactInfo = ProfileContactInfo { |
| 157 | + cellPhone = "" |
| 158 | + email = "" |
| 159 | + } |
| 160 | + } |
| 161 | +} |
0 commit comments