-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from xizzhu/e2e-testing
Added end-to-end testing
- Loading branch information
Showing
63 changed files
with
2,159 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
app/src/androidTest/kotlin/me/xizzhu/android/joshua/Injection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright (C) 2020 Xizhi Zhu | ||
* | ||
* 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 me.xizzhu.android.joshua | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import me.xizzhu.android.joshua.core.* | ||
import me.xizzhu.android.joshua.core.repository.* | ||
import me.xizzhu.android.joshua.core.repository.local.android.* | ||
import me.xizzhu.android.joshua.core.repository.local.android.db.AndroidDatabase | ||
import me.xizzhu.android.joshua.core.repository.remote.android.HttpStrongNumberService | ||
import me.xizzhu.android.joshua.core.repository.remote.android.HttpTranslationService | ||
import javax.inject.Scope | ||
import javax.inject.Singleton | ||
|
||
@Scope | ||
@Retention(AnnotationRetention.RUNTIME) | ||
annotation class ActivityScope | ||
|
||
@Module | ||
class AppModule(private val app: App) { | ||
@Provides | ||
@Singleton | ||
fun provideApp(): App = app | ||
|
||
companion object { | ||
@Provides | ||
@Singleton | ||
fun provideNavigator(): Navigator = Navigator() | ||
|
||
@Provides | ||
@Singleton | ||
fun provideBackupManager(bookmarkRepository: VerseAnnotationRepository<Bookmark>, | ||
highlightRepository: VerseAnnotationRepository<Highlight>, | ||
noteRepository: VerseAnnotationRepository<Note>, | ||
readingProgressRepository: ReadingProgressRepository): BackupManager = BackupManager | ||
|
||
@Provides | ||
@Singleton | ||
fun provideBibleReadingManager(bibleReadingRepository: BibleReadingRepository, | ||
translationRepository: TranslationRepository): BibleReadingManager = BibleReadingManager | ||
|
||
@Provides | ||
@Singleton | ||
fun provideBookmarkManager(bookmarkRepository: VerseAnnotationRepository<Bookmark>): VerseAnnotationManager<Bookmark> = | ||
VerseAnnotationManager(bookmarkRepository) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideHighlightManager(highlightRepository: VerseAnnotationRepository<Highlight>): VerseAnnotationManager<Highlight> = | ||
VerseAnnotationManager(highlightRepository) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideNoteManager(noteRepository: VerseAnnotationRepository<Note>): VerseAnnotationManager<Note> = | ||
VerseAnnotationManager(noteRepository) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideReadingProgressManager(bibleReadingRepository: BibleReadingRepository, | ||
readingProgressRepository: ReadingProgressRepository): ReadingProgressManager = ReadingProgressManager | ||
|
||
@Provides | ||
@Singleton | ||
fun provideSettingsManager(settingsRepository: SettingsRepository): SettingsManager = SettingsManager | ||
|
||
@Provides | ||
@Singleton | ||
fun provideStrongNumberManager(strongNumberRepository: StrongNumberRepository): StrongNumberManager = StrongNumberManager | ||
|
||
@Provides | ||
@Singleton | ||
fun provideTranslationManager(translationRepository: TranslationRepository): TranslationManager = TranslationManager | ||
} | ||
} | ||
|
||
@Module | ||
object RepositoryModule { | ||
@Provides | ||
@Singleton | ||
fun provideAndroidDatabase(app: App): AndroidDatabase = AndroidDatabase(app) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideBibleReadingRepository(androidDatabase: AndroidDatabase): BibleReadingRepository = | ||
BibleReadingRepository(AndroidReadingStorage(androidDatabase)) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideBookmarkRepository(androidDatabase: AndroidDatabase): VerseAnnotationRepository<Bookmark> = BookmarksRepository | ||
|
||
@Provides | ||
@Singleton | ||
fun provideHighlightRepository(androidDatabase: AndroidDatabase): VerseAnnotationRepository<Highlight> = HighlightsRepository | ||
|
||
@Provides | ||
@Singleton | ||
fun provideNoteRepository(androidDatabase: AndroidDatabase): VerseAnnotationRepository<Note> = NotesRepository | ||
|
||
@Provides | ||
@Singleton | ||
fun provideReadingProgressRepository(androidDatabase: AndroidDatabase): ReadingProgressRepository = | ||
ReadingProgressRepository(AndroidReadingProgressStorage(androidDatabase)) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideSettingsRepository(androidDatabase: AndroidDatabase): SettingsRepository = | ||
SettingsRepository(AndroidSettingsStorage(androidDatabase)) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideStrongNumberRepository(androidDatabase: AndroidDatabase): StrongNumberRepository = | ||
StrongNumberRepository(AndroidStrongNumberStorage(androidDatabase), HttpStrongNumberService()) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideTranslationRepository(androidDatabase: AndroidDatabase): TranslationRepository = | ||
TranslationRepository(AndroidTranslationStorage(androidDatabase), HttpTranslationService()) | ||
} |
75 changes: 75 additions & 0 deletions
75
.../androidTest/kotlin/me/xizzhu/android/joshua/annotated/bookmarks/BookmarksActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (C) 2020 Xizhi Zhu | ||
* | ||
* 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 me.xizzhu.android.joshua.annotated.bookmarks | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.LargeTest | ||
import me.xizzhu.android.joshua.annotated.bookmarks.list.BookmarkItem | ||
import me.xizzhu.android.joshua.core.BibleReadingManager | ||
import me.xizzhu.android.joshua.core.Bookmark | ||
import me.xizzhu.android.joshua.core.Constants | ||
import me.xizzhu.android.joshua.core.VerseIndex | ||
import me.xizzhu.android.joshua.core.repository.BookmarksRepository | ||
import me.xizzhu.android.joshua.tests.EspressoTestRule | ||
import me.xizzhu.android.joshua.tests.MockContents | ||
import me.xizzhu.android.joshua.tests.robots.BookmarksActivityRobot | ||
import org.junit.Rule | ||
import org.junit.runner.RunWith | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@LargeTest | ||
class BookmarksActivityTest { | ||
@get:Rule | ||
val activityRule = EspressoTestRule(BookmarksActivity::class.java) | ||
|
||
@Test | ||
fun testEmptyBookmarks() { | ||
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName) | ||
val robot = BookmarksActivityRobot(activityRule.activity) | ||
.isNoBookmarksDisplayed() | ||
|
||
BookmarksRepository.sortOrder.offer(Constants.SORT_BY_BOOK) | ||
robot.isNoBookmarksDisplayed() | ||
} | ||
|
||
@Test | ||
fun testBookmarks() { | ||
val now = System.currentTimeMillis() | ||
val bookmarks = listOf( | ||
Bookmark(VerseIndex(0, 0, 4), now), | ||
Bookmark(VerseIndex(0, 0, 0), now) | ||
) | ||
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName) | ||
BookmarksRepository.annotations = bookmarks | ||
BookmarksActivityRobot(activityRule.activity) | ||
.areBookmarksDisplayed(bookmarks.map { bookmark -> | ||
BookmarkItem( | ||
bookmark.verseIndex, | ||
MockContents.kjvBookNames[bookmark.verseIndex.bookIndex], | ||
MockContents.kjvBookShortNames[bookmark.verseIndex.bookIndex], | ||
MockContents.kjvVerses[bookmark.verseIndex.verseIndex].text.text, | ||
Constants.DEFAULT_SORT_ORDER, | ||
{} | ||
) | ||
}) | ||
.clickBookmark(0) | ||
|
||
assertEquals(VerseIndex(0, 0, 4), BibleReadingManager.currentVerseIndex.value) | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...ndroidTest/kotlin/me/xizzhu/android/joshua/annotated/highlights/HighlightsActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (C) 2020 Xizhi Zhu | ||
* | ||
* 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 me.xizzhu.android.joshua.annotated.highlights | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.LargeTest | ||
import me.xizzhu.android.joshua.annotated.highlights.list.HighlightItem | ||
import me.xizzhu.android.joshua.core.* | ||
import me.xizzhu.android.joshua.core.repository.HighlightsRepository | ||
import me.xizzhu.android.joshua.tests.EspressoTestRule | ||
import me.xizzhu.android.joshua.tests.MockContents | ||
import me.xizzhu.android.joshua.tests.robots.HighlightsActivityRobot | ||
import org.junit.Rule | ||
import org.junit.runner.RunWith | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@LargeTest | ||
class HighlightsActivityTest { | ||
@get:Rule | ||
val activityRule = EspressoTestRule(HighlightsActivity::class.java) | ||
|
||
@Test | ||
fun testEmptyHighlights() { | ||
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName) | ||
val robot = HighlightsActivityRobot(activityRule.activity) | ||
.isNoHighlightsDisplayed() | ||
|
||
HighlightsRepository.sortOrder.offer(Constants.SORT_BY_BOOK) | ||
robot.isNoHighlightsDisplayed() | ||
} | ||
|
||
@Test | ||
fun testHighlights() { | ||
val now = System.currentTimeMillis() | ||
val highlights = listOf( | ||
Highlight(VerseIndex(0, 0, 4), Highlight.COLOR_BLUE, now), | ||
Highlight(VerseIndex(0, 0, 0), Highlight.COLOR_PINK, now) | ||
) | ||
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName) | ||
HighlightsRepository.annotations = highlights | ||
HighlightsActivityRobot(activityRule.activity) | ||
.areHighlightsDisplayed(highlights.map { highlight -> | ||
HighlightItem( | ||
highlight.verseIndex, | ||
MockContents.kjvBookNames[highlight.verseIndex.bookIndex], | ||
MockContents.kjvBookShortNames[highlight.verseIndex.bookIndex], | ||
MockContents.kjvVerses[highlight.verseIndex.verseIndex].text.text, | ||
highlight.color, | ||
Constants.DEFAULT_SORT_ORDER, | ||
{} | ||
) | ||
}) | ||
.clickHighlight(0) | ||
|
||
assertEquals(VerseIndex(0, 0, 4), BibleReadingManager.currentVerseIndex.value) | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
app/src/androidTest/kotlin/me/xizzhu/android/joshua/annotated/notes/NotesActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (C) 2020 Xizhi Zhu | ||
* | ||
* 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 me.xizzhu.android.joshua.annotated.notes | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.LargeTest | ||
import me.xizzhu.android.joshua.annotated.notes.list.NoteItem | ||
import me.xizzhu.android.joshua.core.* | ||
import me.xizzhu.android.joshua.core.repository.NotesRepository | ||
import me.xizzhu.android.joshua.tests.EspressoTestRule | ||
import me.xizzhu.android.joshua.tests.MockContents | ||
import me.xizzhu.android.joshua.tests.robots.NotesActivityRobot | ||
import org.junit.Rule | ||
import org.junit.runner.RunWith | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@LargeTest | ||
class NotesActivityTest { | ||
@get:Rule | ||
val activityRule = EspressoTestRule(NotesActivity::class.java) | ||
|
||
@Test | ||
fun testEmptyNotes() { | ||
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName) | ||
val robot = NotesActivityRobot(activityRule.activity) | ||
.isNoNotesDisplayed() | ||
|
||
NotesRepository.sortOrder.offer(Constants.SORT_BY_BOOK) | ||
robot.isNoNotesDisplayed() | ||
} | ||
|
||
@Test | ||
fun testNotes() { | ||
val now = System.currentTimeMillis() | ||
val notes = listOf( | ||
Note(VerseIndex(0, 0, 4), "some random note", now), | ||
Note(VerseIndex(0, 0, 0), "more sample", now) | ||
) | ||
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName) | ||
NotesRepository.annotations = notes | ||
NotesActivityRobot(activityRule.activity) | ||
.areNotesDisplayed(notes.map { note -> | ||
NoteItem( | ||
note.verseIndex, | ||
MockContents.kjvBookShortNames[note.verseIndex.bookIndex], | ||
MockContents.kjvVerses[note.verseIndex.verseIndex].text.text, | ||
note.note, | ||
{} | ||
) | ||
}) | ||
.clickNote(0) | ||
|
||
assertEquals(VerseIndex(0, 0, 4), BibleReadingManager.currentVerseIndex.value) | ||
} | ||
} |
Oops, something went wrong.