mirror of
https://github.com/S2-/gitlit
synced 2025-08-03 21:00:04 +02:00
133 lines
5.3 KiB
JavaScript
133 lines
5.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const index_1 = require("../src/index");
|
|
const A = require("assert");
|
|
const electron_1 = require("electron");
|
|
const sinon_1 = require("sinon");
|
|
function waitForReady(w) {
|
|
return new Promise(resolve => {
|
|
const c = w.getWebContents && w.getWebContents();
|
|
if (c) {
|
|
resolve(w);
|
|
return;
|
|
}
|
|
w.addEventListener('dom-ready', resolve);
|
|
});
|
|
}
|
|
function pause1000ms() {
|
|
return new Promise(resolve => {
|
|
setTimeout(resolve, 1000);
|
|
});
|
|
}
|
|
context('For browser window', function () {
|
|
before(function () {
|
|
document.body.innerHTML = '<div>foo bar baz foo bar piyo poyo</div>';
|
|
});
|
|
describe('searchInPage()', function () {
|
|
it('creates search instance which enables in-page search', function () {
|
|
const s = index_1.default(electron_1.remote.getCurrentWebContents());
|
|
A.ok(s);
|
|
A.ok(!s.opened);
|
|
A.equal(document.querySelector('webview'), null);
|
|
const opened = sinon_1.spy();
|
|
s.on('open', opened);
|
|
s.openSearchWindow();
|
|
A.ok(opened.called);
|
|
A.ok(s.opened);
|
|
const w = document.querySelector('webview');
|
|
A.equal(w.className, 'electron-in-page-search-window search-active');
|
|
const started = sinon_1.spy();
|
|
s.on('start', started);
|
|
const stopped = sinon_1.spy();
|
|
s.on('stop', stopped);
|
|
const next = sinon_1.spy();
|
|
return waitForReady(w)
|
|
.then(pause1000ms)
|
|
.then(() => {
|
|
electron_1.remote.getCurrentWindow().focusOnWebView();
|
|
w.executeJavaScript(`(function() {
|
|
document.querySelector('.inpage-search-input').value = 'foo';
|
|
document.querySelector('.inpage-search-forward').click();
|
|
})()`, false);
|
|
})
|
|
.then(pause1000ms)
|
|
.then(() => {
|
|
A.ok(started.called);
|
|
A.equal(started.args[0][0], 'foo');
|
|
s.on('next', next);
|
|
w.executeJavaScript(`(function() {
|
|
document.querySelector('.inpage-search-forward').click();
|
|
})()`, false);
|
|
})
|
|
.then(pause1000ms)
|
|
.then(() => {
|
|
A.ok(next.called);
|
|
A.equal(next.args[0][0], 'foo');
|
|
A.ok(next.args[0][1]);
|
|
w.executeJavaScript(`(function() {
|
|
document.querySelector('.inpage-search-close').click();
|
|
})()`, false);
|
|
})
|
|
.then(pause1000ms)
|
|
.then(() => {
|
|
A.ok(!s.opened);
|
|
A.ok(stopped.called);
|
|
A.equal(w.className, 'electron-in-page-search-window search-inactive');
|
|
s.finalize();
|
|
A.equal(document.querySelector('webview'), null);
|
|
});
|
|
});
|
|
it('can search words multiple times', function () {
|
|
const s = index_1.default(electron_1.remote.getCurrentWebContents());
|
|
s.openSearchWindow();
|
|
const w = document.querySelector('webview');
|
|
const next = sinon_1.spy();
|
|
const start = sinon_1.spy();
|
|
s.on('next', next);
|
|
s.on('start', start);
|
|
return waitForReady(w)
|
|
.then(pause1000ms)
|
|
.then(() => {
|
|
electron_1.remote.getCurrentWindow().focusOnWebView();
|
|
w.executeJavaScript(`(function() {
|
|
document.querySelector('.inpage-search-input').value = 'foo';
|
|
const b = document.querySelector('.inpage-search-forward');
|
|
b.click();
|
|
b.click();
|
|
})()`, false);
|
|
})
|
|
.then(pause1000ms)
|
|
.then(() => {
|
|
electron_1.remote.getCurrentWindow().focusOnWebView();
|
|
w.executeJavaScript(`(function() {
|
|
document.querySelector('.inpage-search-input').value = 'ba';
|
|
const b = document.querySelector('.inpage-search-forward');
|
|
b.click();
|
|
b.click();
|
|
})()`, false);
|
|
})
|
|
.then(pause1000ms)
|
|
.then(() => {
|
|
A.equal(start.args[0][0], 'foo');
|
|
A.equal(start.args[1][0], 'ba');
|
|
A.equal(next.args[0][0], 'foo');
|
|
A.ok(next.args[0][1]);
|
|
A.equal(next.args[1][0], 'ba');
|
|
A.ok(next.args[1][1]);
|
|
})
|
|
.then(() => {
|
|
w.executeJavaScript(`(function() {
|
|
document.querySelector('.inpage-search-close').click();
|
|
})()`, false);
|
|
})
|
|
.then(pause1000ms)
|
|
.then(() => {
|
|
A.ok(!s.opened);
|
|
A.equal(w.className, 'electron-in-page-search-window search-inactive');
|
|
s.finalize();
|
|
A.equal(document.querySelector('webview'), null);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
//# sourceMappingURL=smoke_browser_window_test.js.map
|