1
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
2
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
3
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4
- /* global describe, it, before */
4
+ /* global describe, it, before, after */
5
5
6
+ const os = require ( 'os' )
7
+ const path = require ( 'path' )
8
+ const fs = require ( 'fs-extra' )
6
9
const Brave = require ( '../lib/brave' )
7
10
const {
8
11
urlInput,
@@ -11,11 +14,13 @@ const {
11
14
downloadPause,
12
15
downloadResume,
13
16
downloadCancel,
17
+ downloadComplete,
14
18
downloadReDownload,
15
19
downloadRemoveFromList,
16
20
downloadDelete,
17
21
downloadDeleteConfirm
18
22
} = require ( '../lib/selectors' )
23
+ const settingsConst = require ( '../../js/constants/settings' )
19
24
20
25
function * setup ( client ) {
21
26
yield client
@@ -24,75 +29,123 @@ function * setup (client) {
24
29
. waitForVisible ( urlInput )
25
30
}
26
31
27
- describe ( 'downloadItem test' , function ( ) {
28
- Brave . beforeAll ( this )
29
- before ( function * ( ) {
30
- this . downloadSite = 'http://releases.ubuntu.com/16.04.2/ubuntu-16.04.2-desktop-amd64.iso'
31
- yield setup ( this . app . client )
32
+ describe ( 'Downloads' , function ( ) {
33
+ describe ( 'Location and file naming tests' , function ( ) {
34
+ let tempDownloadPath
35
+ Brave . beforeAll ( this )
36
+ before ( function * ( ) {
37
+ tempDownloadPath = path . join ( os . tmpdir ( ) , 'brave-test' , 'downloads' )
38
+ this . downloadFile = 'Brave_proudly-partner_badges.zip'
39
+ this . downloadSite = `https://brave.com/about/${ this . downloadFile } `
40
+ this . renamedFile = this . downloadFile . slice ( 0 , this . downloadFile . indexOf ( '.' ) ) + ' (1)' + this . downloadFile . slice ( this . downloadFile . indexOf ( '.' ) )
32
41
33
- yield this . app . client
34
- . waitForUrl ( Brave . newTabUrl )
35
- . url ( this . downloadSite )
36
- } )
42
+ yield setup ( this . app . client )
37
43
38
- it ( 'check if download bar is shown' , function * ( ) {
39
- yield this . app . client
40
- . windowByUrl ( Brave . browserWindowUrl )
41
- . waitForElementCount ( downloadBar , 1 )
42
- } )
44
+ yield this . app . client
45
+ . waitForUrl ( Brave . newTabUrl )
46
+ } )
43
47
44
- it ( 'check if you can pause download' , function * ( ) {
45
- yield this . app . client
46
- . moveToObject ( downloadItem )
47
- . waitForElementCount ( downloadPause , 1 )
48
- . click ( downloadPause )
49
- . waitForElementCount ( downloadResume , 1 )
50
- } )
48
+ after ( function * ( ) {
49
+ yield new Promise ( ( resolve , reject ) => {
50
+ return fs . remove ( tempDownloadPath , ( err ) => err ? reject ( err ) : resolve ( ) )
51
+ } )
52
+ } )
51
53
52
- it ( 'check if you can resume download' , function * ( ) {
53
- yield this . app . client
54
- . waitForElementCount ( downloadResume , 1 )
55
- . click ( downloadResume )
56
- . waitForElementCount ( downloadPause , 1 )
57
- } )
54
+ it ( 'check if first download completes ' , function * ( ) {
55
+ yield this . app . client
56
+ . windowByUrl ( Brave . browserWindowUrl )
57
+ . changeSetting ( settingsConst . DOWNLOAD_DEFAULT_PATH , tempDownloadPath )
58
+ . url ( this . downloadSite )
59
+ . waitForElementCount ( downloadComplete , 1 )
58
60
59
- it ( 'check if you can cancel download' , function * ( ) {
60
- yield this . app . client
61
- . waitForElementCount ( downloadPause , 1 )
62
- . click ( downloadCancel )
63
- . waitForElementCount ( downloadReDownload , 1 )
64
- } )
61
+ yield new Promise ( ( resolve , reject ) => {
62
+ return fs . exists ( path . join ( tempDownloadPath , this . downloadFile ) , ( res ) => res ? resolve ( res ) : reject ( res ) )
63
+ } ) . should . eventually . be . true
64
+ } )
65
65
66
- it ( 'check if you can re- download' , function * ( ) {
67
- yield this . app . client
68
- . waitForElementCount ( downloadReDownload , 1 )
69
- . click ( downloadReDownload )
70
- . waitForElementCount ( downloadPause , 1 )
71
- } )
66
+ it ( 'check if second download completes and is renamed ' , function * ( ) {
67
+ yield this . app . client
68
+ . windowByUrl ( Brave . browserWindowUrl )
69
+ . changeSetting ( settingsConst . DOWNLOAD_DEFAULT_PATH , tempDownloadPath )
70
+ . url ( this . downloadSite )
71
+ . waitForElementCount ( downloadComplete , 2 )
72
72
73
- it ( 'check if you can remove item from the list' , function * ( ) {
74
- yield this . app . client
75
- . moveToObject ( downloadItem )
76
- . waitForElementCount ( downloadPause , 1 )
77
- . click ( downloadCancel )
78
- . waitForElementCount ( downloadReDownload , 1 )
79
- . click ( downloadRemoveFromList )
80
- . waitForElementCount ( downloadBar , 0 )
73
+ yield new Promise ( ( resolve , reject ) => {
74
+ return fs . exists ( path . join ( tempDownloadPath , this . renamedFile ) , ( res ) => res ? resolve ( res ) : reject ( res ) )
75
+ } ) . should . eventually . be . true
76
+ } )
81
77
} )
82
78
83
- it ( 'check if you can delete downloaded item' , function * ( ) {
84
- yield this . app . client
85
- . tabByIndex ( 0 )
86
- . url ( this . downloadSite )
87
- . windowByUrl ( Brave . browserWindowUrl )
88
- . waitForElementCount ( downloadBar , 1 )
89
- . moveToObject ( downloadItem )
90
- . waitForElementCount ( downloadPause , 1 )
91
- . click ( downloadCancel )
92
- . waitForElementCount ( downloadReDownload , 1 )
93
- . click ( downloadDelete )
94
- . waitForElementCount ( downloadDeleteConfirm , 1 )
95
- . click ( downloadDeleteConfirm )
96
- . waitForElementCount ( downloadBar , 0 )
79
+ describe ( 'Item and bar tests' , function ( ) {
80
+ Brave . beforeAll ( this )
81
+ before ( function * ( ) {
82
+ this . downloadSite = 'http://releases.ubuntu.com/16.04.2/ubuntu-16.04.2-desktop-amd64.iso'
83
+ yield setup ( this . app . client )
84
+
85
+ yield this . app . client
86
+ . waitForUrl ( Brave . newTabUrl )
87
+ . url ( this . downloadSite )
88
+ } )
89
+
90
+ it ( 'check if download bar is shown' , function * ( ) {
91
+ yield this . app . client
92
+ . windowByUrl ( Brave . browserWindowUrl )
93
+ . waitForElementCount ( downloadBar , 1 )
94
+ } )
95
+
96
+ it ( 'check if you can pause download' , function * ( ) {
97
+ yield this . app . client
98
+ . moveToObject ( downloadItem )
99
+ . waitForElementCount ( downloadPause , 1 )
100
+ . click ( downloadPause )
101
+ . waitForElementCount ( downloadResume , 1 )
102
+ } )
103
+
104
+ it ( 'check if you can resume download' , function * ( ) {
105
+ yield this . app . client
106
+ . waitForElementCount ( downloadResume , 1 )
107
+ . click ( downloadResume )
108
+ . waitForElementCount ( downloadPause , 1 )
109
+ } )
110
+
111
+ it ( 'check if you can cancel download' , function * ( ) {
112
+ yield this . app . client
113
+ . waitForElementCount ( downloadPause , 1 )
114
+ . click ( downloadCancel )
115
+ . waitForElementCount ( downloadReDownload , 1 )
116
+ } )
117
+
118
+ it ( 'check if you can re-download' , function * ( ) {
119
+ yield this . app . client
120
+ . waitForElementCount ( downloadReDownload , 1 )
121
+ . click ( downloadReDownload )
122
+ . waitForElementCount ( downloadPause , 1 )
123
+ } )
124
+
125
+ it ( 'check if you can remove item from the list' , function * ( ) {
126
+ yield this . app . client
127
+ . moveToObject ( downloadItem )
128
+ . waitForElementCount ( downloadPause , 1 )
129
+ . click ( downloadCancel )
130
+ . waitForElementCount ( downloadReDownload , 1 )
131
+ . click ( downloadRemoveFromList )
132
+ . waitForElementCount ( downloadBar , 0 )
133
+ } )
134
+
135
+ it ( 'check if you can delete downloaded item' , function * ( ) {
136
+ yield this . app . client
137
+ . tabByIndex ( 0 )
138
+ . url ( this . downloadSite )
139
+ . windowByUrl ( Brave . browserWindowUrl )
140
+ . waitForElementCount ( downloadBar , 1 )
141
+ . moveToObject ( downloadItem )
142
+ . waitForElementCount ( downloadPause , 1 )
143
+ . click ( downloadCancel )
144
+ . waitForElementCount ( downloadReDownload , 1 )
145
+ . click ( downloadDelete )
146
+ . waitForElementCount ( downloadDeleteConfirm , 1 )
147
+ . click ( downloadDeleteConfirm )
148
+ . waitForElementCount ( downloadBar , 0 )
149
+ } )
97
150
} )
98
151
} )
0 commit comments