diff --git a/test/screenshots/darwin/torrent-list-cosmos-delete-data.png b/test/screenshots/darwin/torrent-list-cosmos-delete-data.png new file mode 100644 index 00000000..7f74ef84 Binary files /dev/null and b/test/screenshots/darwin/torrent-list-cosmos-delete-data.png differ diff --git a/test/screenshots/darwin/torrent-list-cosmos-deleted.png b/test/screenshots/darwin/torrent-list-cosmos-deleted.png new file mode 100644 index 00000000..866c4109 Binary files /dev/null and b/test/screenshots/darwin/torrent-list-cosmos-deleted.png differ diff --git a/test/setup.js b/test/setup.js index ee28d82f..09c582b1 100644 --- a/test/setup.js +++ b/test/setup.js @@ -52,9 +52,9 @@ function waitForLoad (app, t, opts) { }) } -// Returns a promise that resolves after 'ms' milliseconds. Default: 500 +// Returns a promise that resolves after 'ms' milliseconds. Default: 1 second function wait (ms) { - if (ms === undefined) ms = 500 // Default: wait long enough for the UI to update + if (ms === undefined) ms = 1000 // Default: wait long enough for the UI to update return new Promise(function (resolve, reject) { setTimeout(resolve, ms) }) @@ -97,6 +97,9 @@ function wipeTestDataDir () { fs.mkdirpSync(TEST_DOWNLOAD_DIR) // Downloads/ is inside of TEST_DATA_DIR } +// Checks a given folder under Downloads. +// Makes sure that the filenames match exactly. +// If `filenames` is null, asserts that the folder doesn't exist. function compareDownloadFolder (t, dirname, filenames) { const dirpath = path.join(TEST_DOWNLOAD_DIR, dirname) try { @@ -105,7 +108,11 @@ function compareDownloadFolder (t, dirname, filenames) { 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) + if (e.code === 'ENOENT') { + t.equal(filenames, null, 'download folder missing: ' + dirname) + } else { + console.error(e) + t.fail('unexpected error getting download folder: ' + dirname) + } } } diff --git a/test/test-torrent-list.js b/test/test-torrent-list.js index 16b323e8..981cdc1e 100644 --- a/test/test-torrent-list.js +++ b/test/test-torrent-list.js @@ -2,7 +2,7 @@ const test = require('tape') const fs = require('fs-extra') const setup = require('./setup') -test.skip('torrent-list: show download path missing', function (t) { +test('torrent-list: show download path missing', function (t) { setup.wipeTestDataDir() fs.removeSync(setup.TEST_DOWNLOAD_DIR) @@ -23,7 +23,7 @@ test.skip('torrent-list: show download path missing', function (t) { (err) => setup.endTest(app, t, err || 'error')) }) -test.skip('torrent-list: start, stop, and delete torrents', function (t) { +test('torrent-list: start, stop, and delete torrents', function (t) { setup.wipeTestDataDir() const app = setup.createApp() @@ -81,7 +81,7 @@ test('torrent-list: expand torrent, unselect file', function (t) { .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(() => app.client.waitUntilTextExists('.torrent-list', 'peers')) .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', [ @@ -97,6 +97,16 @@ test('torrent-list: expand torrent, unselect file', function (t) { 'CosmosLaundromatFirstCycle_meta.sqlite', 'CosmosLaundromatFirstCycle_meta.xml' ])) + // Delete torrent plus data + // Spectron doesn't have proper support for menu clicks yet... + .then(() => app.webContents.executeJavaScript( + 'dispatch("confirmDeleteTorrent", "6a02592d2bbc069628cd5ed8a54f88ee06ac0ba5", true)')) + .then(() => setup.wait()) + .then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-cosmos-delete-data')) + // Click confirm + .then(() => app.client.click('.control.ok')) + .then(() => setup.wait()) + .then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-cosmos-deleted')) // Make sure that all the files are gone .then(() => setup.compareDownloadFolder(t, 'CosmosLaundromatFirstCycle', null)) .then(() => setup.endTest(app, t),