mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-02 21:13:32 +00:00
Reformat all code with Prettier.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
const TEST_APP_PRODUCT_NAME = 'ZulipTest';
|
||||
const TEST_APP_PRODUCT_NAME = "ZulipTest";
|
||||
|
||||
module.exports = {
|
||||
TEST_APP_PRODUCT_NAME
|
||||
TEST_APP_PRODUCT_NAME,
|
||||
};
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
'use strict';
|
||||
const test = require('tape');
|
||||
"use strict";
|
||||
const test = require("tape");
|
||||
|
||||
const setup = require('./setup');
|
||||
const setup = require("./setup");
|
||||
|
||||
test('app runs', async t => {
|
||||
t.timeoutAfter(10e3);
|
||||
setup.resetTestDataDir();
|
||||
const app = setup.createApp();
|
||||
try {
|
||||
await setup.waitForLoad(app, t);
|
||||
await app.client.windowByIndex(1); // Focus on webview
|
||||
await (await app.client.$('//*[@id="connect"]')).waitForExist(); // Id of the connect button
|
||||
await setup.endTest(app, t);
|
||||
} catch (error) {
|
||||
await setup.endTest(app, t, error || 'error');
|
||||
}
|
||||
test("app runs", async (t) => {
|
||||
t.timeoutAfter(10e3);
|
||||
setup.resetTestDataDir();
|
||||
const app = setup.createApp();
|
||||
try {
|
||||
await setup.waitForLoad(app, t);
|
||||
await app.client.windowByIndex(1); // Focus on webview
|
||||
await (await app.client.$('//*[@id="connect"]')).waitForExist(); // Id of the connect button
|
||||
await setup.endTest(app, t);
|
||||
} catch (error) {
|
||||
await setup.endTest(app, t, error || "error");
|
||||
}
|
||||
});
|
||||
|
||||
124
tests/setup.js
124
tests/setup.js
@@ -1,98 +1,108 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
"use strict";
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const rimraf = require('rimraf');
|
||||
const {Application} = require('spectron');
|
||||
const rimraf = require("rimraf");
|
||||
const {Application} = require("spectron");
|
||||
|
||||
const config = require('./config');
|
||||
const config = require("./config");
|
||||
|
||||
module.exports = {
|
||||
createApp,
|
||||
endTest,
|
||||
waitForLoad,
|
||||
wait,
|
||||
resetTestDataDir
|
||||
createApp,
|
||||
endTest,
|
||||
waitForLoad,
|
||||
wait,
|
||||
resetTestDataDir,
|
||||
};
|
||||
|
||||
// Runs Zulip Desktop.
|
||||
// Returns a promise that resolves to a Spectron Application once the app has loaded.
|
||||
// Takes a Tape test. Makes some basic assertions to verify that the app loaded correctly.
|
||||
function createApp() {
|
||||
generateTestAppPackageJson();
|
||||
return new Application({
|
||||
path: path.join(__dirname, '..', 'node_modules', '.bin',
|
||||
'electron' + (process.platform === 'win32' ? '.cmd' : '')),
|
||||
args: [path.join(__dirname)], // Ensure this dir has a package.json file with a 'main' entry piont
|
||||
env: {NODE_ENV: 'test'},
|
||||
waitTimeout: 10e3
|
||||
});
|
||||
generateTestAppPackageJson();
|
||||
return new Application({
|
||||
path: path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"node_modules",
|
||||
".bin",
|
||||
"electron" + (process.platform === "win32" ? ".cmd" : ""),
|
||||
),
|
||||
args: [path.join(__dirname)], // Ensure this dir has a package.json file with a 'main' entry piont
|
||||
env: {NODE_ENV: "test"},
|
||||
waitTimeout: 10e3,
|
||||
});
|
||||
}
|
||||
|
||||
// Generates package.json for test app
|
||||
// Reads app package.json and updates the productName to config.TEST_APP_PRODUCT_NAME
|
||||
// We do this so that the app integration doesn't doesn't share the same appDataDir as the dev application
|
||||
function generateTestAppPackageJson() {
|
||||
const packageJson = require(path.join(__dirname, '../package.json'));
|
||||
packageJson.productName = config.TEST_APP_PRODUCT_NAME;
|
||||
packageJson.main = '../app/main';
|
||||
const packageJson = require(path.join(__dirname, "../package.json"));
|
||||
packageJson.productName = config.TEST_APP_PRODUCT_NAME;
|
||||
packageJson.main = "../app/main";
|
||||
|
||||
const testPackageJsonPath = path.join(__dirname, 'package.json');
|
||||
fs.writeFileSync(testPackageJsonPath, JSON.stringify(packageJson, null, ' '), 'utf-8');
|
||||
const testPackageJsonPath = path.join(__dirname, "package.json");
|
||||
fs.writeFileSync(
|
||||
testPackageJsonPath,
|
||||
JSON.stringify(packageJson, null, " "),
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
|
||||
// Starts the app, waits for it to load, returns a promise
|
||||
async function waitForLoad(app, t, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
await app.start();
|
||||
await app.client.waitUntilWindowLoaded();
|
||||
await app.client.pause(2000);
|
||||
const title = await app.webContents.getTitle();
|
||||
t.equal(title, 'Zulip', 'html title');
|
||||
await app.start();
|
||||
await app.client.waitUntilWindowLoaded();
|
||||
await app.client.pause(2000);
|
||||
const title = await app.webContents.getTitle();
|
||||
t.equal(title, "Zulip", "html title");
|
||||
}
|
||||
|
||||
// Returns a promise that resolves after 'ms' milliseconds. Default: 1 second
|
||||
async function wait(ms) {
|
||||
if (ms === undefined) {
|
||||
ms = 1000;
|
||||
} // 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((resolve => {
|
||||
setTimeout(resolve, ms);
|
||||
}));
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
// Quit the app, end the test, either in success (!err) or failure (err)
|
||||
async function endTest(app, t, error) {
|
||||
await app.client.windowByIndex(0);
|
||||
await app.stop();
|
||||
t.end(error);
|
||||
await app.client.windowByIndex(0);
|
||||
await app.stop();
|
||||
t.end(error);
|
||||
}
|
||||
|
||||
function getAppDataDir() {
|
||||
let base;
|
||||
let base;
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
base = path.join(process.env.HOME, 'Library', 'Application Support');
|
||||
} else if (process.platform === 'linux') {
|
||||
base = process.env.XDG_CONFIG_HOME ?
|
||||
process.env.XDG_CONFIG_HOME : path.join(process.env.HOME, '.config');
|
||||
} else if (process.platform === 'win32') {
|
||||
base = process.env.APPDATA;
|
||||
} else {
|
||||
throw new Error('Could not detect app data dir base.');
|
||||
}
|
||||
if (process.platform === "darwin") {
|
||||
base = path.join(process.env.HOME, "Library", "Application Support");
|
||||
} else if (process.platform === "linux") {
|
||||
base = process.env.XDG_CONFIG_HOME
|
||||
? process.env.XDG_CONFIG_HOME
|
||||
: path.join(process.env.HOME, ".config");
|
||||
} else if (process.platform === "win32") {
|
||||
base = process.env.APPDATA;
|
||||
} else {
|
||||
throw new Error("Could not detect app data dir base.");
|
||||
}
|
||||
|
||||
console.log('Detected App Data Dir base:', base);
|
||||
return path.join(base, config.TEST_APP_PRODUCT_NAME);
|
||||
console.log("Detected App Data Dir base:", base);
|
||||
return path.join(base, config.TEST_APP_PRODUCT_NAME);
|
||||
}
|
||||
|
||||
// Resets the test directory, containing domain.json, window-state.json, etc
|
||||
function resetTestDataDir() {
|
||||
const appDataDir = getAppDataDir();
|
||||
rimraf.sync(appDataDir);
|
||||
rimraf.sync(path.join(__dirname, 'package.json'));
|
||||
const appDataDir = getAppDataDir();
|
||||
rimraf.sync(appDataDir);
|
||||
rimraf.sync(path.join(__dirname, "package.json"));
|
||||
}
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
'use strict';
|
||||
const test = require('tape');
|
||||
"use strict";
|
||||
const test = require("tape");
|
||||
|
||||
const setup = require('./setup');
|
||||
const setup = require("./setup");
|
||||
|
||||
test('add-organization', async t => {
|
||||
t.timeoutAfter(50e3);
|
||||
setup.resetTestDataDir();
|
||||
const app = setup.createApp();
|
||||
try {
|
||||
await setup.waitForLoad(app, t);
|
||||
await app.client.windowByIndex(1); // Focus on webview
|
||||
await (await app.client.$('.setting-input-value')).setValue('chat.zulip.org');
|
||||
await (await app.client.$('#connect')).click();
|
||||
await setup.wait(5000);
|
||||
await app.client.windowByIndex(0); // Switch focus back to main win
|
||||
await app.client.windowByIndex(1); // Switch focus back to org webview
|
||||
await (await app.client.$('//*[@id="id_username"]')).waitForExist();
|
||||
await setup.endTest(app, t);
|
||||
} catch (error) {
|
||||
await setup.endTest(app, t, error || 'error');
|
||||
}
|
||||
test("add-organization", async (t) => {
|
||||
t.timeoutAfter(50e3);
|
||||
setup.resetTestDataDir();
|
||||
const app = setup.createApp();
|
||||
try {
|
||||
await setup.waitForLoad(app, t);
|
||||
await app.client.windowByIndex(1); // Focus on webview
|
||||
await (await app.client.$(".setting-input-value")).setValue(
|
||||
"chat.zulip.org",
|
||||
);
|
||||
await (await app.client.$("#connect")).click();
|
||||
await setup.wait(5000);
|
||||
await app.client.windowByIndex(0); // Switch focus back to main win
|
||||
await app.client.windowByIndex(1); // Switch focus back to org webview
|
||||
await (await app.client.$('//*[@id="id_username"]')).waitForExist();
|
||||
await setup.endTest(app, t);
|
||||
} catch (error) {
|
||||
await setup.endTest(app, t, error || "error");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
'use strict';
|
||||
const test = require('tape');
|
||||
"use strict";
|
||||
const test = require("tape");
|
||||
|
||||
const setup = require('./setup');
|
||||
const setup = require("./setup");
|
||||
|
||||
// Create new org link should open in the default browser [WIP]
|
||||
|
||||
test('new-org-link', async t => {
|
||||
t.timeoutAfter(50e3);
|
||||
setup.resetTestDataDir();
|
||||
const app = setup.createApp();
|
||||
try {
|
||||
await setup.waitForLoad(app, t);
|
||||
await app.client.windowByIndex(1); // Focus on webview
|
||||
await (await app.client.$('#open-create-org-link')).click(); // Click on new org link button
|
||||
await setup.wait(5000);
|
||||
await setup.endTest(app, t);
|
||||
} catch (error) {
|
||||
await setup.endTest(app, t, error || 'error');
|
||||
}
|
||||
test("new-org-link", async (t) => {
|
||||
t.timeoutAfter(50e3);
|
||||
setup.resetTestDataDir();
|
||||
const app = setup.createApp();
|
||||
try {
|
||||
await setup.waitForLoad(app, t);
|
||||
await app.client.windowByIndex(1); // Focus on webview
|
||||
await (await app.client.$("#open-create-org-link")).click(); // Click on new org link button
|
||||
await setup.wait(5000);
|
||||
await setup.endTest(app, t);
|
||||
} catch (error) {
|
||||
await setup.endTest(app, t, error || "error");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user