forked from finos/SymphonyElectron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDownloadManager.test.js
90 lines (67 loc) · 3.53 KB
/
DownloadManager.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const downloadManager = require('../js/downloadManager');
const electron = require('./__mocks__/electron');
describe('download manager', function() {
describe('Download Manager to create DOM once download is initiated', function() {
beforeEach(function() {
global.document.body.innerHTML =
'<div id="download-main">' +
'</div>';
});
it('should inject download bar element into DOM once download is initiated', function() {
electron.ipcRenderer.send('downloadCompleted', { _id: '12345', fileName: 'test.png', total: 100 });
expect(document.getElementsByClassName('text-cutoff')[0].innerHTML).toBe('test.png');
expect(document.getElementById('per').innerHTML).toBe('100 Downloaded');
});
it('should inject multiple download items during multiple downloads', function() {
electron.ipcRenderer.send('downloadCompleted', { _id: '12345', fileName: 'test (1).png', total: 100 });
electron.ipcRenderer.send('downloadCompleted', { _id: '67890', fileName: 'test (2).png', total: 200 });
let fileNames = document.getElementsByClassName('text-cutoff');
let fNames = [];
for (var i = 0; i < fileNames.length; i++) {
fNames.push(fileNames[i].innerHTML);
}
expect(fNames).toEqual(expect.arrayContaining(['test (1).png', 'test (2).png']));
expect(document.getElementById('per').innerHTML).toBe('100 Downloaded');
let downloadElements = document.getElementsByClassName('download-element');
expect(downloadElements[0].id).toBe('67890');
expect(downloadElements[1].id).toBe('12345');
});
});
describe('Download Manager to initiate footer', function() {
beforeEach(function() {
global.document.body.innerHTML =
'<div id="footer" class="hidden">' +
'<div id="download-manager-footer">' +
'<div id="download-main">' +
'</div>' +
'</div>' +
'</div>';
});
it('should inject dom element once download is completed', function() {
electron.ipcRenderer.send('downloadProgress');
expect(document.getElementById('footer').classList).not.toContain('hidden');
});
it('should remove the download bar and clear up the download items', function() {
electron.ipcRenderer.send('downloadProgress');
expect(document.getElementById('footer').classList).not.toContain('hidden');
document.getElementById('close-download-bar').click();
expect(document.getElementById('footer').classList).toContain('hidden');
});
});
describe('Download Manager to initiate footer', function() {
beforeEach(function() {
global.document.body.innerHTML =
'<div id="footer" class="hidden">' +
'<div id="download-manager-footer">' +
'<div id="download-main">' +
'</div>' +
'</div>' +
'</div>';
});
it('should inject ul element if not found', function() {
electron.ipcRenderer.send('downloadProgress');
expect(document.getElementById('download-main')).not.toBeNull();
expect(document.getElementById('footer').classList).not.toContain('hidden');
});
});
});