mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
Added more tests
This commit is contained in:
parent
5d83f248a4
commit
f6c8b9bfb7
8 changed files with 281 additions and 13 deletions
207
luciexpress/htdocs/plugins/core/widgets/luci.brightness.js
Normal file
207
luciexpress/htdocs/plugins/core/widgets/luci.brightness.js
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
jQuery UI Slider plugin wrapper
|
||||
*/
|
||||
JUCI.app.value('uiSliderConfig',{}).directive('luciSlider', ['uiSliderConfig', '$timeout', function(uiSliderConfig, $timeout) {
|
||||
uiSliderConfig = uiSliderConfig || {};
|
||||
return {
|
||||
require: 'ngModel',
|
||||
compile: function() {
|
||||
var preLink = function (scope, elm, attrs, ngModel) {
|
||||
|
||||
function parseNumber(n, decimals) {
|
||||
return (decimals) ? parseFloat(n) : parseInt(n, 10);
|
||||
}
|
||||
|
||||
var options = angular.extend(scope.$eval(attrs.uiSlider) || {}, uiSliderConfig);
|
||||
// Object holding range values
|
||||
var prevRangeValues = {
|
||||
min: null,
|
||||
max: null
|
||||
};
|
||||
|
||||
// convenience properties
|
||||
var properties = ['min', 'max', 'step', 'lowerBound', 'upperBound'];
|
||||
var useDecimals = (!angular.isUndefined(attrs.useDecimals)) ? true : false;
|
||||
|
||||
var init = function() {
|
||||
// When ngModel is assigned an array of values then range is expected to be true.
|
||||
// Warn user and change range to true else an error occurs when trying to drag handle
|
||||
if (angular.isArray(ngModel.$viewValue) && options.range !== true) {
|
||||
console.warn('Change your range option of ui-slider. When assigning ngModel an array of values then the range option should be set to true.');
|
||||
options.range = true;
|
||||
}
|
||||
|
||||
// Ensure the convenience properties are passed as options if they're defined
|
||||
// This avoids init ordering issues where the slider's initial state (eg handle
|
||||
// position) is calculated using widget defaults
|
||||
// Note the properties take precedence over any duplicates in options
|
||||
angular.forEach(properties, function(property) {
|
||||
if (angular.isDefined(attrs[property])) {
|
||||
options[property] = parseNumber(attrs[property], useDecimals);
|
||||
}
|
||||
});
|
||||
|
||||
elm.slider(options);
|
||||
init = angular.noop;
|
||||
};
|
||||
|
||||
// Find out if decimals are to be used for slider
|
||||
angular.forEach(properties, function(property) {
|
||||
// support {{}} and watch for updates
|
||||
attrs.$observe(property, function(newVal) {
|
||||
if (!!newVal) {
|
||||
init();
|
||||
options[property] = parseNumber(newVal, useDecimals);
|
||||
elm.slider('option', property, parseNumber(newVal, useDecimals));
|
||||
ngModel.$render();
|
||||
}
|
||||
});
|
||||
});
|
||||
attrs.$observe('disabled', function(newVal) {
|
||||
init();
|
||||
elm.slider('option', 'disabled', !!newVal);
|
||||
});
|
||||
|
||||
// Watch ui-slider (byVal) for changes and update
|
||||
scope.$watch(attrs.uiSlider, function(newVal) {
|
||||
init();
|
||||
if(newVal !== undefined) {
|
||||
elm.slider('option', newVal);
|
||||
}
|
||||
}, true);
|
||||
|
||||
// Late-bind to prevent compiler clobbering
|
||||
$timeout(init, 0, true);
|
||||
|
||||
// Update model value from slider
|
||||
elm.bind('slide', function(event, ui) {
|
||||
var valuesChanged;
|
||||
|
||||
if (ui.values) {
|
||||
var boundedValues = ui.values.slice();
|
||||
|
||||
if (options.lowerBound && boundedValues[0] < options.lowerBound) {
|
||||
boundedValues[0] = Math.max(boundedValues[0], options.lowerBound);
|
||||
}
|
||||
if (options.upperBound && boundedValues[1] > options.upperBound) {
|
||||
boundedValues[1] = Math.min(boundedValues[1], options.upperBound);
|
||||
}
|
||||
|
||||
if (boundedValues[0] !== ui.values[0] || boundedValues[1] !== ui.values[1]) {
|
||||
valuesChanged = true;
|
||||
ui.values = boundedValues;
|
||||
}
|
||||
} else {
|
||||
var boundedValue = ui.value;
|
||||
|
||||
if (options.lowerBound && boundedValue < options.lowerBound) {
|
||||
boundedValue = Math.max(boundedValue, options.lowerBound);
|
||||
}
|
||||
if (options.upperBound && boundedValue > options.upperBound) {
|
||||
boundedValue = Math.min(boundedValue, options.upperBound);
|
||||
}
|
||||
|
||||
if (boundedValue !== ui.value) {
|
||||
valuesChanged = true;
|
||||
ui.value = boundedValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ngModel.$setViewValue(ui.values || ui.value);
|
||||
scope.$apply();
|
||||
|
||||
if (valuesChanged) {
|
||||
setTimeout(function() {
|
||||
elm.slider('value', ui.values || ui.values);
|
||||
}, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Update slider from model value
|
||||
ngModel.$render = function() {
|
||||
init();
|
||||
var method = options.range === true ? 'values' : 'value';
|
||||
|
||||
if (options.range !== true && isNaN(ngModel.$viewValue) && !(ngModel.$viewValue instanceof Array)) {
|
||||
ngModel.$viewValue = 0;
|
||||
}
|
||||
else if (options.range && !angular.isDefined(ngModel.$viewValue)) {
|
||||
ngModel.$viewValue = [0,0];
|
||||
}
|
||||
|
||||
// Do some sanity check of range values
|
||||
if (options.range === true) {
|
||||
|
||||
// Check outer bounds for min and max values
|
||||
if (angular.isDefined(options.min) && options.min > ngModel.$viewValue[0]) {
|
||||
ngModel.$viewValue[0] = options.min;
|
||||
}
|
||||
if (angular.isDefined(options.max) && options.max < ngModel.$viewValue[1]) {
|
||||
ngModel.$viewValue[1] = options.max;
|
||||
}
|
||||
|
||||
// Check min and max range values
|
||||
if (ngModel.$viewValue[0] > ngModel.$viewValue[1]) {
|
||||
// Min value should be less to equal to max value
|
||||
if (prevRangeValues.min >= ngModel.$viewValue[1]) {
|
||||
ngModel.$viewValue[0] = prevRangeValues.min;
|
||||
}
|
||||
// Max value should be less to equal to min value
|
||||
if (prevRangeValues.max <= ngModel.$viewValue[0]) {
|
||||
ngModel.$viewValue[1] = prevRangeValues.max;
|
||||
}
|
||||
}
|
||||
|
||||
// Store values for later user
|
||||
prevRangeValues.min = ngModel.$viewValue[0];
|
||||
prevRangeValues.max = ngModel.$viewValue[1];
|
||||
|
||||
}
|
||||
elm.slider(method, ngModel.$viewValue);
|
||||
};
|
||||
|
||||
scope.$watch(attrs.ngModel, function() {
|
||||
if (options.range === true) {
|
||||
ngModel.$render();
|
||||
}
|
||||
}, true);
|
||||
|
||||
function destroy() {
|
||||
if (elm.hasClass('ui-slider')) {
|
||||
elm.slider('destroy');
|
||||
}
|
||||
}
|
||||
|
||||
scope.$on("$destroy", destroy);
|
||||
elm.one('$destroy', destroy);
|
||||
};
|
||||
|
||||
var postLink = function (scope, element, attrs, ngModel) {
|
||||
// Add tick marks if 'tick' and 'step' attributes have been setted on element.
|
||||
// Support horizontal slider bar so far. 'tick' and 'step' attributes are required.
|
||||
var options = angular.extend({}, scope.$eval(attrs.uiSlider));
|
||||
var properties = ['max', 'step', 'tick'];
|
||||
angular.forEach(properties, function(property) {
|
||||
if (angular.isDefined(attrs[property])) {
|
||||
options[property] = attrs[property];
|
||||
}
|
||||
});
|
||||
if (angular.isDefined(options['tick']) && angular.isDefined(options['step'])) {
|
||||
var total = parseInt(parseInt(options['max'])/parseInt(options['step']));
|
||||
for (var i = total; i >= 0; i--) {
|
||||
var left = ((i / total) * 100) + '%';
|
||||
$("<div/>").addClass("ui-slider-tick").appendTo(element).css({left: left});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
pre: preLink,
|
||||
post: postLink
|
||||
};
|
||||
}
|
||||
};
|
||||
}]);
|
||||
14
luciexpress/htdocs/plugins/internet/tests/test-internet.js
Normal file
14
luciexpress/htdocs/plugins/internet/tests/test-internet.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
require("../../../../tests/lib-juci");
|
||||
|
||||
var completed = {
|
||||
"dns": 0,
|
||||
"exposed_host": 0,
|
||||
"firewall": 1,
|
||||
"port_mapping": 1
|
||||
}
|
||||
|
||||
describe("Internet plugin", function(){
|
||||
it("should be completed", function(){
|
||||
expect(Object.keys(completed).filter(function(x){ return completed[x] == 0; })).to.be.empty();
|
||||
});
|
||||
});
|
||||
19
luciexpress/htdocs/plugins/phone/tests/test-phone.js
Normal file
19
luciexpress/htdocs/plugins/phone/tests/test-phone.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
require("../../../../tests/lib-juci");
|
||||
|
||||
var completed = {
|
||||
"call_log": 1,
|
||||
"number_blocking": 1,
|
||||
"ringing_schedule": 0,
|
||||
"speed_dialing": 0,
|
||||
"numbers": 0
|
||||
}
|
||||
|
||||
describe("Phone plugin", function(){
|
||||
it("should be completed", function(){
|
||||
expect(completed.call_log).to.be(1);
|
||||
expect(completed.number_blocking).to.be(1);
|
||||
expect(completed.ringing_schedule).to.be(1);
|
||||
expect(completed.speed_dialing).to.be(1);
|
||||
expect(completed.numbers).to.be(1);
|
||||
});
|
||||
});
|
||||
15
luciexpress/htdocs/plugins/settings/tests/test-settings.js
Normal file
15
luciexpress/htdocs/plugins/settings/tests/test-settings.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
require("../../../../tests/lib-juci");
|
||||
|
||||
var completed = {
|
||||
"configuration": 1,
|
||||
"energy": 0,
|
||||
"network": 0,
|
||||
"password": 0,
|
||||
"upgrade": 0
|
||||
}
|
||||
|
||||
describe("Settings", function(){
|
||||
it("should be completed", function(){
|
||||
expect(Object.keys(completed).filter(function(x){ return completed[x] == 0; })).to.be.empty();
|
||||
});
|
||||
});
|
||||
23
luciexpress/htdocs/plugins/status/tests/test-status.js
Normal file
23
luciexpress/htdocs/plugins/status/tests/test-status.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
require("../../../../tests/lib-juci");
|
||||
|
||||
var completed = {
|
||||
"about": 1,
|
||||
"diagnostics": 1,
|
||||
"events": 0,
|
||||
"nat": 0,
|
||||
"restart": 1,
|
||||
"status.dsl": 0,
|
||||
"status.status": 1,
|
||||
"status.tv": 0,
|
||||
"status.voice": 0
|
||||
}
|
||||
|
||||
describe("Status", function(){
|
||||
it("should be completed", function(){
|
||||
expect(Object.keys(completed).filter(function(x){ return completed[x] == 0; })).to.be.empty();
|
||||
});
|
||||
it("should have router.info rpc call", function(done){
|
||||
expect($rpc.router).to.be.ok();
|
||||
expect($rpc.router.info).to.be.ok();
|
||||
});
|
||||
});
|
||||
|
|
@ -11,16 +11,4 @@ $juci.module("wifi")
|
|||
console.log("failed to sync config: "+err);
|
||||
});
|
||||
|
||||
|
||||
$scope.onApply = function(){
|
||||
$scope.busy = 1;
|
||||
$uci.save().done(function(){
|
||||
console.log("Saved wifi config!");
|
||||
}).fail(function(){
|
||||
console.log("Could not save wifi config!");
|
||||
}).always(function(){
|
||||
$scope.busy = 0;
|
||||
$scope.$apply();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
<input type="text" class="form-control" ng-model="mac.macaddr" ng-blur="rebuildMacList()" placeholder="xx:xx:xx:xx:xx:xx" /><!-- ng-pattern="/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/"-->
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-default" ng-click="onDeleteHost(host)"><i class="fa fa-trash-o"></i></button>
|
||||
<button class="btn btn-default" ng-click="onDeleteHost(mac)"><i class="fa fa-trash-o"></i></button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ $juci.module("wifi")
|
|||
added = { hostname: host.hostname.value, macaddr: mac};
|
||||
}
|
||||
});
|
||||
added.maclist = i.maclist;
|
||||
$scope.maclist.push(added);
|
||||
});
|
||||
//$scope.$apply();
|
||||
|
|
@ -93,6 +94,7 @@ $juci.module("wifi")
|
|||
|
||||
$scope.onDeleteHost = function(host){
|
||||
$scope.maclist = ($scope.maclist||[]).filter(function(x) { return x.macaddr != host.macaddr; });
|
||||
host.maclist.value = host.maclist.value.filter(function(x) { return x != host.macaddr; });
|
||||
}
|
||||
|
||||
$scope.onAddClients = function(){
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue