-
Notifications
You must be signed in to change notification settings - Fork 1
Add tests #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KCeh
wants to merge
4
commits into
feature/CI
Choose a base branch
from
feature/tests
base: feature/CI
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add tests #8
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
264 changes: 264 additions & 0 deletions
264
snacky/src/test/java/com/infinum/snacky/DefaultSnackbarDataTest.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,264 @@ | ||
| package com.infinum.snacky | ||
|
|
||
| import com.infinum.snacky.default.DefaultSnackbarData | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertFalse | ||
|
KCeh marked this conversation as resolved.
Outdated
|
||
| import org.junit.Assert.assertNotEquals | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Test | ||
|
|
||
| /** | ||
| * Unit tests for [DefaultSnackbarData]. | ||
| * Tests the data model for default snackbars and their properties. | ||
| */ | ||
| class DefaultSnackbarDataTest { | ||
|
|
||
| @Test | ||
| fun `DefaultSnackbarData should store message correctly`() { | ||
| // Given | ||
| val message = "Test message" | ||
|
|
||
| // When | ||
| val data = DefaultSnackbarData( | ||
| message = message, | ||
| actionLabel = null, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| // Then | ||
| assertEquals(message, data.message) | ||
| } | ||
|
|
||
| @Test | ||
| fun `DefaultSnackbarData should store action label correctly`() { | ||
| // Given | ||
| val actionLabel = "Action" | ||
|
|
||
| // When | ||
| val data = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = actionLabel, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| // Then | ||
| assertEquals(actionLabel, data.actionLabel) | ||
| } | ||
|
|
||
| @Test | ||
| fun `DefaultSnackbarData should handle null action label`() { | ||
| // When | ||
| val data = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = null, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| // Then | ||
| assertNull(data.actionLabel) | ||
| } | ||
|
|
||
| @Test | ||
| fun `DefaultSnackbarData should store dismiss action flag correctly`() { | ||
| // When | ||
| val dataWithDismiss = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = null, | ||
| withDismissAction = true, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| val dataWithoutDismiss = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = null, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| // Then | ||
| assertEquals(true, dataWithDismiss.withDismissAction) | ||
| assertEquals(false, dataWithoutDismiss.withDismissAction) | ||
| } | ||
|
|
||
| @Test | ||
| fun `DefaultSnackbarData should store dismiss action content description`() { | ||
| // Given | ||
| val contentDescription = "Close" | ||
|
|
||
| // When | ||
| val data = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = null, | ||
| withDismissAction = true, | ||
| dismissActionContentDescription = contentDescription, | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| // Then | ||
| assertEquals(contentDescription, data.dismissActionContentDescription) | ||
| } | ||
|
|
||
| @Test | ||
| fun `DefaultSnackbarData should store duration correctly`() { | ||
| // Given | ||
| val duration = SnackyDuration.Long | ||
|
|
||
| // When | ||
| val data = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = null, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = duration | ||
| ) | ||
|
|
||
| // Then | ||
| assertEquals(duration, data.duration) | ||
| } | ||
|
|
||
| @Test | ||
| fun `DefaultSnackbarData should have default empty callbacks`() { | ||
| // When | ||
| val data = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = null, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| // Then - Should not throw when calling callbacks | ||
| data.onDismissCallback() | ||
| data.onMainActionCallback() | ||
| } | ||
|
|
||
| @Test | ||
| fun `DefaultSnackbarData should store custom callbacks`() { | ||
| // Given | ||
| var mainActionCalled = false | ||
| var dismissCalled = false | ||
|
|
||
| // When | ||
| val data = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = "Action", | ||
| withDismissAction = true, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short, | ||
| onMainActionCallback = { mainActionCalled = true }, | ||
| onDismissCallback = { dismissCalled = true } | ||
| ) | ||
|
|
||
| data.onMainActionCallback() | ||
| data.onDismissCallback() | ||
|
|
||
| // Then | ||
| assertEquals(true, mainActionCalled) | ||
| assertEquals(true, dismissCalled) | ||
|
KCeh marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Test | ||
| fun `DefaultSnackbarData hasAction should be based on callback comparison`() { | ||
| // When | ||
| val data = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = null, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| // Then | ||
| // Note: hasAction checks if callbacks are not equal to empty lambda {} | ||
| // This is implementation-specific behavior | ||
| val hasAction = data.hasAction | ||
| // Just verify the property is accessible | ||
| assertEquals(hasAction, data.hasAction) | ||
|
KCeh marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| @Test | ||
| fun `Two DefaultSnackbarData with same properties should have same core values`() { | ||
| // Given | ||
| val callback = { } | ||
| val data1 = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = "Action", | ||
| withDismissAction = true, | ||
| dismissActionContentDescription = "Close", | ||
| duration = SnackyDuration.Short, | ||
| onDismissCallback = callback, | ||
| onMainActionCallback = callback | ||
| ) | ||
|
|
||
| val data2 = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = "Action", | ||
| withDismissAction = true, | ||
| dismissActionContentDescription = "Close", | ||
| duration = SnackyDuration.Short, | ||
| onDismissCallback = callback, | ||
| onMainActionCallback = callback | ||
| ) | ||
|
|
||
| // Then - Check that core properties match | ||
| assertEquals(data1.message, data2.message) | ||
| assertEquals(data1.actionLabel, data2.actionLabel) | ||
| assertEquals(data1.withDismissAction, data2.withDismissAction) | ||
| assertEquals(data1.dismissActionContentDescription, data2.dismissActionContentDescription) | ||
| assertEquals(data1.duration, data2.duration) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Two DefaultSnackbarData with different messages should not be equal`() { | ||
| // Given | ||
| val data1 = DefaultSnackbarData( | ||
| message = "Test 1", | ||
| actionLabel = null, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| val data2 = DefaultSnackbarData( | ||
| message = "Test 2", | ||
| actionLabel = null, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| // Then | ||
| assertNotEquals(data1, data2) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Two DefaultSnackbarData with different durations should not be equal`() { | ||
| // Given | ||
| val data1 = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = null, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Short | ||
| ) | ||
|
|
||
| val data2 = DefaultSnackbarData( | ||
| message = "Test", | ||
| actionLabel = null, | ||
| withDismissAction = false, | ||
| dismissActionContentDescription = "", | ||
| duration = SnackyDuration.Long | ||
| ) | ||
|
|
||
| // Then | ||
| assertNotEquals(data1, data2) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.