Integration test: torrent list
@@ -22,7 +22,7 @@
|
||||
"deep-equal": "^1.0.1",
|
||||
"dlnacasts": "^0.1.0",
|
||||
"drag-drop": "^2.12.1",
|
||||
"electron": "1.3.3",
|
||||
"electron": "1.3.5",
|
||||
"es6-error": "^3.0.1",
|
||||
"fs-extra": "^0.30.0",
|
||||
"iso-639-1": "^1.2.1",
|
||||
|
||||
@@ -36,26 +36,31 @@ module.exports = {
|
||||
|
||||
DEFAULT_TORRENTS: [
|
||||
{
|
||||
testID: 'bbb',
|
||||
name: 'Big Buck Bunny',
|
||||
posterFileName: 'bigBuckBunny.jpg',
|
||||
torrentFileName: 'bigBuckBunny.torrent'
|
||||
},
|
||||
{
|
||||
testID: 'cosmos',
|
||||
name: 'Cosmos Laundromat (Preview)',
|
||||
posterFileName: 'cosmosLaundromat.jpg',
|
||||
torrentFileName: 'cosmosLaundromat.torrent'
|
||||
},
|
||||
{
|
||||
testID: 'sintel',
|
||||
name: 'Sintel',
|
||||
posterFileName: 'sintel.jpg',
|
||||
torrentFileName: 'sintel.torrent'
|
||||
},
|
||||
{
|
||||
testID: 'tears',
|
||||
name: 'Tears of Steel',
|
||||
posterFileName: 'tearsOfSteel.jpg',
|
||||
torrentFileName: 'tearsOfSteel.torrent'
|
||||
},
|
||||
{
|
||||
testID: 'wired',
|
||||
name: 'The WIRED CD - Rip. Sample. Mash. Share.',
|
||||
posterFileName: 'wiredCd.jpg',
|
||||
torrentFileName: 'wiredCd.torrent'
|
||||
@@ -111,7 +116,7 @@ function getPath (key) {
|
||||
if (process.type === 'renderer') {
|
||||
return electron.remote.app.getPath(key)
|
||||
} else {
|
||||
electron.app.getPath(key)
|
||||
return electron.app.getPath(key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@ module.exports = class ModalOKCancel extends React.Component {
|
||||
return (
|
||||
<div className='float-right'>
|
||||
<FlatButton
|
||||
className='control'
|
||||
className='control cancel'
|
||||
style={cancelStyle}
|
||||
label={cancelText}
|
||||
onClick={onCancel} />
|
||||
<RaisedButton
|
||||
className='control'
|
||||
className='control ok'
|
||||
primary
|
||||
label={okText}
|
||||
onClick={onOK} />
|
||||
|
||||
@@ -151,7 +151,8 @@ function setupSavedState (cb) {
|
||||
torrentFileName: parsedTorrent.infoHash + '.torrent',
|
||||
magnetURI: parseTorrent.toMagnetURI(parsedTorrent),
|
||||
files: parsedTorrent.files,
|
||||
selections: parsedTorrent.files.map((x) => true)
|
||||
selections: parsedTorrent.files.map((x) => true),
|
||||
testID: t.testID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ State.load(onState)
|
||||
function onState (err, _state) {
|
||||
if (err) return onError(err)
|
||||
state = window.state = _state // Make available for easier debugging
|
||||
window.dispatch = dispatch
|
||||
|
||||
telemetry.init(state)
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ module.exports = class TorrentList extends React.Component {
|
||||
if (!torrentSummary.torrentKey) throw new InvalidTorrentError('Missing torrentKey')
|
||||
return (
|
||||
<div
|
||||
id={torrentSummary.testID && ('torrent-' + torrentSummary.testID)}
|
||||
key={torrentSummary.torrentKey}
|
||||
style={style}
|
||||
className={classes.join(' ')}
|
||||
@@ -346,7 +347,7 @@ module.exports = class TorrentList extends React.Component {
|
||||
</td>
|
||||
<td className='col-select'
|
||||
onClick={dispatcher('toggleTorrentFile', infoHash, index)}>
|
||||
<i className='icon'>{isSelected ? 'close' : 'add'}</i>
|
||||
<i className='icon deselect-file'>{isSelected ? 'close' : 'add'}</i>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>WebTorrent Desktop</title>
|
||||
<title>Main Window</title>
|
||||
<link rel="stylesheet" href="main.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>WebTorrent Desktop</title>
|
||||
<title>WebTorrent Hidden Window</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: #282828;
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
const test = require('tape')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const setup = require('./setup')
|
||||
|
||||
console.log('Creating test dir: ' + setup.TEST_DATA_DIR)
|
||||
const DOWNLOAD_DIR = path.join(setup.TEST_DATA_DIR, 'Downloads')
|
||||
fs.mkdirpSync(DOWNLOAD_DIR)
|
||||
console.log('Creating download dir: ' + setup.TEST_DOWNLOAD_DIR)
|
||||
fs.mkdirpSync(setup.TEST_DOWNLOAD_DIR)
|
||||
|
||||
test.onFinish(function () {
|
||||
console.log('Removing test dir...')
|
||||
fs.removeSync(setup.TEST_DATA_DIR)
|
||||
console.log('Removing test dir: ' + setup.TEST_DATA_DIR)
|
||||
fs.removeSync(setup.TEST_DATA_DIR) // includes download dir
|
||||
})
|
||||
|
||||
test('app runs', function (t) {
|
||||
@@ -22,28 +20,11 @@ test('app runs', function (t) {
|
||||
(err) => setup.endTest(app, t, err || 'error'))
|
||||
})
|
||||
|
||||
test('show download path missing', function (t) {
|
||||
fs.removeSync(DOWNLOAD_DIR)
|
||||
|
||||
t.timeoutAfter(10e3)
|
||||
const app = setup.createApp()
|
||||
setup.waitForLoad(app, t)
|
||||
.then(() => app.client.getTitle())
|
||||
.then((text) => console.log('Title ' + text))
|
||||
.then(() => app.client.waitUntilTextExists('.torrent-list', 'Download path missing'))
|
||||
.then((err) => t.notOk(err))
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-download-path-missing'))
|
||||
.then(() => app.client.click('a'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => app.browserWindow.getTitle())
|
||||
.then((windowTitle) => t.equal(windowTitle, 'Preferences', 'window title'))
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'prefs-basic'))
|
||||
.then(() => setup.endTest(app, t),
|
||||
(err) => setup.endTest(app, t, err || 'error'))
|
||||
})
|
||||
console.log('Testing the torrent list (home page)...')
|
||||
setup.wipeTestDataDir()
|
||||
require('./test-torrent-list')
|
||||
|
||||
// TODO:
|
||||
// require('./test-torrent-list')
|
||||
// require('./test-add-torrent')
|
||||
// require('./test-create-torrent')
|
||||
// require('./test-prefs')
|
||||
|
||||
BIN
test/screenshots/darwin/torrent-list-cosmos-expand-deselect.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
test/screenshots/darwin/torrent-list-cosmos-expand-start.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
test/screenshots/darwin/torrent-list-cosmos-expand.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
test/screenshots/darwin/torrent-list-cosmos-hover.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
test/screenshots/darwin/torrent-list-delete-prompt.png
Normal file
|
After Width: | Height: | Size: 617 KiB |
BIN
test/screenshots/darwin/torrent-list-delete.png
Normal file
|
After Width: | Height: | Size: 617 KiB |
BIN
test/screenshots/darwin/torrent-list-deleted.png
Normal file
|
After Width: | Height: | Size: 777 KiB |
BIN
test/screenshots/darwin/torrent-list-hover-download.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
test/screenshots/darwin/torrent-list-hover.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
test/screenshots/darwin/torrent-list-start-download.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
test/screenshots/darwin/torrent-list-stop-download.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
@@ -3,14 +3,18 @@ const Application = require('spectron').Application
|
||||
const fs = require('fs-extra')
|
||||
|
||||
const TEST_DATA_DIR = path.join(__dirname, 'tempTestData')
|
||||
const TEST_DOWNLOAD_DIR = path.join(TEST_DATA_DIR, 'Downloads')
|
||||
|
||||
module.exports = {
|
||||
TEST_DATA_DIR,
|
||||
TEST_DOWNLOAD_DIR,
|
||||
createApp,
|
||||
endTest,
|
||||
screenshotCreateOrCompare,
|
||||
compareDownloadFolder,
|
||||
waitForLoad,
|
||||
wait
|
||||
wait,
|
||||
wipeTestDataDir
|
||||
}
|
||||
|
||||
// Runs WebTorrent Desktop.
|
||||
@@ -26,8 +30,16 @@ function createApp (t) {
|
||||
}
|
||||
|
||||
// Starts the app, waits for it to load, returns a promise
|
||||
function waitForLoad (app, t) {
|
||||
function waitForLoad (app, t, opts) {
|
||||
if (!opts) opts = {}
|
||||
return app.start().then(function () {
|
||||
return app.client.waitUntilWindowLoaded()
|
||||
}).then(function () {
|
||||
// Offline mode? Disable internet in the webtorrent window
|
||||
// TODO. For now, just run integration tests with internet turned off.
|
||||
// Spectron is poorly documented, and contrary to the docs, webContents.session is missing
|
||||
// That is the correct API (in theory) to put the app in offline mode
|
||||
}).then(function () {
|
||||
// Switch to the main window. Index 0 is apparently the hidden webtorrent window...
|
||||
return app.client.windowByIndex(1)
|
||||
}).then(function () {
|
||||
@@ -36,7 +48,7 @@ function waitForLoad (app, t) {
|
||||
return app.webContents.getTitle()
|
||||
}).then(function (title) {
|
||||
// Note the window title is WebTorrent (BETA), this is the HTML <title>
|
||||
t.equal(title, 'WebTorrent Desktop', 'html title')
|
||||
t.equal(title, 'Main Window', 'html title')
|
||||
})
|
||||
}
|
||||
|
||||
@@ -78,3 +90,22 @@ function screenshotCreateOrCompare (app, t, name) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Resets the test directory, containing config.json, torrents, downloads, etc
|
||||
function wipeTestDataDir () {
|
||||
fs.removeSync(TEST_DATA_DIR)
|
||||
fs.mkdirpSync(TEST_DOWNLOAD_DIR) // Downloads/ is inside of TEST_DATA_DIR
|
||||
}
|
||||
|
||||
function compareDownloadFolder (t, dirname, filenames) {
|
||||
const dirpath = path.join(TEST_DOWNLOAD_DIR, dirname)
|
||||
try {
|
||||
const actualFilenames = fs.readdirSync(dirpath)
|
||||
const expectedSorted = filenames.slice().sort()
|
||||
const actualSorted = actualFilenames.slice().sort()
|
||||
t.deepEqual(actualSorted, expectedSorted, 'download folder contents: ' + dirname)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
t.equal(filenames, null, 'download folder missing: ' + dirname)
|
||||
}
|
||||
}
|
||||
|
||||
104
test/test-torrent-list.js
Normal file
@@ -0,0 +1,104 @@
|
||||
const test = require('tape')
|
||||
const fs = require('fs-extra')
|
||||
const setup = require('./setup')
|
||||
|
||||
test.skip('torrent-list: show download path missing', function (t) {
|
||||
setup.wipeTestDataDir()
|
||||
fs.removeSync(setup.TEST_DOWNLOAD_DIR)
|
||||
|
||||
t.timeoutAfter(10e3)
|
||||
const app = setup.createApp()
|
||||
setup.waitForLoad(app, t)
|
||||
.then(() => app.client.getTitle())
|
||||
.then((text) => console.log('Title ' + text))
|
||||
.then(() => app.client.waitUntilTextExists('.torrent-list', 'Download path missing'))
|
||||
.then((err) => t.notOk(err))
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-download-path-missing'))
|
||||
.then(() => app.client.click('a'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => app.browserWindow.getTitle())
|
||||
.then((windowTitle) => t.equal(windowTitle, 'Preferences', 'window title'))
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'prefs-basic'))
|
||||
.then(() => setup.endTest(app, t),
|
||||
(err) => setup.endTest(app, t, err || 'error'))
|
||||
})
|
||||
|
||||
test.skip('torrent-list: start, stop, and delete torrents', function (t) {
|
||||
setup.wipeTestDataDir()
|
||||
|
||||
const app = setup.createApp()
|
||||
setup.waitForLoad(app, t, {offline: true})
|
||||
.then(() => app.client.waitUntilTextExists('.torrent-list', 'Big Buck Bunny'))
|
||||
// Mouse over the first torrent
|
||||
.then(() => app.client.moveToObject('.torrent'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-hover'))
|
||||
// Click download on the first torrent, start downloading
|
||||
.then(() => app.client.click('.icon.download'))
|
||||
.then(() => app.client.waitUntilTextExists('.torrent-list', '276 MB'))
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-start-download'))
|
||||
// Click download on the first torrent again, stop downloading
|
||||
.then(() => app.client.click('.icon.download'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-hover-download'))
|
||||
// Click delete on the first torrent
|
||||
.then(() => app.client.click('.icon.delete'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-delete-prompt'))
|
||||
// Click cancel on the resulting confirmation dialog. Should be same as before.
|
||||
.then(() => app.client.click('.control.cancel'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-hover'))
|
||||
// Click delete on the first torrent again
|
||||
.then(() => app.client.click('.icon.delete'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-delete-prompt'))
|
||||
// This time, click OK to confirm.
|
||||
.then(() => app.client.click('.control.ok'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-deleted'))
|
||||
.then(() => setup.endTest(app, t),
|
||||
(err) => setup.endTest(app, t, err || 'error'))
|
||||
})
|
||||
|
||||
test('torrent-list: expand torrent, unselect file', function (t) {
|
||||
setup.wipeTestDataDir()
|
||||
|
||||
const app = setup.createApp()
|
||||
setup.waitForLoad(app, t, {offline: true})
|
||||
.then(() => app.client.waitUntilTextExists('.torrent-list', 'Big Buck Bunny'))
|
||||
// Mouse over the torrent
|
||||
.then(() => app.client.moveToObject('#torrent-cosmos'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-cosmos-hover'))
|
||||
// Click on the torrent, expand
|
||||
.then(() => app.client.click('#torrent-cosmos'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-cosmos-expand'))
|
||||
// Deselect the first file
|
||||
.then(() => app.client.click('#torrent-cosmos .icon.deselect-file'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-cosmos-expand-deselect'))
|
||||
// Start the torrent
|
||||
.then(() => app.client.click('#torrent-cosmos .icon.download'))
|
||||
.then(() => app.client.waitUntilTextExists('.torrent-list', '0%'))
|
||||
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-cosmos-expand-start'))
|
||||
// Make sure that it creates all files EXCEPT the deslected one
|
||||
.then(() => setup.compareDownloadFolder(t, 'CosmosLaundromatFirstCycle', [
|
||||
// TODO: the .gif should NOT be here, since we just deselected it.
|
||||
// This is a bug. See https://github.com/feross/webtorrent-desktop/issues/719
|
||||
'Cosmos Laundromat - First Cycle (1080p).gif',
|
||||
'Cosmos Laundromat - First Cycle (1080p).mp4',
|
||||
'Cosmos Laundromat - First Cycle (1080p).ogv',
|
||||
'CosmosLaundromat-FirstCycle1080p.en.srt',
|
||||
'CosmosLaundromat-FirstCycle1080p.es.srt',
|
||||
'CosmosLaundromat-FirstCycle1080p.fr.srt',
|
||||
'CosmosLaundromat-FirstCycle1080p.it.srt',
|
||||
'CosmosLaundromatFirstCycle_meta.sqlite',
|
||||
'CosmosLaundromatFirstCycle_meta.xml'
|
||||
]))
|
||||
// Make sure that all the files are gone
|
||||
.then(() => setup.compareDownloadFolder(t, 'CosmosLaundromatFirstCycle', null))
|
||||
.then(() => setup.endTest(app, t),
|
||||
(err) => setup.endTest(app, t, err || 'error'))
|
||||
})
|
||||