Skip to content
This repository was archived by the owner on May 20, 2020. It is now read-only.

Tests #299

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open

Tests #299

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
3c6cf45
Started working on tests
yoogottamk Jun 12, 2019
9b81965
Using console.assert for now, will convert to jest; Currenltly, it wo…
yoogottamk Jun 12, 2019
2e06f1c
Fixed a typo, added actual eg
yoogottamk Jun 12, 2019
99e310f
Tests working now
yoogottamk Jun 12, 2019
0a1231b
Added multiple pages testing
yoogottamk Jun 12, 2019
f8e9b26
[sigma_g] lint all except dist and editor files
yoogottamk Jun 12, 2019
c1b6df9
Trying to make jest work with puppeteer
yoogottamk Jun 13, 2019
a979b1e
refactors
GaurangTandon Jun 13, 2019
b3e4c1d
[WIP]
GaurangTandon Jun 13, 2019
17fa570
fixes
GaurangTandon Jun 13, 2019
addb169
all tests are working now
GaurangTandon Jun 13, 2019
686ac2c
fixes
GaurangTandon Jun 13, 2019
007c052
tests work now
GaurangTandon Jun 13, 2019
c5295f3
fix leaving confirm box
GaurangTandon Jun 13, 2019
a0df2b8
attempted parallelizartion, but does not work :(
GaurangTandon Jun 13, 2019
d57f97f
successfully made test parallel! :)
GaurangTandon Jun 13, 2019
07a8e33
Made it work with slower connections
yoogottamk Jun 13, 2019
32cd98c
Removed unnecessary command
yoogottamk Jun 13, 2019
2dd959d
Trying to test options page
yoogottamk Jun 13, 2019
028a97b
fix options page wasn't detected
GaurangTandon Jun 13, 2019
681784a
Delimited snippets tested
yoogottamk Jun 15, 2019
69655ab
Tried to break tests into files [WIP]
yoogottamk Jun 15, 2019
0fb14d8
Settings page doesn't load [WIP]
yoogottamk Jun 15, 2019
a9c4634
add useragent detection so we won't have to open options page :)
GaurangTandon Jun 15, 2019
fa60890
Broken down tests work [cleanup might be reqd]
yoogottamk Jun 15, 2019
b61e6b7
some cleanup done
yoogottamk Jun 15, 2019
73aa4bf
Placeholder snippets test working
yoogottamk Jun 17, 2019
331aabf
Funny errors [testing tab to sp]
yoogottamk Jun 17, 2019
ebe5da4
Tab to space expansion test working
yoogottamk Jun 24, 2019
22a6c2c
Using better sleep
yoogottamk Jun 24, 2019
3c84670
Expanded functions for RTE
yoogottamk Jun 24, 2019
7d42526
Setup for RTE snippet testing
yoogottamk Jun 24, 2019
bb08dd8
not sure how eslint missed this
GaurangTandon Jun 24, 2019
faac89f
not sure how eslint missed this
GaurangTandon Jun 24, 2019
3ee6089
basic pruning
GaurangTandon Jun 27, 2019
ebaf3a3
[WIP] getting evaluate handle to work
GaurangTandon Jun 27, 2019
83b50be
almost made it
GaurangTandon Jun 27, 2019
f7a2d72
[WIP] :(
GaurangTandon Jun 27, 2019
46385f4
Fixed some errors
yoogottamk Jun 28, 2019
cf301b0
only one P element is enough for testing
GaurangTandon Jun 28, 2019
7b096c7
WIP
GaurangTandon Jun 28, 2019
34c3d76
Fixed some errors
yoogottamk Jun 28, 2019
7954b86
Some tests fail
yoogottamk Jun 29, 2019
e4e3384
Mathomania is being tested
yoogottamk Jul 1, 2019
32b6531
Embedded snippets being tested
yoogottamk Jul 1, 2019
59243ee
Urls are being tested now
yoogottamk Jul 1, 2019
4d2f0a7
common testing, unverified
GaurangTandon Jul 1, 2019
6272206
got it to work
GaurangTandon Jul 1, 2019
5d22b7e
nicer formatting
GaurangTandon Jul 1, 2019
d65728f
correct escaping
GaurangTandon Jul 1, 2019
4ecad12
embed snip broke, dk why
GaurangTandon Jul 1, 2019
4488238
all tests passed, remove debug stmnts
GaurangTandon Jul 1, 2019
5310f64
Clipboard snippets are now being tested
yoogottamk Jul 2, 2019
3310084
Organized macro tests
yoogottamk Jul 3, 2019
bfc0603
Randomize copied text to ensure it actually works
yoogottamk Jul 3, 2019
ecec82e
weird switch case indent + better parsing
yoogottamk Jul 3, 2019
be6ad3a
Context menu doesn't work [most probably will never work]
yoogottamk Jul 6, 2019
131fc84
Date snippets are now being tested
yoogottamk Jul 8, 2019
150d09b
Corrected order
yoogottamk Jul 8, 2019
ac1d294
Context menu insertions being tested
yoogottamk Jul 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
"env": {
"browser": true,
"es6": true,
"webextensions": true
"webextensions": true,
"jest": true
},
"extends": "airbnb-base",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
"SharedArrayBuffer": "readonly",
"page": true,
"browser": true,
"context": true,
"jestPuppeteer": true
},
"parserOptions": {
"ecmaVersion": 2018,
Expand Down
15 changes: 15 additions & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const pathToExtension = require("path").join(__dirname, "dist"),
prokeysUA = "iamprokeysyay";

module.exports = {
launch: {
headless: false,
args: [
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
"--single-process",
`--user-agent=${prokeysUA}`,
],
sloMo: 250,
},
};
101 changes: 67 additions & 34 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,29 @@ const BLOCK_SITE_ID = "blockSite",
// for gettting the blocked site status in case of unfinished loading of cs.js
LIMIT_OF_RECALLS = 10,
SNIPPET_MAIN_ID = "snippet_main",
URL_REGEX = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/;
LS_BG_PAGE_SUSPENDED_KEY = "pkBgWasSuspended",
URL_REGEX = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/,
testData = {
snippets: [
"Snippets",
1560477878650,
{ name: "brb", body: "be right back", timestamp: 10210201015 },
],
blockedSites: [],
charsToAutoInsertUserList: [["(", ")"], ["{", "}"], ["\"", "\""], ["[", "]"]],
dataVersion: 1,
language: "English",
hotKey: ["shiftKey", 32],
dataUpdateVariable: false,
matchDelimitedWord: false,
tabKey: false,
snipNameDelimiterList: "@#$%&*+-=(){}[]:\"'/_<>?!., ",
omniboxSearchURL: "https://www.google.com/search?q=SEARCH",
wrapSelectionAutoInsert: true,
ctxEnabled: true,
},
prokeysUA = "iamprokeysyay";

let contextMenuActionBlockSite,
recalls = 0,
// received from cs.js; when there are mutliple iframes on a page
Expand All @@ -30,10 +52,10 @@ let contextMenuActionBlockSite,
latestCtxTimestamp,
modalHTML,
/**
* Aim is that there should be only one copy of storage type present across
* the entire system. Hence, the background js is the safest place for it to be
* and others can message bg.js to interact with it
*/
* Aim is that there should be only one copy of storage type present across
* the entire system. Hence, the background js is the safest place for it to be
* and others can message bg.js to interact with it
*/
storage = chrome.storage.local;

// so that snippet_classes.js can work properly
Expand Down Expand Up @@ -70,7 +92,7 @@ function getDomain(url) {
idx;

if (path1) {
// remove all the unnecessary query/anchors parameter content
// remove all the unnecessary query/anchors parameter content
idx = path1.indexOf("?");
if (idx !== -1) {
path1 = path1.substring(0, idx);
Expand Down Expand Up @@ -162,18 +184,21 @@ let currentOmniboxQuery,
chrome.omnibox.onInputChanged.addListener((text, suggestCallback) => {
currentOmniboxQuery = text;

Data.snippets.filterSnippetsForOmnibox(text, ([defSuggest, ...otherSuggests]) => {
// {} when user entered text does not match any snippet content
defaultOmniboxSuggestion = defSuggest || {
description: "Sorry, entered text did not match any existing snippet",
};
Data.snippets.filterSnippetsForOmnibox(
text,
([defSuggest, ...otherSuggests]) => {
// {} when user entered text does not match any snippet content
defaultOmniboxSuggestion = defSuggest || {
description: "Sorry, entered text did not match any existing snippet",
};

chrome.omnibox.setDefaultSuggestion({
description: defaultOmniboxSuggestion.description,
});
chrome.omnibox.setDefaultSuggestion({
description: defaultOmniboxSuggestion.description,
});

suggestCallback(otherSuggests);
});
suggestCallback(otherSuggests);
},
);
});

chrome.omnibox.onInputEntered.addListener((omniboxText) => {
Expand All @@ -187,7 +212,10 @@ chrome.omnibox.onInputEntered.addListener((omniboxText) => {
if (isURL(query)) {
url = query;
} else {
url = localStorage.omniboxSearchURL.replace("SEARCH", encodeURIComponent(query));
url = localStorage.omniboxSearchURL.replace(
"SEARCH",
encodeURIComponent(query),
);
}

chrome.tabs.query({ currentWindow: true, active: true }, (tabs) => {
Expand All @@ -198,15 +226,15 @@ chrome.omnibox.onInputEntered.addListener((omniboxText) => {
// create modal dialog for blocking site by detector.js
(function createBlockSiteModal() {
const modalContent = "<div class='prokeys-block block-theme-plain'>"
+ "<div class='block-overlay'></div>"
+ "<div class='block-content'>"
+ "<div class='block-dialog-form'>"
+ "<div class='block-dialog-message'>Are you sure you want to <span class='action'></span><br> <input type='text' class='site-name'><br> from ProKeys?</div>"
+ "<div class='block-dialog-buttons'>"
+ "<input type='button' value='OK' class='block-dialog-button-primary block-dialog-button'>"
+ "<input type='button' value='Cancel' class='block-dialog-button-secondary block-dialog-button'> </div>"
+ "</div>"
+ "</div></div>";
+ "<div class='block-overlay'></div>"
+ "<div class='block-content'>"
+ "<div class='block-dialog-form'>"
+ "<div class='block-dialog-message'>Are you sure you want to <span class='action'></span><br> <input type='text' class='site-name'><br> from ProKeys?</div>"
+ "<div class='block-dialog-buttons'>"
+ "<input type='button' value='OK' class='block-dialog-button-primary block-dialog-button'>"
+ "<input type='button' value='Cancel' class='block-dialog-button-secondary block-dialog-button'> </div>"
+ "</div>"
+ "</div></div>";

modalHTML = modalContent;
}());
Expand All @@ -228,9 +256,9 @@ let removeCtxSnippetList,
};

/**
* if new input did not change snippets
* do not do anything; otherwise remove all snippets and readd them
*/
* if new input did not change snippets
* do not do anything; otherwise remove all snippets and readd them
*/
makeCtxSnippetList = function () {
const { snippets } = Data,
newInput = JSON.stringify(snippets.toArray());
Expand Down Expand Up @@ -306,10 +334,13 @@ chrome.runtime.onInstalled.addListener((details) => {
{ version } = chrome.runtime.getManifest();

if (reason === "install") {
// set initial data
// set initial data
localStorage[LS_REVISIONS_PROP] = "[]";
localStorage[LS_STORAGE_TYPE_PROP] = "local";
window.Data = SETTINGS_DEFAULTS;
if (window.navigator.userAgent === prokeysUA) {
window.Data = testData;
}
window.latestRevisionLabel = "data created (added defaut snippets)";

saveRevision(Data.snippets);
Expand Down Expand Up @@ -337,7 +368,7 @@ chrome.runtime.onInstalled.addListener((details) => {
localStorage.extensionUpdated = "true";
decideCorrectStorageType(() => handleExtUpdate(args));
} else {
// do not process anything other than install or update
// do not process anything other than install or update
}
});

Expand Down Expand Up @@ -395,8 +426,8 @@ function updateContextMenu(isRecalled = false) {
*/
function initContextMenu() {
if (Data.ctxEnabled) {
// let this call decide whether to show snippets or not
// based on whether site is blocked or not
// let this call decide whether to show snippets or not
// based on whether site is blocked or not
updateContextMenu();
} else {
removeCtxSnippetList();
Expand Down Expand Up @@ -516,7 +547,9 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// setIndices necessary everytime we reassign data
// otherwise search function doesn't work as expected
DBSave(() => {
if (Data.snippets) { makeDataReady(); }
if (Data.snippets) {
makeDataReady();
}
sendResponse("done");
});
return true;
Expand Down
1 change: 0 additions & 1 deletion js/pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ function gTranlateImmune(text) {
return `<span class=notranslate>${text}</span>`;
}


/**
* in certain web apps, like mailchimp
* node refers to the editor inside iframe
Expand Down
Loading