forked from mozilla-mobile/android-components
-
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.
For mozilla-mobile#12171 - Add a PocketStory supertype for all Pocket…
… stories types
- Loading branch information
Showing
16 changed files
with
157 additions
and
92 deletions.
There are no files selected for viewing
26 changes: 0 additions & 26 deletions
26
.../service/pocket/src/main/java/mozilla/components/service/pocket/PocketRecommendedStory.kt
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
...ts/service/pocket/src/main/java/mozilla/components/service/pocket/PocketSponsoredStory.kt
This file was deleted.
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
71 changes: 71 additions & 0 deletions
71
components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStory.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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.service.pocket | ||
|
||
/** | ||
* A Pocket story downloaded from the Internet and intended to be displayed in the application. | ||
*/ | ||
sealed class PocketStory { | ||
/** | ||
* Title of the story. | ||
*/ | ||
abstract val title: String | ||
|
||
/** | ||
* Url where the story can be full read. | ||
*/ | ||
abstract val url: String | ||
|
||
/** | ||
* A Pocket recommended story. | ||
* | ||
* @property title The title of the story. | ||
* @property url A "pocket.co" shortlink for the original story's page. | ||
* @property imageUrl A url to a still image representing the story. | ||
* @property publisher Optional publisher name/domain, e.g. "The New Yorker" / "nationalgeographic.co.uk"". | ||
* **May be empty**. | ||
* @property category Topic of interest under which similar stories are grouped. | ||
* @property timeToRead Inferred time needed to read the entire story. **May be -1**. | ||
*/ | ||
data class PocketRecommendedStory( | ||
override val title: String, | ||
override val url: String, | ||
val imageUrl: String, | ||
val publisher: String, | ||
val category: String, | ||
val timeToRead: Int, | ||
val timesShown: Long | ||
) : PocketStory() | ||
|
||
/** | ||
* A Pocket sponsored story. | ||
* | ||
* @property title The title of the story. | ||
* @property url 3rd party url containing the original story. | ||
* @property imageUrl A url to a still image representing the story. | ||
* Contains a "resize" parameter in the form of "resize=w618-h310" allowing to get the image | ||
* with a specific resolution and the CENTER_CROP ScaleType. | ||
* @property sponsor 3rd party sponsor of this story, e.g. "NextAdvisor". | ||
* @property shim Unique identifiers for when the user interacts with this story. | ||
*/ | ||
data class PocketSponsoredStory( | ||
override val title: String, | ||
override val url: String, | ||
val imageUrl: String, | ||
val sponsor: String, | ||
val shim: PocketSponsoredStoryShim, | ||
) : PocketStory() | ||
|
||
/** | ||
* Sponsored story unique identifiers intended to be used in telemetry. | ||
* | ||
* @property click Unique identifier for when the sponsored story is clicked. | ||
* @property impression Unique identifier for when the user sees this sponsored story. | ||
*/ | ||
data class PocketSponsoredStoryShim( | ||
val click: String, | ||
val impression: String, | ||
) | ||
} |
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
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
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
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
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
21 changes: 0 additions & 21 deletions
21
...vice/pocket/src/test/java/mozilla/components/service/pocket/PocketRecommendedStoryTest.kt
This file was deleted.
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
69 changes: 69 additions & 0 deletions
69
components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoryTest.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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.service.pocket | ||
|
||
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory | ||
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory | ||
import mozilla.components.service.pocket.helpers.assertConstructorsVisibility | ||
import mozilla.components.support.test.mock | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import kotlin.reflect.KVisibility | ||
|
||
class PocketStoryTest { | ||
@Test | ||
fun `GIVEN PocketSponsoredStory THEN it should be publicly available`() { | ||
assertConstructorsVisibility(PocketSponsoredStory::class, KVisibility.PUBLIC) | ||
} | ||
|
||
@Test | ||
fun `GIVEN PocketRecommendedStory THEN it should be publicly available`() { | ||
assertConstructorsVisibility(PocketRecommendedStory::class, KVisibility.PUBLIC) | ||
} | ||
|
||
@Test | ||
fun `GIVEN a PocketRecommendedStory WHEN it's title is accessed from parent THEN it returns the previously set value`() { | ||
val pocketRecommendedStory = PocketRecommendedStory( | ||
title = "testTitle", url = "", imageUrl = "", publisher = "", category = "", timeToRead = 0, timesShown = 0 | ||
) | ||
|
||
val result = (pocketRecommendedStory as PocketStory).title | ||
|
||
assertEquals("testTitle", result) | ||
} | ||
|
||
@Test | ||
fun `GIVEN a PocketRecommendedStory WHEN it's url is accessed from parent THEN it returns the previously set value`() { | ||
val pocketRecommendedStory = PocketRecommendedStory( | ||
title = "", url = "testUrl", imageUrl = "", publisher = "", category = "", timeToRead = 0, timesShown = 0 | ||
) | ||
|
||
val result = (pocketRecommendedStory as PocketStory).url | ||
|
||
assertEquals("testUrl", result) | ||
} | ||
|
||
@Test | ||
fun `GIVEN a PocketSponsoredStory WHEN it's title is accessed from parent THEN it returns the previously set value`() { | ||
val pocketRecommendedStory = PocketSponsoredStory( | ||
title = "testTitle", url = "", imageUrl = "", sponsor = "", shim = mock() | ||
) | ||
|
||
val result = (pocketRecommendedStory as PocketStory).title | ||
|
||
assertEquals("testTitle", result) | ||
} | ||
|
||
@Test | ||
fun `GIVEN a PocketSponsoredStory WHEN it's url is accessed from parent THEN it returns the previously set value`() { | ||
val pocketRecommendedStory = PocketSponsoredStory( | ||
title = "", url = "testUrl", imageUrl = "", sponsor = "", shim = mock() | ||
) | ||
|
||
val result = (pocketRecommendedStory as PocketStory).url | ||
|
||
assertEquals("testUrl", result) | ||
} | ||
} |
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
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
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
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