@theia-extension-tester/tests
Version:
Tests for theia-extension-tester package.
226 lines • 11 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const page_objects_1 = require("@theia-extension-tester/page-objects");
const chai_1 = require("chai");
const repeat_1 = require("@theia-extension-tester/repeat");
describe('Notifications', function () {
this.timeout(40000);
let center;
beforeEach(function () {
return __awaiter(this, void 0, void 0, function* () {
yield new page_objects_1.EditorView().closeAllEditors();
});
});
describe('NotificationsCenter', function () {
beforeEach(function () {
return __awaiter(this, void 0, void 0, function* () {
center = yield new page_objects_1.Workbench().openNotificationsCenter();
yield center.wait(this.timeout() - 2000);
});
});
afterEach(function () {
return __awaiter(this, void 0, void 0, function* () {
const center = yield new page_objects_1.Workbench().openNotificationsCenter();
yield center.wait(this.timeout() - 2000);
yield center.close();
});
});
it('close', function () {
return __awaiter(this, void 0, void 0, function* () {
chai_1.expect(yield center.isDisplayed()).to.be.true;
yield center.close();
chai_1.expect(yield center.isDisplayed()).to.be.false;
});
});
it('clearAllNotifications', function () {
return __awaiter(this, void 0, void 0, function* () {
chai_1.expect(yield center.isDisplayed()).to.be.true;
yield createNotifications(true);
yield repeat_1.repeat(() => __awaiter(this, void 0, void 0, function* () {
center = yield new page_objects_1.Workbench().openNotificationsCenter();
yield center.clearAllNotifications();
center = yield new page_objects_1.Workbench().openNotificationsCenter();
if ((yield center.getNotifications(page_objects_1.NotificationType.Any)).length === 0) {
return {
value: true
};
}
else {
return {
value: false,
delay: 1000
};
}
}), {
timeout: this.timeout() - 2000,
message: () => __awaiter(this, void 0, void 0, function* () { return (center) ? (chai_1.expect(yield center.getNotifications(page_objects_1.NotificationType.Any)).to.be.empty, 'string hack') : ('Could not find notification center'); })
});
});
});
it('getNotifications', function () {
return __awaiter(this, void 0, void 0, function* () {
chai_1.expect(yield center.isDisplayed()).to.be.true;
yield createNotifications(true);
chai_1.expect((yield center.getNotifications(page_objects_1.NotificationType.Any)).length).least(2);
});
});
});
let notificationType = [false, true];
for (const type of notificationType) {
describe(`Notification - ${type ? 'center' : 'standalone'}`, function () {
return __awaiter(this, void 0, void 0, function* () {
const notificationDetails = {
'Open a file first to copy its path': {
icon: page_objects_1.NotificationType.Info,
source: ''
},
"Please use the browser's paste command or shortcut.": {
icon: page_objects_1.NotificationType.Warning,
source: ''
}
};
beforeEach(function () {
return __awaiter(this, void 0, void 0, function* () {
const center = yield new page_objects_1.Workbench().openNotificationsCenter();
yield center.wait(this.timeout() - 2000);
yield center.clearAllNotifications();
yield createNotifications(type);
});
});
it('getMessage', function () {
return __awaiter(this, void 0, void 0, function* () {
for (const message of Object.keys(notificationDetails)) {
yield getNotification(message, type);
}
});
});
it('getType', function () {
return __awaiter(this, void 0, void 0, function* () {
for (const message of Object.keys(notificationDetails)) {
const notification = yield getNotification(message, type);
chai_1.expect(yield notification.getType()).equals(notificationDetails[message].icon);
}
});
});
it('getSource', function () {
return __awaiter(this, void 0, void 0, function* () {
for (const message of Object.keys(notificationDetails)) {
const notification = yield getNotification(message, type);
chai_1.expect(yield notification.getSource()).equals(notificationDetails[message].source);
}
});
});
it('dismiss', function () {
return __awaiter(this, void 0, void 0, function* () {
for (const message of Object.keys(notificationDetails)) {
const notification = yield getNotification(message, type);
yield notification.dismiss();
try {
yield notification.isDisplayed();
chai_1.expect.fail('This should be unreachable.');
}
catch (_a) {
continue;
}
}
});
});
it.skip('hasProgress', function () {
return __awaiter(this, void 0, void 0, function* () {
});
});
it.skip('getActions', function () {
return __awaiter(this, void 0, void 0, function* () {
});
});
it.skip('takeAction', function () {
return __awaiter(this, void 0, void 0, function* () {
});
});
it('openContextMenu', function () {
return __awaiter(this, void 0, void 0, function* () {
try {
const notification = yield getNotification(Object.keys(notificationDetails)[0], type);
yield notification.openContextMenu();
chai_1.expect.fail('This code should not be reachable.');
}
catch (_a) {
}
});
});
});
});
}
});
function createNotifications(useCenter) {
return __awaiter(this, void 0, void 0, function* () {
const workbench = new page_objects_1.Workbench();
let center;
center = yield workbench.openNotificationsCenter();
yield center.clearAllNotifications();
yield center.close();
if (useCenter) {
center = yield workbench.openNotificationsCenter();
}
else {
center = undefined;
}
yield workbench.executeCommand('Paste');
yield workbench.getDriver().wait(page_objects_1.until.elementIsNotVisible(new page_objects_1.InputBox()));
yield workbench.executeCommand('Copy Path');
yield workbench.getDriver().wait(page_objects_1.until.elementIsNotVisible(new page_objects_1.InputBox()));
yield repeat_1.repeat(() => __awaiter(this, void 0, void 0, function* () {
var _a;
let matches = 0;
const notifications = (_a = (yield (center === null || center === void 0 ? void 0 : center.getNotifications(page_objects_1.NotificationType.Any)))) !== null && _a !== void 0 ? _a : (yield workbench.getNotifications());
for (const notification of notifications) {
try {
const message = yield notification.getMessage();
if (message.startsWith('Open a file') || message.startsWith('Please use the browser')) {
matches += 1;
}
}
catch (e) {
if (e instanceof page_objects_1.error.StaleElementReferenceError) {
break;
}
throw e;
}
}
return matches === 2;
}), {
timeout: 20000,
message: 'Could not create notifications'
});
});
}
function getNotification(message, useCenter) {
return __awaiter(this, void 0, void 0, function* () {
let center;
if (useCenter) {
center = yield new page_objects_1.Workbench().openNotificationsCenter();
}
return yield repeat_1.repeat(() => __awaiter(this, void 0, void 0, function* () {
const notifications = useCenter ? (yield center.getNotifications(page_objects_1.NotificationType.Any)) : (yield new page_objects_1.Workbench().getNotifications());
for (const notification of notifications) {
if ((yield notification.getMessage()) === message) {
return notification;
}
}
return undefined;
}), {
timeout: 9000,
message: `Could not get notification with message "${message}".`
});
});
}
//# sourceMappingURL=01_Notification.test.js.map