mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 09:28:51 +00:00
testing infra: basic QueryViewCtrl tests
This commit is contained in:
parent
9cfae349da
commit
a74ae32122
@ -89,4 +89,4 @@ angular.module('redash', [
|
||||
|
||||
|
||||
}
|
||||
]);
|
||||
]);
|
||||
|
@ -144,4 +144,4 @@
|
||||
angular.module('redash.controllers')
|
||||
.controller('QueryViewCtrl',
|
||||
['$scope', 'Events', '$route', '$location', 'notifications', 'growl', 'Query', 'DataSource', QueryViewCtrl]);
|
||||
})();
|
||||
})();
|
||||
|
@ -18,61 +18,65 @@ module.exports = function(config) {
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
"app/bower_components/jquery/jquery.js",
|
||||
"app/bower_components/angular/angular.js",
|
||||
"app/bower_components/jquery-ui/ui/jquery-ui.js",
|
||||
"app/bower_components/bootstrap/js/collapse.js",
|
||||
"app/bower_components/bootstrap/js/modal.js",
|
||||
"app/bower_components/angular-resource/angular-resource.js",
|
||||
"app/bower_components/angular-route/angular-route.js",
|
||||
"app/bower_components/underscore/underscore.js",
|
||||
"app/bower_components/moment/moment.js",
|
||||
"app/bower_components/angular-moment/angular-moment.js",
|
||||
"app/bower_components/codemirror/lib/codemirror.js",
|
||||
"app/bower_components/codemirror/addon/edit/matchbrackets.js",
|
||||
"app/bower_components/codemirror/addon/edit/closebrackets.js",
|
||||
"app/bower_components/codemirror/mode/sql/sql.js",
|
||||
"app/bower_components/codemirror/mode/javascript/javascript.js",
|
||||
"app/bower_components/angular-ui-codemirror/ui-codemirror.js",
|
||||
"app/bower_components/highcharts/highcharts.js",
|
||||
"app/bower_components/highcharts/modules/exporting.js",
|
||||
"app/bower_components/gridster/dist/jquery.gridster.js",
|
||||
"app/bower_components/angular-growl/build/angular-growl.js",
|
||||
"app/bower_components/pivottable/dist/pivot.js",
|
||||
"app/bower_components/cornelius/src/cornelius.js",
|
||||
"app/bower_components/mousetrap/mousetrap.js",
|
||||
"app/bower_components/mousetrap/plugins/global-bind/mousetrap-global-bind.js",
|
||||
"app/bower_components/select2/select2.js",
|
||||
"app/bower_components/angular-ui-select2/src/select2.js",
|
||||
"app/bower_components/underscore.string/lib/underscore.string.js",
|
||||
"app/bower_components/marked/lib/marked.js",
|
||||
"app/scripts/ng_highchart.js",
|
||||
"app/scripts/ng_smart_table.js",
|
||||
"app/scripts/ui-bootstrap-tpls-0.5.0.min.js",
|
||||
"app/bower_components/bucky/bucky.js",
|
||||
"app/bower_components/pace/pace.js",
|
||||
'app/bower_components/jquery/jquery.js',
|
||||
'app/bower_components/jquery-ui/ui/jquery-ui.js',
|
||||
|
||||
"app/scripts/app.js",
|
||||
"app/scripts/services/services.js",
|
||||
"app/scripts/services/resources.js",
|
||||
"app/scripts/services/notifications.js",
|
||||
"app/scripts/services/dashboards.js",
|
||||
"app/scripts/controllers/controllers.js",
|
||||
"app/scripts/controllers/dashboard.js",
|
||||
"app/scripts/controllers/admin_controllers.js",
|
||||
"app/scripts/controllers/query_view.js",
|
||||
"app/scripts/controllers/query_source.js",
|
||||
"app/scripts/visualizations/base.js",
|
||||
"app/scripts/visualizations/chart.js",
|
||||
"app/scripts/visualizations/cohort.js",
|
||||
"app/scripts/visualizations/table.js",
|
||||
"app/scripts/visualizations/pivot.js",
|
||||
"app/scripts/directives/directives.js",
|
||||
"app/scripts/directives/query_directives.js",
|
||||
"app/scripts/directives/dashboard_directives.js",
|
||||
"app/scripts/filters.js",
|
||||
'app/bower_components/angular/angular.js',
|
||||
'app/bower_components/angular-route/angular-route.js',
|
||||
'app/bower_components/angular-mocks/angular-mocks.js',
|
||||
|
||||
'test/spec/**/*.js'
|
||||
'app/bower_components/bootstrap/js/collapse.js',
|
||||
'app/bower_components/bootstrap/js/modal.js',
|
||||
'app/bower_components/angular-resource/angular-resource.js',
|
||||
'app/bower_components/underscore/underscore.js',
|
||||
'app/bower_components/moment/moment.js',
|
||||
'app/bower_components/angular-moment/angular-moment.js',
|
||||
'app/bower_components/codemirror/lib/codemirror.js',
|
||||
'app/bower_components/codemirror/addon/edit/matchbrackets.js',
|
||||
'app/bower_components/codemirror/addon/edit/closebrackets.js',
|
||||
'app/bower_components/codemirror/mode/sql/sql.js',
|
||||
'app/bower_components/codemirror/mode/javascript/javascript.js',
|
||||
'app/bower_components/angular-ui-codemirror/ui-codemirror.js',
|
||||
'app/bower_components/highcharts/highcharts.js',
|
||||
'app/bower_components/highcharts/modules/exporting.js',
|
||||
'app/bower_components/gridster/dist/jquery.gridster.js',
|
||||
'app/bower_components/angular-growl/build/angular-growl.js',
|
||||
'app/bower_components/pivottable/dist/pivot.js',
|
||||
'app/bower_components/cornelius/src/cornelius.js',
|
||||
'app/bower_components/mousetrap/mousetrap.js',
|
||||
'app/bower_components/mousetrap/plugins/global-bind/mousetrap-global-bind.js',
|
||||
'app/bower_components/select2/select2.js',
|
||||
'app/bower_components/angular-ui-select2/src/select2.js',
|
||||
'app/bower_components/underscore.string/lib/underscore.string.js',
|
||||
'app/bower_components/marked/lib/marked.js',
|
||||
'app/scripts/ng_highchart.js',
|
||||
'app/scripts/ng_smart_table.js',
|
||||
'app/scripts/ui-bootstrap-tpls-0.5.0.min.js',
|
||||
'app/bower_components/bucky/bucky.js',
|
||||
'app/bower_components/pace/pace.js',
|
||||
|
||||
'app/scripts/app.js',
|
||||
'app/scripts/services/services.js',
|
||||
'app/scripts/services/resources.js',
|
||||
'app/scripts/services/notifications.js',
|
||||
'app/scripts/services/dashboards.js',
|
||||
'app/scripts/controllers/controllers.js',
|
||||
'app/scripts/controllers/dashboard.js',
|
||||
'app/scripts/controllers/admin_controllers.js',
|
||||
'app/scripts/controllers/query_view.js',
|
||||
'app/scripts/controllers/query_source.js',
|
||||
'app/scripts/visualizations/base.js',
|
||||
'app/scripts/visualizations/chart.js',
|
||||
'app/scripts/visualizations/cohort.js',
|
||||
'app/scripts/visualizations/table.js',
|
||||
'app/scripts/visualizations/pivot.js',
|
||||
'app/scripts/directives/directives.js',
|
||||
'app/scripts/directives/query_directives.js',
|
||||
'app/scripts/directives/dashboard_directives.js',
|
||||
'app/scripts/filters.js',
|
||||
|
||||
'test/mocks/*.js',
|
||||
'test/unit/*.js'
|
||||
],
|
||||
|
||||
// list of files / patterns to exclude
|
||||
|
77
rd_ui/test/mocks/redashMocks.js
Normal file
77
rd_ui/test/mocks/redashMocks.js
Normal file
@ -0,0 +1,77 @@
|
||||
// these are non angu
|
||||
featureFlags = [];
|
||||
currentUser = {
|
||||
id: 1,
|
||||
name: 'John Mock',
|
||||
email: 'john@example.com',
|
||||
groups: ['default'],
|
||||
permissions: [],
|
||||
canEdit: function(object) {
|
||||
var user_id = object.user_id || (object.user && object.user.id);
|
||||
return user_id && (user_id == currentUser.id);
|
||||
},
|
||||
hasPermission: function(permission) {
|
||||
return this.permissions.indexOf(permission) != -1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
angular.module('redashMocks', [])
|
||||
.value('mockData', {
|
||||
query: {
|
||||
|
||||
"ttl": -1,
|
||||
"query": "select name from users;",
|
||||
"id": 1803,
|
||||
"description": "",
|
||||
"name": "my test query",
|
||||
"created_at": "2014-01-07T16:11:31.859528+02:00",
|
||||
"query_hash": "c89c235bc73e462e9702debc56adc309",
|
||||
|
||||
"user": {
|
||||
"email": "amirn@everything.me",
|
||||
"id": 48,
|
||||
"name": "Amir Nissim"
|
||||
},
|
||||
|
||||
"visualizations": [{
|
||||
"description": "",
|
||||
"options": {},
|
||||
"type": "TABLE",
|
||||
"id": 636,
|
||||
"name": "Table"
|
||||
}],
|
||||
|
||||
"api_key": "123456789",
|
||||
|
||||
"data_source_id": 1,
|
||||
|
||||
"latest_query_data_id": 106632,
|
||||
|
||||
"latest_query_data": {
|
||||
"retrieved_at": "2014-07-29T10:49:10.951364+03:00",
|
||||
"query_hash": "c89c235bc73e462e9702debc56adc309",
|
||||
"query": "select name from users;",
|
||||
"runtime": 0.0139260292053223,
|
||||
"data": {
|
||||
"rows": [{
|
||||
"name": "Amir Nissim"
|
||||
}, {
|
||||
"name": "Arik Fraimovich"
|
||||
}],
|
||||
"columns": [{
|
||||
"friendly_name": "name",
|
||||
"type": null,
|
||||
"name": "name"
|
||||
}, {
|
||||
"friendly_name": "mail::filter",
|
||||
"type": null,
|
||||
"name": "mail::filter"
|
||||
}]
|
||||
},
|
||||
"id": 106632,
|
||||
"data_source_id": 1
|
||||
}
|
||||
|
||||
}
|
||||
});
|
36
rd_ui/test/unit/test_query_view.js
Normal file
36
rd_ui/test/unit/test_query_view.js
Normal file
@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
describe('QueryViewCtrl', function() {
|
||||
var scope;
|
||||
var mockData;
|
||||
|
||||
beforeEach(module('redash', 'redashMocks'));
|
||||
|
||||
beforeEach(inject(function($injector, $controller, $rootScope, Query, _mockData_) {
|
||||
mockData = _mockData_;
|
||||
scope = $rootScope.$new();
|
||||
|
||||
var route = {
|
||||
current: {
|
||||
locals: {
|
||||
query: new Query(mockData.query)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$controller('QueryViewCtrl', {$scope: scope, $route: route});
|
||||
}));
|
||||
|
||||
it('should have a query', function() {
|
||||
expect(scope.query).toBeDefined();
|
||||
});
|
||||
|
||||
it('should update the executing state', function() {
|
||||
expect(scope.queryExecuting).toBe(false);
|
||||
scope.executeQuery();
|
||||
expect(scope.queryExecuting).toBe(true);
|
||||
scope.cancelExecution();
|
||||
expect(scope.queryExecuting).toBe(false);
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user