Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'kotlin-multiplatform'
id 'kotlinx-serialization' version '1.3.0'
id 'kotlinx-serialization'
}
repositories {
maven { url "https://kotlin.bintray.com/ktor" }
Expand All @@ -13,7 +13,9 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: "com.squareup.sqldelight"
sqldelight {
packageName = "sample.db"
MyDatabase {
packageName = "sample.db"
}
}

android {
Expand All @@ -32,21 +34,40 @@ android {
minifyEnabled false
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/ktor-http.kotlin_module'
exclude 'META-INF/main.kotlin_module'
exclude 'META-INF/kotlinx-io.kotlin_module'
exclude 'META-INF/atomicfu.kotlin_module'
exclude 'META-INF/kotlinx-coroutines-io.kotlin_module'
exclude 'META-INF/ktor-utils.kotlin_module'
exclude 'META-INF/ktor-client-json.kotlin_module'
exclude 'META-INF/ktor-client-core.kotlin_module'

}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'
implementation "io.ktor:ktor-client-android:1.0.0-beta-4"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
implementation "io.ktor:ktor-client-okhttp:1.1.3"
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.android.support:design:28.0.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation "com.squareup.sqldelight:android-driver:1.1.0"
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation "com.squareup.sqldelight:android-driver:1.0.0"
}

kotlin {
Expand All @@ -62,9 +83,9 @@ kotlin {
commonMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
implementation "io.ktor:ktor-client:1.0.0-beta-4"
implementation "io.ktor:ktor-client-json:1.0.0-beta-4"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.9.0"
implementation "io.ktor:ktor-client-core:1.1.3"
implementation "io.ktor:ktor-client-json:1.1.3"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.10.0"
}
}
commonTest {
Expand All @@ -77,9 +98,8 @@ kotlin {
androidMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation "io.ktor:ktor-client-core-jvm:1.0.0-beta-4"
implementation "io.ktor:ktor-client-json-jvm:1.0.0-beta-4"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.9.0"
implementation "io.ktor:ktor-client-json-jvm:1.1.3"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.10.0"
}
}
androidTest {
Expand All @@ -91,12 +111,12 @@ kotlin {
}
iosMain {
dependencies {
implementation "io.ktor:ktor-client-ios:1.0.0-beta-4"
implementation "io.ktor:ktor-client-core-ios:1.0.0-beta-4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.0.1"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.9.0"
implementation "io.ktor:ktor-client-json-ios:1.0.0-beta-4"
implementation "com.squareup.sqldelight:native-driver:1.0.0"
implementation "io.ktor:ktor-client-core-native:1.1.3"
implementation "io.ktor:ktor-client-json-native:1.1.3"
implementation "io.ktor:ktor-client-ios:1.1.3"
implementation "com.squareup.sqldelight:ios-driver:1.1.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.1.1"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.10.0"
}
}
iosTest {
Expand Down
2 changes: 1 addition & 1 deletion app/src/commonMain/kotlin/sample/api/NetworkApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import sample.AllData
class NetworkApi(private val endPoint: String) {

private val httpClient = HttpClient {
install(JsonFeature){
install(JsonFeature) {
serializer = KotlinxSerializer().apply {
setMapper(AllData::class, AllData.serializer())
}
Expand Down
206 changes: 103 additions & 103 deletions app/src/commonTest/kotlin/sample/presentation/MainPresenterTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package sample.presentation

import io.mockk.*
import kotlinx.coroutines.Dispatchers
import sample.*
//import io.mockk.*
//import kotlinx.coroutines.Dispatchers
//import sample.*
import kotlin.test.*

/**
Expand All @@ -11,104 +11,104 @@ import kotlin.test.*
@Ignore
open class MainPresenterTest {

lateinit var view: MainView
lateinit var repository: DataRepository
lateinit var presenter: MainPresenter


@BeforeTest
fun initDeps() {

view = mockk(relaxed = true)
repository = mockk(relaxed = true)

presenter = MainPresenter(
view = view,
repository = repository,
uiContext = Dispatchers.Default
)
}

@Test
fun `when load data is empty, it shows an error message`() {

presenter.loadData("")
verify {
view.showError(USER_NAME_NOT_VALID)

}
}

@Test
fun `shows loader while calling an API`() {

presenter.loadData("iamBedant")
verify {
view.showLoader()
}
}

@Test
fun `calls getData and displays result if call is successfull`() = runTest {

every { repository.data } returns allData
presenter.loadData("iamBedant")
coVerify {
repository.getData("iamBedant")
}
verify(ordering = Ordering.ORDERED) {
view.showLoader()
view.hideLoader()
}
}


@Test
fun `if user name is valid show actual name`() {
val displayData = presenter.getDisplayData(allData.copy("Test Name"))
assertEquals(displayData.name, allData.name)
}

@Test
fun `if user name is empty or null show login id as name`() {
val displayData = presenter.getDisplayData(allData.copy(name = null))
assertEquals(displayData.name, allData.login)
}

@Test
fun `if user bio is valid show bio`() {
val displayData = presenter.getDisplayData(allData.copy(bio = "This is test Bio"))
assertEquals(displayData.bio, "This is test Bio")
}

@Test
fun `if user bio is empty or null show no bio available`() {
val displayData = presenter.getDisplayData(allData.copy(bio = null))
assertEquals(displayData.bio, NO_BIO_AVAILABLE)
}

@Test
fun `if user avatar is valid show avatar`() {
val displayData = presenter.getDisplayData(allData.copy(avatar_url = "https://abc.def"))
assertEquals(displayData.avatarUrl, "https://abc.def")
}


@Test
fun `if user avatar is empty or null show default avatar`() {
val displayData = presenter.getDisplayData(allData.copy(avatar_url = null))
assertEquals(displayData.avatarUrl, DEFAULT_AVATAR)
}

@Test
fun `shows gists and repos in proper format`() {
val displayData = presenter.getDisplayData(allData.copy(public_gists = 4, public_repos = 5))
assertEquals(displayData.publicGists, "4 $PUBLIC_GISTS")
assertEquals(displayData.publicRepos, "5 $PUBLIC_REPOS")
}

@AfterTest
fun tearDown() {

}
// lateinit var view: MainView
// lateinit var repository: DataRepository
// lateinit var presenter: MainPresenter
//
//
// @BeforeTest
// fun initDeps() {
//
// view = mockk(relaxed = true)
// repository = mockk(relaxed = true)
//
// presenter = MainPresenter(
// view = view,
// repository = repository,
// uiContext = Dispatchers.Default
// )
// }
//
// @Test
// fun `when load data is empty, it shows an error message`() {
//
// presenter.loadData("")
// verify {
// view.showError(USER_NAME_NOT_VALID)
//
// }
// }
//
// @Test
// fun `shows loader while calling an API`() {
//
// presenter.loadData("iamBedant")
// verify {
// view.showLoader()
// }
// }
//
// @Test
// fun `calls getData and displays result if call is successfull`() = runTest {
//
// every { repository.data } returns allData
// presenter.loadData("iamBedant")
// coVerify {
// repository.getData("iamBedant")
// }
// verify(ordering = Ordering.ORDERED) {
// view.showLoader()
// view.hideLoader()
// }
// }
//
//
// @Test
// fun `if user name is valid show actual name`() {
// val displayData = presenter.getDisplayData(allData.copy("Test Name"))
// assertEquals(displayData.name, allData.name)
// }
//
// @Test
// fun `if user name is empty or null show login id as name`() {
// val displayData = presenter.getDisplayData(allData.copy(name = null))
// assertEquals(displayData.name, allData.login)
// }
//
// @Test
// fun `if user bio is valid show bio`() {
// val displayData = presenter.getDisplayData(allData.copy(bio = "This is test Bio"))
// assertEquals(displayData.bio, "This is test Bio")
// }
//
// @Test
// fun `if user bio is empty or null show no bio available`() {
// val displayData = presenter.getDisplayData(allData.copy(bio = null))
// assertEquals(displayData.bio, NO_BIO_AVAILABLE)
// }
//
// @Test
// fun `if user avatar is valid show avatar`() {
// val displayData = presenter.getDisplayData(allData.copy(avatar_url = "https://abc.def"))
// assertEquals(displayData.avatarUrl, "https://abc.def")
// }
//
//
// @Test
// fun `if user avatar is empty or null show default avatar`() {
// val displayData = presenter.getDisplayData(allData.copy(avatar_url = null))
// assertEquals(displayData.avatarUrl, DEFAULT_AVATAR)
// }
//
// @Test
// fun `shows gists and repos in proper format`() {
// val displayData = presenter.getDisplayData(allData.copy(public_gists = 4, public_repos = 5))
// assertEquals(displayData.publicGists, "4 $PUBLIC_GISTS")
// assertEquals(displayData.publicRepos, "5 $PUBLIC_REPOS")
// }
//
// @AfterTest
// fun tearDown() {
//
// }
}
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.squareup.sqldelight:gradle-plugin:1.0.0'
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.squareup.sqldelight:gradle-plugin:1.1.1'
classpath "org.jetbrains.kotlin:kotlin-serialization:1.3.21"
}
}
repositories {
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Nov 13 15:19:23 IST 2018
#Mon Mar 25 15:09:01 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
1 change: 1 addition & 0 deletions iosApp/iosApp/BaseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import UIKit
import app


var firstUpdateError = true

extension UIViewController: BaseView {
Expand Down
Loading