|
22 | 22 | import android.content.pm.PackageManager; |
23 | 23 | import android.database.SQLException; |
24 | 24 | import android.database.sqlite.SQLiteDatabase; |
| 25 | +import android.net.Uri; |
25 | 26 | import android.os.Build; |
26 | 27 | import android.support.test.InstrumentationRegistry; |
| 28 | +import android.support.test.espresso.Espresso; |
27 | 29 | import android.support.test.espresso.contrib.DrawerActions; |
28 | 30 | import android.support.test.espresso.matcher.ViewMatchers; |
29 | 31 | import android.support.test.runner.AndroidJUnit4; |
|
53 | 55 | import org.gnucash.android.model.Transaction; |
54 | 56 | import org.gnucash.android.ui.account.AccountsActivity; |
55 | 57 | import org.gnucash.android.ui.settings.PreferenceActivity; |
| 58 | +import org.gnucash.android.util.BookUtils; |
56 | 59 | import org.junit.After; |
57 | 60 | import org.junit.Before; |
58 | 61 | import org.junit.FixMethodOrder; |
@@ -139,139 +142,6 @@ public void setUp() throws Exception { |
139 | 142 | mAccountsDbAdapter.addRecord(account, DatabaseAdapter.UpdateMethod.insert); |
140 | 143 |
|
141 | 144 | } |
142 | | - |
143 | | - /** |
144 | | - * Tests the export of an OFX file with the transactions from the application. |
145 | | - * The exported file name contains a timestamp with minute precision. |
146 | | - * If this test fails, it may be due to the file being created and tested in different minutes of the clock |
147 | | - * Just try rerunning it again. |
148 | | - */ |
149 | | - @Test |
150 | | - public void testOfxExport(){ |
151 | | - SharedPreferences.Editor prefsEditor = PreferenceActivity.getActiveBookSharedPreferences() |
152 | | - .edit(); |
153 | | - prefsEditor.putBoolean(mAcccountsActivity.getString(R.string.key_use_double_entry), false) |
154 | | - .commit(); |
155 | | - testExport(ExportFormat.OFX); |
156 | | - prefsEditor.putBoolean(mAcccountsActivity.getString(R.string.key_use_double_entry), true) |
157 | | - .commit(); |
158 | | - } |
159 | | - |
160 | | - @Test |
161 | | - public void whenInSingleEntry_shouldHideXmlExportOption(){ |
162 | | - SharedPreferences.Editor prefsEditor = PreferenceActivity.getActiveBookSharedPreferences() |
163 | | - .edit(); |
164 | | - prefsEditor.putBoolean(mAcccountsActivity.getString(R.string.key_use_double_entry), false) |
165 | | - .commit(); |
166 | | - |
167 | | - DrawerActions.openDrawer(R.id.drawer_layout); |
168 | | - onView(withText(R.string.nav_menu_export)).perform(click()); |
169 | | - onView(withId(R.id.radio_xml_format)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); |
170 | | - |
171 | | - prefsEditor.putBoolean(mAcccountsActivity.getString(R.string.key_use_double_entry), true) |
172 | | - .commit(); |
173 | | - } |
174 | | - |
175 | | - /** |
176 | | - * Test the export of transactions in the QIF format |
177 | | - */ |
178 | | - @Test |
179 | | - public void testQifExport(){ |
180 | | - testExport(ExportFormat.QIF); |
181 | | - } |
182 | | - |
183 | | - @Test |
184 | | - public void testXmlExport(){ |
185 | | - testExport(ExportFormat.XML); |
186 | | - } |
187 | | - |
188 | | - /** |
189 | | - * Generates export for the specified format and tests that the file actually is created |
190 | | - * @param format Export format to use |
191 | | - */ |
192 | | - public void testExport(ExportFormat format){ |
193 | | - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
194 | | - if (mAcccountsActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) |
195 | | - != PackageManager.PERMISSION_GRANTED) { |
196 | | - mAcccountsActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, |
197 | | - Manifest.permission.READ_EXTERNAL_STORAGE}, 0x23); |
198 | | - |
199 | | - onView(withId(AlertDialog.BUTTON_POSITIVE)).perform(click()); |
200 | | - } |
201 | | - } |
202 | | - |
203 | | - File folder = new File(Exporter.getExportFolderPath(BooksDbAdapter.getInstance().getActiveBookUID())); |
204 | | - folder.mkdirs(); |
205 | | - assertThat(folder).exists(); |
206 | | - |
207 | | - for (File file : folder.listFiles()) { |
208 | | - file.delete(); |
209 | | - } |
210 | | - |
211 | | - onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); |
212 | | - onView(withText(R.string.nav_menu_export)).perform(click()); |
213 | | - |
214 | | - onView(withId(R.id.spinner_export_destination)).perform(click()); |
215 | | - String[] destinations = getActivity().getResources().getStringArray(R.array.export_destinations); |
216 | | - |
217 | | - onView(withText(destinations[0])).perform(click()); |
218 | | - onView(withText(format.name())).perform(click()); |
219 | | - |
220 | | - onView(withId(R.id.menu_save)).perform(click()); |
221 | | - |
222 | | - assertThat(folder.listFiles().length).isEqualTo(1); |
223 | | - File exportFile = folder.listFiles()[0]; |
224 | | - assertThat(exportFile.getName()).endsWith(format.getExtension()); |
225 | | - } |
226 | | - |
227 | | - @Test |
228 | | - public void testDeleteTransactionsAfterExport(){ |
229 | | - assertThat(mTransactionsDbAdapter.getRecordsCount()).isGreaterThan(0); |
230 | | - |
231 | | - SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit(); //PreferenceActivity.getActiveBookSharedPreferences(getActivity()).edit(); |
232 | | - editor.putBoolean(mAcccountsActivity.getString(R.string.key_delete_transactions_after_export), true); |
233 | | - editor.commit(); |
234 | | - |
235 | | - PreferenceActivity.getActiveBookSharedPreferences() |
236 | | - .edit() |
237 | | - .putBoolean(mAcccountsActivity.getString(R.string.key_use_double_entry), true) |
238 | | - .apply(); |
239 | | - |
240 | | - testExport(ExportFormat.XML); |
241 | | - |
242 | | - assertThat(mTransactionsDbAdapter.getRecordsCount()).isEqualTo(0); |
243 | | - List<Transaction> transactions = mTransactionsDbAdapter.getAllTransactions(); |
244 | | - |
245 | | - editor.putBoolean(mAcccountsActivity.getString(R.string.key_delete_transactions_after_export), false).commit(); |
246 | | - } |
247 | | - |
248 | | - /** |
249 | | - * Test creating a scheduled export |
250 | | - * Does not work on Travis yet |
251 | | - */ |
252 | | - @Test |
253 | | - public void testShouldCreateExportSchedule(){ |
254 | | - onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); |
255 | | - onView(withText(R.string.nav_menu_export)).perform(click()); |
256 | | - |
257 | | - onView(withText(ExportFormat.XML.name())).perform(click()); |
258 | | - onView(withId(R.id.input_recurrence)).perform(click()); |
259 | | - |
260 | | - //switch on recurrence dialog |
261 | | - onView(allOf(isAssignableFrom(CompoundButton.class), isDisplayed(), isEnabled())).perform(click()); |
262 | | - onView(withText("OK")).perform(click()); |
263 | | - |
264 | | - onView(withId(R.id.menu_save)).perform(click()); |
265 | | - ScheduledActionDbAdapter scheduledactionDbAdapter = ScheduledActionDbAdapter.getInstance(); //new ScheduledActionDbAdapter(mDb, new RecurrenceDbAdapter(mDb)); |
266 | | - List<ScheduledAction> scheduledActions = scheduledactionDbAdapter.getAllEnabledScheduledActions(); |
267 | | - assertThat(scheduledActions) |
268 | | - .hasSize(1) |
269 | | - .extracting("mActionType").contains(ScheduledAction.ActionType.BACKUP); |
270 | | - |
271 | | - ScheduledAction action = scheduledActions.get(0); |
272 | | - assertThat(action.getRecurrence().getPeriodType()).isEqualTo(PeriodType.WEEK); |
273 | | - assertThat(action.getEndTime()).isEqualTo(0); |
274 | | - } |
275 | 145 |
|
276 | 146 | @Test |
277 | 147 | public void testCreateBackup(){ |
|
0 commit comments