Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljohanneskraft committed Nov 26, 2024
1 parent bc9663c commit 2c4e8a7
Showing 1 changed file with 24 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package edu.stanford.spezi.module.onboarding.consent

import android.graphics.pdf.PdfDocument

Check warning on line 3 in modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt#L3 <detekt.NoUnusedImports>

Unused import
Raw output
/github/workspace/modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt:3:1: warning: Unused import (detekt.NoUnusedImports)

Check warning on line 3 in modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt#L3 <detekt.UnusedImports>

The import 'android.graphics.pdf.PdfDocument' is unused.
Raw output
/github/workspace/modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt:3:1: warning: The import 'android.graphics.pdf.PdfDocument' is unused. (detekt.UnusedImports)
import androidx.compose.ui.graphics.Path
import com.google.common.truth.Truth.assertThat
import edu.stanford.spezi.core.design.component.markdown.MarkdownElement
import edu.stanford.spezi.core.design.component.markdown.MarkdownParser
import edu.stanford.spezi.core.testing.CoroutineTestRule
import edu.stanford.spezi.core.testing.runTestUnconfined
import edu.stanford.spezi.module.account.manager.UserSessionManager
import edu.stanford.spezi.module.onboarding.spezi.consent.ConsentDataSource
import edu.stanford.spezi.module.onboarding.spezi.consent.ConsentDocumentExportConfiguration

Check warning on line 11 in modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt#L11 <detekt.NoUnusedImports>

Unused import
Raw output
/github/workspace/modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt:11:1: warning: Unused import (detekt.NoUnusedImports)

Check warning on line 11 in modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt#L11 <detekt.UnusedImports>

The import 'edu.stanford.spezi.module.onboarding.spezi.consent.ConsentDocumentExportConfiguration' is unused.
Raw output
/github/workspace/modules/onboarding/src/test/kotlin/edu/stanford/spezi/module/onboarding/consent/ConsentViewModelTest.kt:11:1: warning: The import 'edu.stanford.spezi.module.onboarding.spezi.consent.ConsentDocumentExportConfiguration' is unused. (detekt.UnusedImports)
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
Expand All @@ -21,16 +23,14 @@ class ConsentViewModelTest {
@get:Rule
val coroutineTestRule = CoroutineTestRule()

private val consentManager: ConsentManager = mockk(relaxed = true)
private val markdownParser: MarkdownParser = mockk(relaxed = true)
private val pdfCreationService: PdfCreationService = mockk(relaxed = true)
private val consentDataSource: ConsentDataSource = mockk(relaxed = true)
private val consentPdfService: ConsentPdfService = mockk(relaxed = true)
private val userSessionManager: UserSessionManager = mockk(relaxed = true)
private val viewModel by lazy {
ConsentViewModel(
consentManager = consentManager,
markdownParser = markdownParser,
pdfCreationService = pdfCreationService,
userSessionManager = userSessionManager
pdfService = consentPdfService,
consentDataSource = consentDataSource,
)
}

Expand All @@ -50,7 +50,7 @@ class ConsentViewModelTest {

// Then
val uiState = viewModel.uiState.first()
assertThat(name).isEqualTo(uiState.firstName.value)
assertThat(name).isEqualTo(uiState.name.givenName)
}

@Test
Expand All @@ -65,7 +65,7 @@ class ConsentViewModelTest {

// Then
val uiState = viewModel.uiState.first()
assertThat(lastName).isEqualTo(uiState.lastName.value)
assertThat(lastName).isEqualTo(uiState.name.familyName)
}

@Test
Expand Down Expand Up @@ -95,47 +95,27 @@ class ConsentViewModelTest {
assertThat(uiState.paths.size).isEqualTo(0)
}

@Test
fun `init block should fetch ConsentData correctly`() = runTestUnconfined {
// Given
val markdownText = "some markdown text"
val elements: List<MarkdownElement> = emptyList()
every { markdownParser.parse(markdownText) } returns elements
coEvery { consentManager.getMarkdownText() } returns markdownText

// When
val uiState = viewModel.uiState.first()

// Then
assertThat(uiState.markdownElements).isEqualTo(elements)
}

/*
@Test
fun `it should invoke handle consent action correctly on success case`() = runTestUnconfined {
// given
val pdfBytes = byteArrayOf()
coEvery { pdfCreationService.createPdf(viewModel.uiState.value) } returns pdfBytes
coEvery { userSessionManager.uploadConsentPdf(pdfBytes) } returns Result.success(Unit)

// when
viewModel.onAction(action = ConsentAction.Consent)

// then
coVerify { consentManager.onConsented() }
}

@Test
fun `it should invoke handle consent action correctly on error case`() = runTestUnconfined {
// given
val error: Throwable = mockk()
val pdfBytes = byteArrayOf()
coEvery { pdfCreationService.createPdf(viewModel.uiState.value) } returns pdfBytes
coEvery { userSessionManager.uploadConsentPdf(pdfBytes) } returns Result.failure(error)
val pdfDocument = PdfDocument()
val documentIdentifier = "testDocument"
val configuration = ConsentDocumentExportConfiguration()
coEvery {
consentPdfService.createDocument(
configuration,
viewModel.uiState.value.name,
viewModel.uiState.value.paths,
viewModel.uiState.value.markdownElements
)
} returns pdfDocument
// when
viewModel.onAction(action = ConsentAction.Consent)
viewModel.onAction(action = ConsentAction.Consent(documentIdentifier, configuration))
// then
coVerify { consentManager.onConsentFailure(error) }
coVerify { consentDataSource.store({ pdfDocument }, documentIdentifier) }
}
*/
}

0 comments on commit 2c4e8a7

Please sign in to comment.