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+ }
0 commit comments