Skip to content

Commit

Permalink
fluid-projectGH-32: Finish writing tests and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyli committed Dec 7, 2022
1 parent bacbfdf commit 6402f55
Show file tree
Hide file tree
Showing 29 changed files with 481 additions and 3,075 deletions.
14 changes: 0 additions & 14 deletions TODOs

This file was deleted.

3 changes: 0 additions & 3 deletions jest.config.js

This file was deleted.

6 changes: 0 additions & 6 deletions jest.setup.js

This file was deleted.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"test": "run-s test:node test:browser",
"test:node": "nyc node tests/node/all-tests.js",
"test:browser": "testem ci --file tests/browser/testem.js",
"test:jest": "jest",
"test:report": "nyc report -r text-summary -r html -r json",
"posttest": "npm run test:report",
"clean": "run-p clean:*",
Expand All @@ -47,15 +46,14 @@
},
"devDependencies": {
"eslint-config-fluid": "2.1.1",
"fluid-lint-all": "1.2.2",
"fluid-lint-all": "1.2.3",
"fluid-testem": "2.1.15",
"jest": "27.0.0",
"jest-chrome": "0.7.2",
"laravel-mix": "6.0.49",
"node-jqunit": "1.1.9",
"npm-run-all": "4.1.5",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"testem": "3.9.0"
"sinon-chrome": "3.0.1",
"testem": "3.10.0"
}
}
3 changes: 2 additions & 1 deletion src/html/adjusters.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<script src="../js/panels.js"></script>
<script src="../js/schemas.js"></script>
<script src="../js/store.js"></script>
<script src="../js/prefsEditor.js" defer></script>
<script src="../js/prefsEditor.js"></script>
<script src="../js/instantiator.js" defer></script>

<title>Preferences Editor</title>
</head>
Expand Down
11 changes: 5 additions & 6 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
* https://github.com/fluid-project/uio-plus/blob/main/LICENSE.txt
*/

/* global chrome */

"use strict";

const uioPlus = {};
var chrome = chrome || require("sinon-chrome");

// Quick Panel Config

Expand Down Expand Up @@ -124,8 +123,8 @@ uioPlus.createMenuItems = async (menuItems, parentId, storage) => {
/**
* Update checkbox states based on values updated into the local storage.
*
* @param {Object} menuItems - the changed preferences.
* @param {Object} menuItems - menu items structure. See `uioPlus.contextMenuItems` for an example.
* @param {Object} changes - the changed preferences.
*/
uioPlus.updateQuickPanelState = (menuItems, changes) => {
Object.keys(menuItems.preferences.children).forEach(prefName => {
Expand All @@ -142,7 +141,7 @@ uioPlus.updateQuickPanelState = (menuItems, changes) => {
* If the previously saved preference value is false, remove it from the saved preferences object. Otherwise, save it.
*
* @param {String} prefName - a preference name.
* @param {Boolean} arrays - the arrays to filter `toFilter` with.
* @param {Boolean} state - the state of the given preference.
* @return {Promise} - the result of saving the preference.
*/
uioPlus.storePref = async (prefName, state) => {
Expand Down Expand Up @@ -235,8 +234,8 @@ if (!menu) {
menu = uioPlus.createMenuItems(uioPlus.contextMenuItems);
}

// For tests only as jest and jest-chrome only works with node.js module scripts
if (typeof exports !== 'undefined') {
// For node.js tests only
if (typeof exports !== "undefined") {
exports.createMenuItems = uioPlus.createMenuItems;
exports.storePref = uioPlus.storePref;
exports.storeZoom = uioPlus.storeZoom;
Expand Down
27 changes: 27 additions & 0 deletions src/js/instantiator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright The UIO+ copyright holders
* See the AUTHORS.md file at the top-level directory of this distribution and at
* https://github.com/fluid-project/uio-plus/blob/main/AUTHORS.md
*
* Licensed under the BSD 3-Clause License. You may not use this file except in
* compliance with this license.
*
* You may obtain a copy of the license at
* https://github.com/fluid-project/uio-plus/blob/main/LICENSE.txt
*/

/* global uioPlus */

"use strict";

uioPlus.prefsEditor(".uioPlus", {
auxiliarySchema: {
terms: {
// adjust paths
templatePrefix: "../lib/infusion/src/framework/preferences/html",
messagePrefix: "../lib/infusion/src/framework/preferences/messages",
localTemplatePrefix: "../templates",
localMessagePrefix: "../messages"
}
}
});
10 changes: 2 additions & 8 deletions src/js/prefsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ fluid.defaults("uioPlus.prefsEditor.panelIndex", {
}
});

fluid.uiOptions(".uioPlus", {
fluid.defaults("uioPlus.prefsEditor", {
gradeNames: ["fluid.uiOptions"],
preferences: [
"uioPlus.prefs.zoom",
"fluid.prefs.letterSpace",
Expand All @@ -48,13 +49,6 @@ fluid.uiOptions(".uioPlus", {
storeType: "uioPlus.prefs.store",
auxiliarySchema: {
loaderGrades: ["fluid.prefs.fullNoPreview"],
terms: {
// adjust paths
templatePrefix: "../lib/infusion/src/framework/preferences/html",
messagePrefix: "../lib/infusion/src/framework/preferences/messages",
localTemplatePrefix: "../templates",
localMessagePrefix: "../messages"
},
// Remove aliases and enactors from schemas. UIO+ does not apply settings to the adjusters themselves.
// In the future if we wish to support that, the overrides will need to be removed.
"fluid.prefs.tableOfContents": {
Expand Down
4 changes: 3 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"js/contentView.js",
"js/panels.js",
"js/enactors.js",
"js/enhancer.js"
"js/enhancer.js",
"js/prefsEditor.js",
"js/instantiator.js"
]
}],
"commands": {
Expand Down
7 changes: 6 additions & 1 deletion tests/browser/all-tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@

fluid.testem.safeRollup(
[
"/tests/browser/html/contentViewTests.html",
"/tests/browser/html/enactorTests.html",
"/tests/browser/html/enhancerTests.html",
"/tests/browser/html/panelTests.html",
"/tests/browser/html/contentViewTests.html"
"/tests/browser/html/prefsEditorTests.html",
"/tests/browser/html/storeTests.html",
"/tests/browser/html/webInjectionTests.html"
],
"../.."
);
Expand Down
2 changes: 1 addition & 1 deletion tests/browser/html/enhancerTests.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<script src="../../../node_modules/infusion/tests/lib/qunit/js/qunit.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/jqUnit/js/jqUnit.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/jqUnit/js/jqUnit-browser.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/utils/js/IoCTestUtils.js"></script>
<script src="../../../node_modules/sinon-chrome/bundle/sinon-chrome.min.js"></script>
<script src="../../../node_modules/sinon/pkg/sinon.js"></script>
<script src="../../../src/js/contentView.js"></script>
Expand All @@ -25,6 +24,7 @@
<script src="/testem.js"></script>
<script src="/coverage/client/coverageSender.js"></script>

<script src="../js/testUtils.js"></script>
<script src="../js/enhancerTests.js"></script>
</head>

Expand Down
24 changes: 6 additions & 18 deletions tests/browser/html/prefsEditorTests.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
<script src="../../../node_modules/infusion/tests/lib/qunit/js/qunit.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/jqUnit/js/jqUnit.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/jqUnit/js/jqUnit-browser.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/utils/js/IoCTestUtils.js"></script>
<script src="../../../node_modules/sinon-chrome/bundle/sinon-chrome.min.js"></script>
<script src="../../../node_modules/sinon/pkg/sinon.js"></script>
<script src="../../../src/js/shared/portBinding.js"></script>
<script src="../../../src/js/browserAction/PrefsEditor.js"></script>
<script src="../../../src/js/panels.js"></script>
<script src="../../../src/js/schemas.js"></script>
<script src="../../../src/js/store.js"></script>
<script src="../../../src/js/prefsEditor.js" defer></script>

<!-- Required to send coverage data at the end of the test run on this page -->
<script src="/testem.js"></script>
<script src="/coverage/client/coverageSender.js"></script>

<script src="../js/portTestUtils.js"></script>
<script src="../js/portBindingTestUtils.js"></script>
<script src="../js/PanelTestUtils.js"></script>
<script src="../js/testUtils.js"></script>
<script src="../js/prefsEditorTests.js"></script>
</head>

Expand All @@ -35,16 +33,6 @@ <h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<!-- Test Markup -->

<div class="uioPlusJS-textSize"></div>
<div class="uioPlusJS-lineSpace"></div>
<div class="uioPlusJS-charSpace"></div>
<div class="uioPlusJS-syllabification"></div>
<div class="uioPlusJS-contrast"></div>
<div class="uioPlusJS-highlight"></div>
<div class="uioPlusJS-simplify"></div>
<div class="uioPlusJS-clickToSelect"></div>

<div class="uioPlusJS-prefsEditor"></div>

<div class="uioPlus"></div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>UIO+ port binding tests</title>
<title>UIO+ prefs editor tests</title>

<link rel="stylesheet" media="screen" href="../../../node_modules/infusion/tests/lib/qunit/css/qunit.css" />
<link rel="stylesheet" href="../../../node_modules/infusion/tests/lib/qunit/addons/composite/qunit-composite.css">
Expand All @@ -11,27 +11,23 @@
<script src="../../../node_modules/infusion/tests/lib/qunit/js/qunit.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/jqUnit/js/jqUnit.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/jqUnit/js/jqUnit-browser.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/utils/js/IoCTestUtils.js"></script>
<script src="../../../node_modules/sinon-chrome/bundle/sinon-chrome.min.js"></script>
<script src="../../../node_modules/sinon/pkg/sinon.js"></script>
<script src="../../../src/js/shared/portBinding.js"></script>
<script src="../../../src/js/store.js"></script>

<!-- Required to send coverage data at the end of the test run on this page -->
<script src="/testem.js"></script>
<script src="/coverage/client/coverageSender.js"></script>

<script src="../js/portTestUtils.js"></script>
<script src="../js/portBindingTestUtils.js"></script>
<script src="../js/portBindingTests.js"></script>
<script src="../js/storeTests.js"></script>
</head>

<body id="body">
<h1 id="qunit-header">UIO+ port binding tests</h1>
<h1 id="qunit-header">UIO+ prefs editor tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<!-- Test Markup -->

</body>
</html>
33 changes: 33 additions & 0 deletions tests/browser/html/webInjectionTests.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>UIO+ prefs editor tests</title>

<link rel="stylesheet" media="screen" href="../../../node_modules/infusion/tests/lib/qunit/css/qunit.css" />
<link rel="stylesheet" href="../../../node_modules/infusion/tests/lib/qunit/addons/composite/qunit-composite.css">

<script src="../../../node_modules/infusion/dist/infusion-all.js"></script>
<script src="../../../node_modules/infusion/tests/lib/qunit/js/qunit.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/jqUnit/js/jqUnit.js"></script>
<script src="../../../node_modules/infusion/tests/test-core/jqUnit/js/jqUnit-browser.js"></script>
<script src="../../../node_modules/sinon-chrome/bundle/sinon-chrome.min.js"></script>
<script src="../../../node_modules/sinon/pkg/sinon.js"></script>
<script src="../../../src/js/webInjection.js"></script>

<!-- Required to send coverage data at the end of the test run on this page -->
<script src="/testem.js"></script>
<script src="/coverage/client/coverageSender.js"></script>

<script src="../js/webInjectionTests.js"></script>
</head>

<body id="body">
<h1 id="qunit-header">UIO+ prefs editor tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<!-- Test Markup -->
</body>
</html>
19 changes: 6 additions & 13 deletions tests/browser/js/enhancerTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* https://github.com/fluid-project/uio-plus/blob/main/LICENSE.txt
*/

/* global fluid, jqUnit, uioPlus */
/* global jqUnit, uio, uioPlus, chrome */

"use strict";

(function ($) {
Expand All @@ -19,17 +20,11 @@

fluid.registerNamespace("uioPlus.tests");

uioPlus.tests.verifySubcomponentsExist = function (that, subcomponents) {
subcomponents.forEach((oneComponent) => {
jqUnit.assertNotUndefined(oneComponent + " exist", that[oneComponent]);
});
};

jqUnit.test("Test instantiated UIO", function () {
// Initial Instantiation
jqUnit.assertNotUndefined("UIO enhancer has been instantiated", uio);
jqUnit.assertEquals("The enhancer acts on the body element", "body", uio.container.selector);
uioPlus.tests.verifySubcomponentsExist(uio, ["store", "enhancer"])
uioPlus.tests.verifySubcomponentsExist(uio, ["store", "enhancer"]);
uioPlus.tests.verifySubcomponentsExist(uio.enhancer.uiEnhancer, [
"fluid_prefs_enactor_letterSpace",
"fluid_prefs_enactor_wordSpace",
Expand Down Expand Up @@ -75,8 +70,8 @@
fluid_prefs_syllabification: true
});
jqUnit.assertTrue("The model value is properly relayed to the syllabification enactor", uio.enhancer.uiEnhancer.fluid_prefs_enactor_syllabification.model.enabled);
jqUnit.assertEquals("The patternPrefix has been set properly", "lib/infusion/src/lib/hypher/patterns", uio.enhancer.uiEnhancer.fluid_prefs_enactor_syllabification.options.terms.patternPrefix)
jqUnit.assertEquals("The injectScript function is properly set", "uioPlus.contentScript.requestInjection", uio.enhancer.uiEnhancer.fluid_prefs_enactor_syllabification.options.invokers.injectScript.funcName)
jqUnit.assertEquals("The patternPrefix has been set properly", "lib/infusion/src/lib/hypher/patterns", uio.enhancer.uiEnhancer.fluid_prefs_enactor_syllabification.options.terms.patternPrefix);
jqUnit.assertEquals("The injectScript function is properly set", "uioPlus.contentScript.requestInjection", uio.enhancer.uiEnhancer.fluid_prefs_enactor_syllabification.options.invokers.injectScript.funcName);

// Contrast
uio.enhancer.uiEnhancer.applier.change("", {
Expand Down Expand Up @@ -141,9 +136,8 @@
const onChangedListener = chrome.storage.onChanged._listeners[0];
jqUnit.assertTrue("chrome.storage.onChanged has a listener", typeof onChangedListener === "function");

// Trigger listener
// Trigger the listener and test the result
const initialModel = uio.enhancer.uiEnhancer.initialModel;
console.log("initialModel: ", initialModel);
const testCases = [
{
areaName: "local",
Expand Down Expand Up @@ -183,7 +177,6 @@
{...uio.enhancer.uiEnhancer.initialModel.preferences, ...oneTestCase.changes.preferences.newValue},
uio.enhancer.uiEnhancer.model
);
console.log(uio.enhancer.uiEnhancer.model);
// Reset the uiEnhancer model back to the initial for the next test to run
uio.enhancer.uiEnhancer.updateModel(initialModel);
}
Expand Down
Loading

0 comments on commit 6402f55

Please sign in to comment.