@@ -30,6 +30,9 @@ class UploadPresenterTest {
30
30
@Mock
31
31
private lateinit var uploadableFile: UploadableFile
32
32
33
+ @Mock
34
+ private lateinit var anotherUploadableFile: UploadableFile
35
+
33
36
@InjectMocks
34
37
var uploadPresenter: UploadPresenter ? = null
35
38
@@ -44,7 +47,6 @@ class UploadPresenterTest {
44
47
MockitoAnnotations .initMocks(this )
45
48
uploadPresenter?.onAttachView(view)
46
49
`when `(repository?.buildContributions()).thenReturn(Observable .just(contribution))
47
- `when `(view?.isLoggedIn).thenReturn(true )
48
50
uploadableFiles.add(uploadableFile)
49
51
`when `(view?.uploadableFiles).thenReturn(uploadableFiles)
50
52
`when `(uploadableFile?.filePath).thenReturn(" data://test" )
@@ -54,7 +56,8 @@ class UploadPresenterTest {
54
56
* unit test case for method UploadPresenter.handleSubmit
55
57
*/
56
58
@Test
57
- fun handleSubmitTest () {
59
+ fun handleSubmitTestUserLoggedIn () {
60
+ `when `(view?.isLoggedIn).thenReturn(true )
58
61
uploadPresenter?.handleSubmit()
59
62
verify(view)?.isLoggedIn
60
63
verify(view)?.showProgress(true )
@@ -63,13 +66,57 @@ class UploadPresenterTest {
63
66
}
64
67
65
68
/* *
66
- * unit test for UploadMediaPresenter.deletePictureAtIndex
69
+ * unit test case for method UploadPresenter.handleSubmit
70
+ */
71
+ @Test
72
+ fun handleSubmitTestUserNotLoggedIn () {
73
+ `when `(view?.isLoggedIn).thenReturn(false )
74
+ uploadPresenter?.handleSubmit()
75
+ verify(view)?.isLoggedIn
76
+ verify(view)?.askUserToLogIn()
77
+
78
+ }
79
+
80
+ private fun deletePictureBaseTest (){
81
+ uploadableFiles.clear()
82
+ }
83
+
84
+ /* *
85
+ * Test which asserts If the next fragment to be shown is not one of the MediaDetailsFragment, lets hide the top card
67
86
*/
68
87
@Test
69
- fun deletePictureAtIndexTest () {
88
+ fun hideTopCardWhenReachedTheLastFile (){
89
+ deletePictureBaseTest()
90
+ uploadableFiles.add(uploadableFile)
70
91
uploadPresenter?.deletePictureAtIndex(0 )
92
+ verify(view)?.showHideTopCard(false )
93
+ verify(repository)?.deletePicture(ArgumentMatchers .anyString())
94
+ }
95
+
96
+ /* *
97
+ * Test media deletion during single upload
98
+ */
99
+ @Test
100
+ fun testDeleteWhenSingleUpload (){
101
+ deletePictureBaseTest()
102
+ uploadableFiles.add(uploadableFile)
103
+ uploadPresenter?.deletePictureAtIndex(0 )
104
+ verify(view)?.showHideTopCard(false )
71
105
verify(repository)?.deletePicture(ArgumentMatchers .anyString())
72
106
verify(view)?.showMessage(ArgumentMatchers .anyInt())// As there is only one while which we are asking for deletion, upload should be cancelled and this flow should be triggered
73
107
verify(view)?.finish()
74
108
}
109
+
110
+ /* *
111
+ * Test media deletion during multiple upload
112
+ */
113
+ @Test
114
+ fun testDeleteWhenMultipleFilesUpload (){
115
+ deletePictureBaseTest()
116
+ uploadableFiles.add(uploadableFile)
117
+ uploadableFiles.add(anotherUploadableFile)
118
+ uploadPresenter?.deletePictureAtIndex(0 )
119
+ verify(view)?.onUploadMediaDeleted(0 )
120
+ verify(view)?.updateTopCardTitle()
121
+ }
75
122
}
0 commit comments