Skip to content

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
subsymbolic committed Dec 11, 2017
2 parents 1d17a6b + 7be683b commit 38e257c
Show file tree
Hide file tree
Showing 50 changed files with 637 additions and 296 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'kotlin-kapt'
apply from: '../versioning.gradle'

ext {
VERSION_NAME = "0.4.0"
VERSION_NAME = "0.5.0"
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ class BrowserViewModelTest {
}

@Test
fun whenViewModelNotifiedThatUrlFocusChangedGotFocusThenViewStateIsUpdated() {
testee.urlFocusChanged(true)
fun whenViewModelNotifiedThatUrlGotFocusThenViewStateIsUpdated() {
testee.onUrlInputStateChanged("", true)
assertTrue(testee.viewState.value!!.isEditing)
}

@Test
fun whenViewModelNotifiedThatUrlFocusChangedLostFocusThenViewStateIsUpdated() {
testee.urlFocusChanged(false)
fun whenViewModelNotifiedThatUrlLostFocusThenViewStateIsUpdated() {
testee.onUrlInputStateChanged("", false)
assertFalse(testee.viewState.value!!.isEditing)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
/*
* Copyright (c) 2017 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.app.privacymonitor.ui

import android.arch.core.executor.testing.InstantTaskExecutorRule
import android.arch.lifecycle.Observer
import android.support.test.InstrumentationRegistry
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.privacymonitor.HttpsStatus
import com.duckduckgo.app.privacymonitor.PrivacyMonitor
import com.duckduckgo.app.privacymonitor.store.PrivacySettingsStore
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.whenever
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class PrivacyDashboardViewModelTest {

@get:Rule
@Suppress("unused")
var instantTaskExecutorRule = InstantTaskExecutorRule()

private lateinit var viewStateObserver: Observer<PrivacyDashboardViewModel.ViewState>
private lateinit var monitor: PrivacyMonitor
private lateinit var settingStore: PrivacySettingsStore

private val testee: PrivacyDashboardViewModel by lazy {
val model = PrivacyDashboardViewModel(InstrumentationRegistry.getTargetContext(), settingStore)
model.viewState.observeForever(viewStateObserver)
model
}

@Before
fun before() {
viewStateObserver = mock()
monitor = mock()
settingStore = mock()
whenever(monitor.https).thenReturn(HttpsStatus.SECURE)
}

@After
fun after() {
testee.viewState.removeObserver(viewStateObserver)
settingStore = mock()
}

@Test
fun whenPrivacyInitiallyOnAndSwitchedOffThenShouldReloadIsTrue() {
whenever(settingStore.privacyOn)
.thenReturn(true)
.thenReturn(false)
assertTrue(testee.shouldReloadPage)
}

@Test
fun whenPrivacyInitiallyOnAndUnchangedThenShouldReloadIsFalse() {
whenever(settingStore.privacyOn).thenReturn(true)
assertFalse(testee.shouldReloadPage)
}

@Test
fun whenPrivacyInitiallyOffAndSwitchedOnThenShouldReloadIsTrue() {
whenever(settingStore.privacyOn)
.thenReturn(false)
.thenReturn(true)
assertTrue(testee.shouldReloadPage)
}

@Test
fun whenPrivacyInitiallyOffAndUnchangedThenShouldReloadIsFalse() {
whenever(settingStore.privacyOn).thenReturn(false)
assertFalse(testee.shouldReloadPage)
}

@Test
fun whenHttpsStatusIsSecureThenTextAndIconReflectSame() {
whenever(monitor.https).thenReturn(HttpsStatus.SECURE)
testee.onPrivacyMonitorChanged(monitor)
assertEquals(getStringResource(R.string.httpsGood), testee.viewState.value?.httpsText)
assertEquals(R.drawable.dashboard_https_good, testee.viewState.value?.httpsIcon)
}

@Test
fun whenHttpsStatusIsMixedThenTextAndIconReflectSame() {
whenever(monitor.https).thenReturn(HttpsStatus.MIXED)
testee.onPrivacyMonitorChanged(monitor)
assertEquals(getStringResource(R.string.httpsMixed), testee.viewState.value?.httpsText)
assertEquals(R.drawable.dashboard_https_neutral, testee.viewState.value?.httpsIcon)
}

@Test
fun whenHttpsStatusIsNoneThenTextAndIconReflectSame() {
whenever(monitor.https).thenReturn(HttpsStatus.NONE)
testee.onPrivacyMonitorChanged(monitor)
assertEquals(getStringResource(R.string.httpsBad), testee.viewState.value?.httpsText)
assertEquals(R.drawable.dashboard_https_bad, testee.viewState.value?.httpsIcon)
}

@Test
fun whenNoTrackersNetworksThenNetworkIconIsGood() {
whenever(monitor.networkCount).thenReturn(0)
testee.onPrivacyMonitorChanged(monitor)
assertEquals(R.drawable.dashboard_networks_good, testee.viewState.value?.networksIcon)
}

@Test
fun whenTenTrackerNetworksAndAllBlockedThenNetworkIconIsGood() {
whenever(monitor.networkCount).thenReturn(10)
whenever(monitor.allTrackersBlocked).thenReturn(true)
testee.onPrivacyMonitorChanged(monitor)
assertEquals(R.drawable.dashboard_networks_good, testee.viewState.value?.networksIcon)
}

@Test
fun whenTenTrackerNetworksAndNotAllBlockedThenNetworkIconIsBad() {
whenever(monitor.networkCount).thenReturn(10)
whenever(monitor.allTrackersBlocked).thenReturn(false)
testee.onPrivacyMonitorChanged(monitor)
assertEquals(R.drawable.dashboard_networks_bad, testee.viewState.value?.networksIcon)
}

@Test
fun whenNoMajorTrackersNetworksThenMajorNetworkIconIsGood() {
whenever(monitor.majorNetworkCount).thenReturn(0)
testee.onPrivacyMonitorChanged(monitor)
assertEquals(R.drawable.dashboard_major_networks_good, testee.viewState.value?.majorNetworksIcon)
}

@Test
fun whenTenMajorTrackerNetworksAndAllBlockedThenMajorNetworkIconIsGood() {
whenever(monitor.majorNetworkCount).thenReturn(10)
whenever(monitor.allTrackersBlocked).thenReturn(true)
testee.onPrivacyMonitorChanged(monitor)
assertEquals(R.drawable.dashboard_major_networks_good, testee.viewState.value?.majorNetworksIcon)
}

@Test
fun whenTenMajorTrackerNetworksAndNotAllBlockedThenMajorNetworkIconIsBad() {
whenever(monitor.majorNetworkCount).thenReturn(10)
whenever(monitor.allTrackersBlocked).thenReturn(false)
testee.onPrivacyMonitorChanged(monitor)
assertEquals(R.drawable.dashboard_major_networks_bad, testee.viewState.value?.majorNetworksIcon)
}

@Test
fun whenNoTrackerNetworksThenNetworkTextShowsZeroBlocked() {
whenever(monitor.networkCount).thenReturn(0)
whenever(monitor.allTrackersBlocked).thenReturn(true)
testee.onPrivacyMonitorChanged(monitor)
assertEquals("0 Tracker Networks Blocked", testee.viewState.value?.networksText)
}

@Test
fun whenTenTrackerNetworksAndAllBlockedThenNetworkTextShowsTenBlocked() {
whenever(monitor.networkCount).thenReturn(10)
whenever(monitor.allTrackersBlocked).thenReturn(true)
testee.onPrivacyMonitorChanged(monitor)
assertEquals("10 Tracker Networks Blocked", testee.viewState.value?.networksText)
}

@Test
fun whenTenTrackersNetworksAndNotAllBlockedThenNetworkTextShowsTenFound() {
whenever(monitor.networkCount).thenReturn(10)
whenever(monitor.allTrackersBlocked).thenReturn(false)
testee.onPrivacyMonitorChanged(monitor)
assertEquals("10 Tracker Networks Found", testee.viewState.value?.networksText)
}

@Test
fun whenNoMajorTrackersNetworksThenMajorNetworkTextShowsZeroBlocked() {
whenever(monitor.majorNetworkCount).thenReturn(0)
whenever(monitor.allTrackersBlocked).thenReturn(true)
testee.onPrivacyMonitorChanged(monitor)
assertEquals("0 Major Tracker Networks Blocked", testee.viewState.value?.majorNetworksText)
}

@Test
fun whenTenMajorTrackerNetworksAndAllBlockedThenMajorNetworkTextShowsTenBlocked() {
whenever(monitor.majorNetworkCount).thenReturn(10)
whenever(monitor.allTrackersBlocked).thenReturn(true)
testee.onPrivacyMonitorChanged(monitor)
assertEquals("10 Major Tracker Networks Blocked", testee.viewState.value?.majorNetworksText)
}

@Test
fun whenTenMajorTrackerNetworksAndNotAllBlockedThenMajorNetworkTextShowsTenFound() {
whenever(monitor.majorNetworkCount).thenReturn(10)
whenever(monitor.allTrackersBlocked).thenReturn(false)
testee.onPrivacyMonitorChanged(monitor)
assertEquals("10 Major Tracker Networks Found", testee.viewState.value?.majorNetworksText)
}

@Test
fun whenNoDataThenDefaultValuesAreUsed() {
val viewState = testee.viewState.value!!
assertEquals(getStringResource(R.string.httpsGood), viewState.httpsText)
assertEquals(R.drawable.dashboard_networks_good, testee.viewState.value?.networksIcon)
assertEquals("0 Tracker Networks Blocked", testee.viewState.value?.networksText)
assertEquals(R.drawable.dashboard_major_networks_good, testee.viewState.value?.majorNetworksIcon)
assertEquals("0 Major Tracker Networks Blocked", testee.viewState.value?.majorNetworksText)
}

private fun getStringResource(id: Int): String =
InstrumentationRegistry.getTargetContext().getString(id)
}
Loading

0 comments on commit 38e257c

Please sign in to comment.