Skip to content
Snippets Groups Projects
Commit 3accbc6f authored by didierfred's avatar didierfred
Browse files

add jasmine tests

parent 6d9f7e9a
No related branches found
No related tags found
No related merge requests found
Copyright (c) 2008-2017 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jasmine Spec Runner v3.3.0</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-3.3.0/jasmine_favicon.png">
<link rel="stylesheet" href="lib/jasmine-3.3.0/jasmine.css">
<script src="../popup/config.js"></script>
<script src="lib/jasmine-3.3.0/jasmine.js"></script>
<script src="lib/jasmine-3.3.0/jasmine-html.js"></script>
<script src="lib/jasmine-3.3.0/boot.js"></script>
<!-- include source files here... -->
<!-- include spec files here... -->
<script src="spec/ConfigSpec.js"></script>
</head>
<body>
<div hidden>
<!-- MAIN SCREEN -->
<div id="main_screen" style="text-align:center">
<table class="standard_table">
<tr>
<td style="text-align:left"><h2 class="title"> SIMPLE MODIFY HEADERS </h2> </td>
<td style="text-align:right"> <img id="start_img" src="img/start.png" alt="start/stop" style="float:right;vertical-align:top"> </img> </td>
</tr>
</table>
<br/>
<br/>
<table class="standard_table">
<tr>
<td style="text-align:left" > <strong> Url Patterns* : </strong> <input id="targetPage" class="form_control input_url" type="text" value=""> </td>
<td style="text-align:right">
<a href="#" id="export_button" class="btn btn-primary btn-sm" >
<span class="glyphicon glyphicon-export"></span> Export
</a>
<a href="#" id="import_button" class="btn btn-primary btn-sm" >
<span class="glyphicon glyphicon-import"></span> Import
</a>
<a href="#" id="parameters_button" class="btn btn-primary btn-sm">
<span class="glyphicon glyphicon-cog"></span> Parameters
</a>
</td>
</tr>
</table>
<br/> <br/>
<table id="table_config" class="table table-condensed " >
<thead>
<tr id="config_table_head">
<th> When URL contains </th>
<th> Action </th>
<th> Header Field Name </th>
<th> Header Field Value </th>
<th> Comment </th>
<th> Apply on </th>
<th> Status </th>
<th> </th>
<th> </th>
<th> </th>
</tr>
</thead>
<tbody id="config_tab">
</tbody>
</table>
<table class="standard_table"> <tr><td style="text-align:center">
<a href="#" id="add_button" class="btn btn-primary btn-sm" style="width:100px">
<span class="glyphicon glyphicon-plus"></span> New line
</a>
<a href="#" id="save_button" class="btn btn-primary btn-sm" style="width:100px">
<span class="glyphicon glyphicon-save"></span> Save
</a>
</td></tr></table>
<br/>
<table class="standard_table">
<tr>
<td style="text-align:left" >
<em style="font-size:10pt"> * Informations on url pattern can be found <a href="https://developer.chrome.com/extensions/match_patterns" target="_blank"> here.</a> <br> An empty string on the field will select all urls. It's possible to select mutliple url patterns using semicolon(;) separator </em>
</td>
<td style="text-align:right">
<a href="https://github.com/didierfred/SimpleModifyHeaders/tree/v1.6.2" target="_blank"> <span class="glyphicon glyphicon-question-sign"></span> About </a>
</td>
</tr>
</table>
</div>
<!-- PARAMETERS SCREEN -->
<div id="parameters_screen" hidden>
<h2 class="title"> SIMPLE MODIFY HEADERS </h2>
<strong> Parameters : </strong>
<br/>
<br/>
<input type="checkbox" id="debug_mode"> Debug mode </input>
<br/>
<input type="checkbox" id="show_comments"> Show comments </input>
<br/>
<input type="checkbox" id="use_url_contains"> Filter URL per rules </input>
<br/>
<br/>
<a href="#" id="exit_parameters_screen_button" class="btn btn-primary btn-sm" style="width:100px">
<span class="glyphicon glyphicon-step-backward"></span> Back
</a>
</div>
<iframe id="download" title="hidden_download_frame" width="0" height="0" style="border:none;">
</iframe>
<br/>
</div>
</div>
</body>
</html>
/**
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
[jasmine-gem]: http://github.com/pivotal/jasmine-gem
*/
(function() {
/**
* ## Require &amp; Instantiate
*
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
*/
window.jasmine = jasmineRequire.core(jasmineRequire);
/**
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
*/
jasmineRequire.html(jasmine);
/**
* Create the Jasmine environment. This is used to run all specs in a project.
*/
var env = jasmine.getEnv();
/**
* ## The Global Interface
*
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
*/
var jasmineInterface = jasmineRequire.interface(jasmine, env);
/**
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
*/
extend(window, jasmineInterface);
/**
* ## Runner Parameters
*
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
*/
var queryString = new jasmine.QueryString({
getWindowLocation: function() { return window.location; }
});
var filterSpecs = !!queryString.getParam("spec");
var config = {
failFast: queryString.getParam("failFast"),
oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
hideDisabled: queryString.getParam("hideDisabled")
};
var random = queryString.getParam("random");
if (random !== undefined && random !== "") {
config.random = random;
}
var seed = queryString.getParam("seed");
if (seed) {
config.seed = seed;
}
/**
* ## Reporters
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
*/
var htmlReporter = new jasmine.HtmlReporter({
env: env,
navigateWithNewParam: function(key, value) { return queryString.navigateWithNewParam(key, value); },
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
getContainer: function() { return document.body; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
timer: new jasmine.Timer(),
filterSpecs: filterSpecs
});
/**
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
*/
env.addReporter(jasmineInterface.jsApiReporter);
env.addReporter(htmlReporter);
/**
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
*/
var specFilter = new jasmine.HtmlSpecFilter({
filterString: function() { return queryString.getParam("spec"); }
});
config.specFilter = function(spec) {
return specFilter.matches(spec.getFullName());
};
env.configure(config);
/**
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
*/
window.setTimeout = window.setTimeout;
window.setInterval = window.setInterval;
window.clearTimeout = window.clearTimeout;
window.clearInterval = window.clearInterval;
/**
* ## Execution
*
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
*/
var currentWindowOnload = window.onload;
window.onload = function() {
// if (currentWindowOnload) {
// currentWindowOnload();
// }
htmlReporter.initialize();
env.execute();
};
/**
* Helper function for readability above.
*/
function extend(destination, source) {
for (var property in source) destination[property] = source[property];
return destination;
}
}());
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
tests/lib/jasmine-3.3.0/jasmine_favicon.png

1.45 KiB

describe("Config", function() {
function cleanConfigTableForTest() {
let tr_elements = document.querySelectorAll("#config_tab tr");
for (let i=0;i<tr_elements.length;i++) {
tr_elements[i].parentNode.removeChild(tr_elements[i]);
}
}
function createDefaultConfigForTest() {
let headers = [];
headers.push({url_contains:"",action:"add",header_name:"test-header-name",header_value:"test-header-value",comment:"test",apply_on:"req",status:"on"});
config = {format_version:"1.1",target_page:"https://httpbin.org/*",headers:headers,debug_mode:false};
// save configuration
localStorage.setItem("config",JSON.stringify(config));
}
describe("#function initConfigurationPage", function() {
beforeEach(function() {
createDefaultConfigForTest();
});
it("init default value should be ok ", function() {
initConfigurationPage();
expect(document.getElementById("debug_mode").checked).toEqual(false);
expect(document.getElementById("show_comments").checked).toEqual(true);
expect(document.getElementById("use_url_contains").checked).toEqual(false);
expect(document.getElementById("targetPage").value).toEqual("https://httpbin.org/*");
expect(document.getElementById("url_contains1").value).toEqual("");
expect(document.getElementById("select_action1").value).toEqual("add");
expect(document.getElementById("header_name1").value).toEqual("test-header-name");
expect(document.getElementById("header_value1").value).toEqual("test-header-value");
expect(document.getElementById("comment1").value).toEqual("test");
expect(document.getElementById("apply_on1").value).toEqual("req");
expect(document.getElementById("activate_button1").className).toEqual("btn btn-primary btn-sm");
});
beforeEach(function() {
cleanConfigTableForTest();
});
});
describe("#function appendLine", function() {
beforeEach(function() {
createDefaultConfigForTest();
});
it("append one line should create a new line and not more ", function() {
initConfigurationPage();
appendLine("test","add","-","-","","req","on");
expect(document.getElementById("url_contains2")).not.toEqual(null);
expect(document.getElementById("url_contains3")).toEqual(null);
});
it("append two lines should create two lines and not more ", function() {
initConfigurationPage();
appendLine("test","add","-","-","","req","on");
appendLine("test","add","-","-","","req","on");
expect(document.getElementById("url_contains2")).not.toEqual(null);
expect(document.getElementById("url_contains3")).not.toEqual(null);
expect(document.getElementById("url_contains4")).toEqual(null);
});
it("append three lines should create three lines and not more ", function() {
initConfigurationPage();
appendLine("test","add","-","-","","req","on");
appendLine("test","add","-","-","","req","on");
appendLine("test","add","-","-","","req","on");
expect(document.getElementById("url_contains2")).not.toEqual(null);
expect(document.getElementById("url_contains3")).not.toEqual(null);
expect(document.getElementById("url_contains4")).not.toEqual(null);
expect(document.getElementById("url_contains5")).toEqual(null);
});
afterEach(function() {
cleanConfigTableForTest();
});
});
describe("#function deleteLine", function() {
beforeEach(function() {
createDefaultConfigForTest();
});
it("delete line 3 should delete line 3 form the GUI ", function() {
initConfigurationPage();
appendLine("line2","add","header_name2","header_value2","comment2","req","on");
appendLine("line3","add","header_name3","header_value3","comment3","req","on");
appendLine("line4","modify","test_name","test_value","test_comment","res","off");
deleteLine(3);
expect(document.getElementById("url_contains4")).toEqual(null);
expect(document.getElementById("url_contains3").value).toEqual("line4");
expect(document.getElementById("select_action3").value).toEqual("modify");
expect(document.getElementById("header_name3").value).toEqual("test_name");
expect(document.getElementById("header_value3").value).toEqual("test_value");
expect(document.getElementById("comment3").value).toEqual("test_comment");
expect(document.getElementById("apply_on3").value).toEqual("res");
expect(document.getElementById("activate_button3").className).toEqual("btn btn-default btn-sm");
expect(document.getElementById("url_contains2").value).toEqual("line2");
expect(document.getElementById("header_name2").value).toEqual("header_name2");
expect(document.getElementById("header_value2").value).toEqual("header_value2");
expect(document.getElementById("comment2").value).toEqual("comment2");
});
it("delete line 1 should delete line 1 form the GUI ", function() {
initConfigurationPage();
appendLine("line2","add","-","-","","req","on");
appendLine("line3","add","-","-","","req","on");
appendLine("line4","add","-","-","","req","on");
deleteLine(1);
expect(document.getElementById("url_contains4")).toEqual(null);
expect(document.getElementById("url_contains3").value).toEqual("line4");
expect(document.getElementById("url_contains2").value).toEqual("line3");
expect(document.getElementById("url_contains1").value).toEqual("line2");
});
afterEach(function() {
cleanConfigTableForTest();
});
});
describe("#function invertLine", function() {
beforeEach(function() {
createDefaultConfigForTest();
});
it("invert line 2 with line 3 should invert line on the GUI ", function() {
initConfigurationPage();
appendLine("line2","add","header_name2","header_value2","comment2","res","off");
appendLine("line3","delete","header_name3","header_value3","comment3","req","on");
appendLine("line4","modify","test_name","test_value","test_comment","res","off");
invertLine(2,3);
expect(document.getElementById("url_contains4").value).toEqual("line4");
expect(document.getElementById("url_contains3").value).toEqual("line2");
expect(document.getElementById("url_contains2").value).toEqual("line3");
expect(document.getElementById("select_action3").value).toEqual("add");
expect(document.getElementById("select_action2").value).toEqual("delete");
expect(document.getElementById("header_name3").value).toEqual("header_name2");
expect(document.getElementById("header_name2").value).toEqual("header_name3")
expect(document.getElementById("header_value3").value).toEqual("header_value2");
expect(document.getElementById("header_value2").value).toEqual("header_value3");
expect(document.getElementById("comment3").value).toEqual("comment2");
expect(document.getElementById("comment2").value).toEqual("comment3");
expect(document.getElementById("apply_on3").value).toEqual("res");
expect(document.getElementById("apply_on2").value).toEqual("req");
expect(document.getElementById("activate_button3").className).toEqual("btn btn-default btn-sm"); // button off
expect(document.getElementById("activate_button2").className).toEqual("btn btn-primary btn-sm"); // button on
});
it("invert line 0 with line 3 should do nothing ", function() {
initConfigurationPage();
appendLine("line2","add","header_name2","header_value2","comment2","res","off");
appendLine("line3","delete","header_name3","header_value3","comment3","req","on");
appendLine("line4","modify","test_name","test_value","test_comment","res","off");
invertLine(0,3);
expect(document.getElementById("url_contains1").value).toEqual("");
expect(document.getElementById("select_action1").value).toEqual("add");
expect(document.getElementById("header_name1").value).toEqual("test-header-name");
expect(document.getElementById("header_value1").value).toEqual("test-header-value");
expect(document.getElementById("comment1").value).toEqual("test");
expect(document.getElementById("apply_on1").value).toEqual("req");
expect(document.getElementById("activate_button1").className).toEqual("btn btn-primary btn-sm");
expect(document.getElementById("url_contains4").value).toEqual("line4");
expect(document.getElementById("url_contains3").value).toEqual("line3");
expect(document.getElementById("url_contains2").value).toEqual("line2");
expect(document.getElementById("select_action3").value).toEqual("delete");
expect(document.getElementById("select_action2").value).toEqual("add");
expect(document.getElementById("header_name3").value).toEqual("header_name3");
expect(document.getElementById("header_name2").value).toEqual("header_name2")
expect(document.getElementById("header_value3").value).toEqual("header_value3");
expect(document.getElementById("header_value2").value).toEqual("header_value2");
expect(document.getElementById("comment3").value).toEqual("comment3");
expect(document.getElementById("comment2").value).toEqual("comment2");
expect(document.getElementById("apply_on3").value).toEqual("req");
expect(document.getElementById("apply_on2").value).toEqual("res");
expect(document.getElementById("activate_button2").className).toEqual("btn btn-default btn-sm"); // button off
expect(document.getElementById("activate_button3").className).toEqual("btn btn-primary btn-sm"); // button on
});
it("invert line 4 with line 5 should do nothing ", function() {
initConfigurationPage();
appendLine("line2","add","header_name2","header_value2","comment2","res","off");
appendLine("line3","delete","header_name3","header_value3","comment3","req","on");
appendLine("line4","modify","test_name","test_value","test_comment","res","off");
invertLine(4,5);
expect(document.getElementById("url_contains1").value).toEqual("");
expect(document.getElementById("select_action1").value).toEqual("add");
expect(document.getElementById("header_name1").value).toEqual("test-header-name");
expect(document.getElementById("header_value1").value).toEqual("test-header-value");
expect(document.getElementById("comment1").value).toEqual("test");
expect(document.getElementById("apply_on1").value).toEqual("req");
expect(document.getElementById("activate_button1").className).toEqual("btn btn-primary btn-sm");// button on
expect(document.getElementById("url_contains4").value).toEqual("line4");
expect(document.getElementById("select_action4").value).toEqual("modify");
expect(document.getElementById("header_name4").value).toEqual("test_name");
expect(document.getElementById("header_value4").value).toEqual("test_value");
expect(document.getElementById("comment4").value).toEqual("test_comment");
expect(document.getElementById("apply_on4").value).toEqual("res");
expect(document.getElementById("activate_button4").className).toEqual("btn btn-default btn-sm");// button off
expect(document.getElementById("url_contains3").value).toEqual("line3");
expect(document.getElementById("url_contains2").value).toEqual("line2");
expect(document.getElementById("select_action3").value).toEqual("delete");
expect(document.getElementById("select_action2").value).toEqual("add");
expect(document.getElementById("header_name3").value).toEqual("header_name3");
expect(document.getElementById("header_name2").value).toEqual("header_name2")
expect(document.getElementById("header_value3").value).toEqual("header_value3");
expect(document.getElementById("header_value2").value).toEqual("header_value2");
expect(document.getElementById("comment3").value).toEqual("comment3");
expect(document.getElementById("comment2").value).toEqual("comment2");
expect(document.getElementById("apply_on3").value).toEqual("req");
expect(document.getElementById("apply_on2").value).toEqual("res");
expect(document.getElementById("activate_button2").className).toEqual("btn btn-default btn-sm"); // button off
expect(document.getElementById("activate_button3").className).toEqual("btn btn-primary btn-sm"); // button on
});
afterEach(function() {
cleanConfigTableForTest();
});
});
describe("#function isTargetValid ", function() {
it("should validate the * pattern", function() {
expect(isTargetValid("*")).toEqual(true);
});
it("should validate the empty pattern", function() {
expect(isTargetValid("")).toEqual(true);
});
it("should validate the \" \" pattern", function() {
expect(isTargetValid(" ")).toEqual(true);
});
it("should validate the *://*/* pattern", function() {
expect(isTargetValid("*://*/*")).toEqual(true);
});
it("should validate the http://*/* pattern", function() {
expect(isTargetValid("http://*/*")).toEqual(true);
});
it("should validate the http://test/* pattern", function() {
expect(isTargetValid("http://test/*")).toEqual(true);
});
it("should validate the *://*/ pattern", function() {
expect(isTargetValid("*://*/")).toEqual(true);
});
it("should validate the http://test/ pattern", function() {
expect(isTargetValid("http://test/")).toEqual(true);
});
it("should validate the https://test/test pattern", function() {
expect(isTargetValid("https://test/test")).toEqual(true);
});
it("should not validate the *://*.test/ pattern", function() {
expect(isTargetValid("*://*.test/")).toEqual(true);
});
it("should not validate the test pattern", function() {
expect(isTargetValid("test")).toEqual(false);
});
it("should not validate the *://* pattern", function() {
expect(isTargetValid("*://*")).toEqual(false);
});
it("should not validate the tty://*/ pattern", function() {
expect(isTargetValid("tty://*/")).toEqual(false);
});
it("should not validate the *:/*/ pattern", function() {
expect(isTargetValid("*:/*/")).toEqual(false);
});
});
describe("#function checkTargetPageField ", function() {
it("text field url pattern should be black id pattern is valid", function() {
document.getElementById('targetPage').value = "*"
checkTargetPageField();
expect(document.getElementById('targetPage').style.color).toEqual("black");
});
it("text field url pattern should be red if pattern is invalid", function() {
document.getElementById('targetPage').value = "test"
checkTargetPageField();
expect(document.getElementById('targetPage').style.color).toEqual("red");
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment