Skip to content

Commit 107080e

Browse files
committed
Customized Settings as per MC with test cases.
1 parent 93fd21e commit 107080e

File tree

17 files changed

+1100
-214
lines changed

17 files changed

+1100
-214
lines changed
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
package com.nmc.android.ui
2+
3+
import android.preference.ListPreference
4+
import android.preference.Preference
5+
import androidx.test.espresso.Espresso.onData
6+
import androidx.test.espresso.assertion.ViewAssertions.matches
7+
import androidx.test.espresso.matcher.PreferenceMatchers
8+
import androidx.test.espresso.matcher.PreferenceMatchers.withKey
9+
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
10+
import androidx.test.ext.junit.rules.ActivityScenarioRule
11+
import com.owncloud.android.AbstractIT
12+
import com.owncloud.android.R
13+
import com.owncloud.android.ui.AppVersionPreference
14+
import com.owncloud.android.ui.PreferenceCustomCategory
15+
import com.owncloud.android.ui.ThemeableSwitchPreference
16+
import com.owncloud.android.ui.activity.SettingsActivity
17+
import org.hamcrest.Matchers.allOf
18+
import org.hamcrest.Matchers.instanceOf
19+
import org.hamcrest.Matchers.`is`
20+
import org.junit.Assert.assertEquals
21+
import org.junit.Rule
22+
import org.junit.Test
23+
24+
class SettingsPreferenceIT : AbstractIT() {
25+
26+
@get:Rule
27+
val activityRule = ActivityScenarioRule(SettingsActivity::class.java)
28+
29+
@Test
30+
fun verifyPreferenceSectionCustomClass() {
31+
activityRule.scenario.onActivity {
32+
val preferenceAccountInfo = it.findPreference("account_info")
33+
val preferenceGeneral = it.findPreference("general")
34+
val preferenceDetails = it.findPreference("details")
35+
val preferenceMore = it.findPreference("more")
36+
val preferenceDataProtection = it.findPreference("data_protection")
37+
val preferenceInfo = it.findPreference("info")
38+
39+
val preferenceCategoryList = listOf(
40+
preferenceAccountInfo,
41+
preferenceGeneral,
42+
preferenceDetails,
43+
preferenceMore,
44+
preferenceDataProtection,
45+
preferenceInfo
46+
)
47+
48+
for (preference in preferenceCategoryList) {
49+
assertEquals(PreferenceCustomCategory::class.java, preference.javaClass)
50+
}
51+
}
52+
}
53+
54+
@Test
55+
fun verifySwitchPreferenceCustomClass() {
56+
activityRule.scenario.onActivity {
57+
val preferenceShowHiddenFiles = it.findPreference("show_hidden_files")
58+
assertEquals(ThemeableSwitchPreference::class.java, preferenceShowHiddenFiles.javaClass)
59+
}
60+
}
61+
62+
@Test
63+
fun verifyAppVersionPreferenceCustomClass() {
64+
activityRule.scenario.onActivity {
65+
val preferenceAboutApp = it.findPreference("about_app")
66+
assertEquals(AppVersionPreference::class.java, preferenceAboutApp.javaClass)
67+
}
68+
}
69+
70+
@Test
71+
fun verifyPreferenceChildCustomLayout() {
72+
activityRule.scenario.onActivity {
73+
val userName = it.findPreference("user_name")
74+
val storagePath = it.findPreference("storage_path")
75+
val lock = it.findPreference("lock")
76+
val showHiddenFiles = it.findPreference("show_hidden_files")
77+
val syncedFolders = it.findPreference("syncedFolders")
78+
val backup = it.findPreference("backup")
79+
val mnemonic = it.findPreference("mnemonic")
80+
val privacySettings = it.findPreference("privacy_settings")
81+
val privacyPolicy = it.findPreference("privacy_policy")
82+
val sourceCode = it.findPreference("sourcecode")
83+
val help = it.findPreference("help")
84+
val imprint = it.findPreference("imprint")
85+
86+
val preferenceList = listOf(
87+
userName,
88+
storagePath,
89+
lock,
90+
showHiddenFiles,
91+
syncedFolders,
92+
backup,
93+
mnemonic,
94+
privacySettings,
95+
privacyPolicy,
96+
sourceCode,
97+
help,
98+
imprint
99+
)
100+
101+
for (preference in preferenceList) {
102+
assertEquals(R.layout.custom_preference_layout, preference.layoutResource)
103+
}
104+
105+
val aboutApp = it.findPreference("about_app")
106+
assertEquals(R.layout.custom_app_preference_layout, aboutApp.layoutResource)
107+
108+
}
109+
}
110+
111+
@Test
112+
fun verifyPreferencesTitleText() {
113+
onData(allOf(`is`(instanceOf(PreferenceCustomCategory::class.java)), withKey("account_info"),
114+
PreferenceMatchers.withTitleText("Account Information")))
115+
.check(matches(isCompletelyDisplayed()))
116+
117+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("user_name"),
118+
PreferenceMatchers.withTitleText("test")))
119+
.check(matches(isCompletelyDisplayed()))
120+
121+
onData(allOf(`is`(instanceOf(PreferenceCustomCategory::class.java)), withKey("general"),
122+
PreferenceMatchers.withTitleText("General")))
123+
.check(matches(isCompletelyDisplayed()))
124+
125+
onData(allOf(`is`(instanceOf(ListPreference::class.java)), withKey("storage_path"),
126+
PreferenceMatchers.withTitleText("Data storage folder")))
127+
.check(matches(isCompletelyDisplayed()))
128+
129+
onData(allOf(`is`(instanceOf(PreferenceCustomCategory::class.java)), withKey("details"),
130+
PreferenceMatchers.withTitleText("Details")))
131+
.check(matches(isCompletelyDisplayed()))
132+
133+
onData(allOf(`is`(instanceOf(ListPreference::class.java)), withKey("lock"),
134+
PreferenceMatchers.withTitleText("App passcode")))
135+
.check(matches(isCompletelyDisplayed()))
136+
137+
onData(allOf(`is`(instanceOf(ThemeableSwitchPreference::class.java)), withKey("show_hidden_files"),
138+
PreferenceMatchers.withTitleText("Show hidden files")))
139+
.check(matches(isCompletelyDisplayed()))
140+
141+
onData(allOf(`is`(instanceOf(PreferenceCustomCategory::class.java)), withKey("more"),
142+
PreferenceMatchers.withTitleText("More")))
143+
.check(matches(isCompletelyDisplayed()))
144+
145+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("syncedFolders"),
146+
PreferenceMatchers.withTitleText("Auto upload")))
147+
.check(matches(isCompletelyDisplayed()))
148+
149+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("backup"),
150+
PreferenceMatchers.withTitleText("Back up contacts")))
151+
.check(matches(isCompletelyDisplayed()))
152+
153+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("mnemonic"),
154+
PreferenceMatchers.withTitleText("E2E mnemonic")))
155+
.check(matches(isCompletelyDisplayed()))
156+
157+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("logger"),
158+
PreferenceMatchers.withTitleText("Logs")))
159+
.check(matches(isCompletelyDisplayed()))
160+
161+
onData(allOf(`is`(instanceOf(PreferenceCustomCategory::class.java)), withKey("data_protection"),
162+
PreferenceMatchers.withTitleText("Data Privacy")))
163+
.check(matches(isCompletelyDisplayed()))
164+
165+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("privacy_settings"),
166+
PreferenceMatchers.withTitleText("Privacy Settings")))
167+
.check(matches(isCompletelyDisplayed()))
168+
169+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("privacy_policy"),
170+
PreferenceMatchers.withTitleText("Privacy Policy")))
171+
.check(matches(isCompletelyDisplayed()))
172+
173+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("sourcecode"),
174+
PreferenceMatchers.withTitleText("Used OpenSource Software")))
175+
.check(matches(isCompletelyDisplayed()))
176+
177+
onData(allOf(`is`(instanceOf(PreferenceCustomCategory::class.java)), withKey("service"),
178+
PreferenceMatchers.withTitleText("Service")))
179+
.check(matches(isCompletelyDisplayed()))
180+
181+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("help"),
182+
PreferenceMatchers.withTitleText("Help")))
183+
.check(matches(isCompletelyDisplayed()))
184+
185+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("imprint"),
186+
PreferenceMatchers.withTitleText("Imprint")))
187+
.check(matches(isCompletelyDisplayed()))
188+
189+
onData(allOf(`is`(instanceOf(PreferenceCustomCategory::class.java)), withKey("info"),
190+
PreferenceMatchers.withTitleText("Info")))
191+
.check(matches(isCompletelyDisplayed()))
192+
}
193+
194+
@Test
195+
fun verifyPreferencesSummaryText() {
196+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("lock"),
197+
PreferenceMatchers.withSummaryText("None")))
198+
.check(matches(isCompletelyDisplayed()))
199+
200+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("syncedFolders"),
201+
PreferenceMatchers.withSummaryText("Manage folders for auto upload")))
202+
.check(matches(isCompletelyDisplayed()))
203+
204+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("backup"),
205+
PreferenceMatchers.withSummaryText("Daily backup of your calendar & contacts")))
206+
.check(matches(isCompletelyDisplayed()))
207+
208+
onData(allOf(`is`(instanceOf(Preference::class.java)), withKey("mnemonic"),
209+
PreferenceMatchers.withSummaryText("To show mnemonic please enable device credentials.")))
210+
.check(matches(isCompletelyDisplayed()))
211+
}
212+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.nmc.android.ui
2+
3+
import android.content.Context
4+
5+
/**
6+
* interface to open privacy settings activity from nmc/1921-settings branch
7+
* for implementation look nmc/1878-privacy branch
8+
* this class will have the declaration for it since it has the PrivacySettingsActivity.java in place
9+
* since we don't have privacy settings functionality in this branch so to handle the redirection we have used interface
10+
*/
11+
interface PrivacySettingsInterface {
12+
fun openPrivacySettingsActivity(context: Context)
13+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.owncloud.android.ui
2+
3+
import android.content.Context
4+
import android.content.pm.PackageManager
5+
import android.preference.Preference
6+
import android.util.AttributeSet
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import android.widget.TextView
10+
import com.owncloud.android.R
11+
import com.owncloud.android.lib.common.utils.Log_OC
12+
import com.owncloud.android.utils.StringUtils
13+
14+
class AppVersionPreference : Preference {
15+
constructor(context: Context?) : super(context)
16+
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
17+
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)
18+
19+
override fun getView(convertView: View?, parent: ViewGroup?): View {
20+
val v = super.getView(convertView, parent)
21+
updatePreferenceView(v.findViewById(R.id.title), v.findViewById(R.id.summary))
22+
return v
23+
}
24+
25+
private fun updatePreferenceView(title: TextView, summary: TextView) {
26+
val appVersion = appVersion
27+
val titleColor: Int = context.resources.getColor(R.color.fontAppbar, null)
28+
title.text = StringUtils.getColorSpan(
29+
context.getString(R.string.app_name),
30+
titleColor
31+
)
32+
summary.text = String.format(context.getString(R.string.about_version), appVersion)
33+
}
34+
35+
private val appVersion: String
36+
get() {
37+
var temp: String
38+
try {
39+
val pkg = context.packageManager.getPackageInfo(context.packageName, 0)
40+
temp = pkg.versionName
41+
} catch (e: PackageManager.NameNotFoundException) {
42+
temp = ""
43+
Log_OC.e(TAG, "Error while showing about dialog", e)
44+
}
45+
return temp
46+
}
47+
48+
companion object {
49+
private val TAG = AppVersionPreference::class.java.simpleName
50+
}
51+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.owncloud.android.ui
2+
3+
import android.content.Context
4+
import android.graphics.Typeface
5+
import android.preference.PreferenceCategory
6+
import android.util.AttributeSet
7+
import android.util.TypedValue
8+
import android.view.View
9+
import android.widget.TextView
10+
import com.owncloud.android.R
11+
12+
class PreferenceCustomCategory : PreferenceCategory {
13+
constructor(context: Context?) : super(context)
14+
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
15+
constructor(
16+
context: Context?, attrs: AttributeSet?,
17+
defStyle: Int
18+
) : super(context, attrs, defStyle)
19+
20+
override fun onBindView(view: View) {
21+
super.onBindView(view)
22+
val titleView = view.findViewById<TextView>(android.R.id.title)
23+
titleView.setTextColor(context.resources.getColor(R.color.text_color))
24+
titleView.setTextSize(
25+
TypedValue.COMPLEX_UNIT_PX,
26+
context.resources.getDimensionPixelSize(R.dimen.txt_size_16sp).toFloat()
27+
)
28+
titleView.setTypeface(null, Typeface.BOLD)
29+
}
30+
}

0 commit comments

Comments
 (0)