Skip to content

Commit

Permalink
Update on-line testing page
Browse files Browse the repository at this point in the history
  • Loading branch information
Cimbali committed Mar 16, 2020
1 parent 01928c8 commit 54a42c1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 32 deletions.
77 changes: 50 additions & 27 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@

<!-- Mock browser object so cleanLink can be loaded -->
<script>
let nop = () => Promise.resolve({})
var browser = {
runtime: {getManifest: () => ({
"name": "Clean Links",
"description": "Converts obfuscated/nested links to genuine clean links",
"author": "Cimbali (maintainer), \nDiego Casorran (creator), \nEduard Braun (German translation), \nSimon Chan (Chinese and Taiwanese translations)",
"version": "3.0.3",
"homepage_url": "https://github.com/Cimbali/CleanLinks",
}),
getURL: (url) => ('https://cdn.rawgit.com/Cimbali/CleanLinks/master/addon/' + url.replace(/^\/+/, '')),
var browser =
{
runtime:
{
getURL: url => ('https://cdn.rawgit.com/Cimbali/CleanLinks/master/addon/' + url.replace(/^\/+/, '')),
},
i18n:
{
getMessage: () => null
},
storage: {sync: {get: nop, set: nop, remove: nop}, local: {get: nop, set: nop, remove: nop}},
i18n: {getMessage: () => "string"}
storage: {}
}
</script>
<script src="https://cdn.rawgit.com/Cimbali/CleanLinks/master/tests/setup.js"></script>

<!-- Embed the actual cleanLink script -->
<!-- Embed the actual clean_link script -->
<script src="https://cdn.rawgit.com/Cimbali/CleanLinks/master/addon/modules/common.js"></script>
<script src="https://cdn.rawgit.com/Cimbali/CleanLinks/master/addon/modules/punycode.js"></script>
<script src="https://cdn.rawgit.com/Cimbali/CleanLinks/master/addon/modules/publicsuffixlist.js"></script>
Expand All @@ -32,32 +31,54 @@

<!-- Inner workings of this page -->
<script>
function addToList(dirty, clean)
function add_to_list(dirty, clean)
{
var l = document.querySelector('ul#clean_history');
let l = document.querySelector('ul#clean_history');

l.appendChild(document.createElement('li'));
l.appendChild(document.createElement('li'));
l.appendChild(document.createElement('li'));

l.insertBefore(document.createElement('li'), l.children[0]);
l.children[0].textContent = ' ';
l.children[2].textContent = ' ';

l.insertBefore(document.createElement('li'), l.children[0]);
l.children[0].textContent = clean;
l.children[0].className = 'cleaned'
l.children[1].textContent = clean;
l.children[1].className = 'cleaned'

l.insertBefore(document.createElement('li'), l.children[0]);
l.children[0].textContent = dirty;
}

function testCleaning()
function test_cleaning()
{
var link = document.querySelector('#paste_link input').value;
let link = document.querySelector('#paste_link input').value;
if (link)
cleanLink(link).then(result => addToList(link, result))
Rules.loaded.then(() =>
{
add_to_list(link, clean_link(link));
document.querySelector('#paste_link input').value = '';
})
}

window.onload = () =>
window.addEventListener('load', () =>
{
document.querySelector('#paste_link button').onclick = testCleaning
}
document.querySelector('#paste_link button').addEventListener('click', test_cleaning);
document.querySelector('#paste_link input').addEventListener('keyup', e =>
{
if (e.key === 'Enter')
{
e.stopPropagation();
e.preventDefault();
test_cleaning();
}
});

fetch(browser.runtime.getURL('manifest.json')).then(async json =>
{
const manifest = JSON.parse(await json.text());
const h1 = document.getElementsByTagName('h1')[0];
h1.textContent = manifest.name + ' v' + manifest.version;
});

});
</script>

<!-- Styling for the page -->
Expand Down Expand Up @@ -85,6 +106,8 @@
</head>

<body>
<h1></h1>
<p>Test default rules of Clean Links.</p>
<p id="paste_link">Link:&nbsp;<input type="text" />&nbsp;<button>Clean it!</button></p>
<ul id="clean_history"></ul>
</body>
Expand Down
2 changes: 2 additions & 0 deletions tests/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = config => Object.assign(config,
"modules/cleanlink.js",

{type: 'css', included: false, served: true, nocache: true, pattern: "data/*"},
{type: 'css', included: false, served: true, nocache: false, pattern: "manifest.json"},

// The tests, finally
'../tests/*.test.js',
Expand All @@ -35,6 +36,7 @@ module.exports = config => Object.assign(config,
'/modules/': 'http://localhost:9876/base/modules/',
'/icons/': 'http://localhost:9876/base/icons/',
'/data/': 'http://localhost:9876/base/data/',
'/manifest.json': 'http://localhost:9876/base/manifest.json',
},

reporters: ['progress'],
Expand Down
12 changes: 7 additions & 5 deletions tests/setup.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'use strict';

// sinon-chrome defines chrome, but firefox uses browser
var browser = typeof chrome !== 'undefined' ? chrome : browser
const browser = typeof chrome !== 'undefined' ? chrome : browser

// sinon-chrome does not get the manifest
browser.runtime = Object.assign({
getManifest: () => ({
"name": "Clean Links",
"description": "Converts obfuscated/nested links to genuine clean links",
"author": "Cimbali (maintainer), \nDiego Casorran (creator), \nEduard Braun (German translation), \nSimon Chan (Chinese and Taiwanese translations)",
"version": "3.0.3",
"author": "Cimbali (maintainer), \nDiego Casorran (historic creator), \nEduard Braun (German translation), \nSimon Chan (Chinese and Taiwanese translations)",
"version": "tests",
"homepage_url": "https://github.com/Cimbali/CleanLinks",
}),
getURL: (url) => ('/' + url.replace(/^\/+/, '')),
getURL: url => ('/' + url.replace(/^\/+/, '')),
onMessage: {addListener: () => {}}
}, browser.runtime)

Expand All @@ -30,7 +32,7 @@ browser.storage.sync = browser.storage.local = {
else if (typeof keys === 'object')
{
key_filter = candidate => candidate in keys
defauts = {...keys};
defaults = {...keys};
}
else
return Promise.reject('Unknown type of key ' + keys)
Expand Down

0 comments on commit 54a42c1

Please sign in to comment.