From bd4dee8ad7577db8899a24e87e7faa48ec860188 Mon Sep 17 00:00:00 2001 From: Sarin Kizhakkepurayil Date: Mon, 24 Aug 2015 16:14:55 -0700 Subject: [PATCH] Relate-Bug: #1476413 1. file name changes for test, test suites, mock data - .test.js, .test.suite.js, .mock.data.js 2. adding infra for running library api tests. 3. new grunt target grunt api for starting api task. 4. updated test runner functions for common and lib tests. 5. TODO current GridView lib tests are not functoinal. needs update in *.lib.test.suite.js Change-Id: I92e916a3ff4ca2de478d61dd6ca90f6a4c1d24b0 --- webroot/test/ui/Gruntfile.js | 85 +++++ webroot/test/ui/js/co.test.app.js | 71 ++++ webroot/test/ui/js/co.test.app.utils.js | 19 +- webroot/test/ui/js/co.test.init.js | 48 ++- webroot/test/ui/js/co.test.mock.data.js | 42 +++ webroot/test/ui/js/co.test.unit.js | 305 ++++++++++++++++++ .../grid/ContrailListModel.lib.test.suite.js | 79 +++++ ...est.js => ContrailListModel.test.suite.js} | 2 +- webroot/test/ui/js/grid/GridView.lib.test.js | 28 ++ .../ui/js/grid/GridView.lib.test.suite.js | 25 ++ ...ridview.test.js => GridView.test.suite.js} | 2 +- webroot/test/ui/karma.config.js | 63 ++++ 12 files changed, 760 insertions(+), 9 deletions(-) create mode 100644 webroot/test/ui/Gruntfile.js create mode 100644 webroot/test/ui/js/co.test.app.js create mode 100644 webroot/test/ui/js/co.test.mock.data.js create mode 100644 webroot/test/ui/js/co.test.unit.js create mode 100644 webroot/test/ui/js/grid/ContrailListModel.lib.test.suite.js rename webroot/test/ui/js/grid/{listmodel.test.js => ContrailListModel.test.suite.js} (99%) create mode 100644 webroot/test/ui/js/grid/GridView.lib.test.js create mode 100644 webroot/test/ui/js/grid/GridView.lib.test.suite.js rename webroot/test/ui/js/grid/{gridview.test.js => GridView.test.suite.js} (99%) create mode 100644 webroot/test/ui/karma.config.js diff --git a/webroot/test/ui/Gruntfile.js b/webroot/test/ui/Gruntfile.js new file mode 100644 index 000000000..d614e6f4f --- /dev/null +++ b/webroot/test/ui/Gruntfile.js @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. + */ +module.exports = function (grunt) { + grunt.loadNpmTasks("grunt-contrib-jshint"); + grunt.loadNpmTasks("grunt-contrib-qunit"); + grunt.loadNpmTasks('grunt-qunit-junit'); + grunt.loadNpmTasks('grunt-karma'); + //this option is to avoid interruption of test case execution on failure of one in sequence + //grunt.option('force',true); + grunt.option('stack', true); + + var commonFiles = [ + {pattern: 'contrail-web-core/webroot/assets/**/!(tests)/*.js', included: false}, + {pattern: 'contrail-web-core/webroot/assets/**/*.css', included: false}, + {pattern: 'contrail-web-core/webroot/css/**/*.css', included: false}, + {pattern: 'contrail-web-core/webroot/test/ui/**/*.css', included: false}, + + {pattern: 'contrail-web-core/webroot/font/**/*.woff', included: false}, + {pattern: 'contrail-web-core/webroot/assets/**/*.woff', included: false}, + {pattern: 'contrail-web-core/webroot/assets/**/*.ttf', included: false}, + + {pattern: 'contrail-web-core/webroot/img/**/*.png', included: false}, + {pattern: 'contrail-web-core/webroot/css/**/*.png', included: false}, + {pattern: 'contrail-web-core/webroot/assets/select2/styles/**/*.png', included: false}, + {pattern: 'contrail-web-core/webroot/css/**/*.gif', included: false}, + + {pattern: 'contrail-web-core/webroot/test/ui/js/co.test.app.js'}, + {pattern: 'contrail-web-core/webroot/test/ui/js/**/co.test.*.js', included: false}, + {pattern: 'contrail-web-core/webroot/test/ui/js/**/*.lib.test.suite.js', included: false}, + {pattern: 'contrail-web-core/webroot/test/ui/js/**/*.lib.test.js', included: false}, + //{pattern: 'contrail-web-core/webroot/test/ui/js/**/*.lib.test.js', included: false}, + //{pattern: 'contrail-web-core/webroot/test/ui/js/**/*.lib.test.suite.js', included: false}, + //{pattern: 'contrail-web-core/webroot/test/ui/js/**/{!(*.lib.test.js), !(*.test.suite.js)}', included: false}, + //{pattern: 'contrail-web-core/webroot/test/ui/js/**/*.js', included: false}, + + {pattern: 'contrail-web-core/webroot/js/**/*.js', included: false}, + {pattern: 'contrail-web-core/webroot/templates/*.tmpl', included: false} + ]; + + var karmaConfig = { + options: { + configFile: 'karma.config.js', + }, + grid: { + options: { + files: [ + //{pattern: 'contrail-web-core/webroot/assets/slickgrid/js/slick.*.js'}, + {pattern: 'contrail-web-core/webroot/test/ui/js/grid/GridView.lib.test.js', included: false} + ], + preprocessors: { + 'contrail-web-core/webroot/assets/slickgrid/js/slick.*.js': ['coverage'] + } + } + } + }; + + for (var feature in karmaConfig) { + if (feature != 'options') { + karmaConfig[feature]['options']['files'] = commonFiles.concat(karmaConfig[feature]['options']['files']); + } + } + + grunt.initConfig({ + pkg: grunt.file.readJSON(__dirname + "/../../../../contrail-web-core/package.json"), + karma: karmaConfig, + jshint: { + options: { + jshintrc: ".jshintrc" + }, + files: ["Gruntfile.js"] + }, + api: { + grid: 'grid' + } + + }); + + grunt.registerMultiTask('api', 'Core libs API Test Cases', function () { + if (this.target == 'grid') { + grunt.task.run('karma:grid'); + + } + }); +}; diff --git a/webroot/test/ui/js/co.test.app.js b/webroot/test/ui/js/co.test.app.js new file mode 100644 index 000000000..fe65b1c47 --- /dev/null +++ b/webroot/test/ui/js/co.test.app.js @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. + */ + +var coreBaseDir = "/base/contrail-web-core/webroot", + featurePkg = "testLibApi"; + +require([ + coreBaseDir + '/js/core-app-utils.js', + coreBaseDir + '/test/ui/js/co.test.app.utils.js' +], function () { + globalObj['env'] = "test"; + + + requirejs.config({ + baseUrl: coreBaseDir, + paths: getCoreAppAndCoreTestAppPaths(coreBaseDir), + map: coreAppMap, + shim: getCoreAppAndCoreTestAppShims(), + waitSeconds: 0 + }); + + require(['co-test-init'], function () { + setFeaturePkgAndInit(featurePkg); + }); + + + function getCoreAppAndCoreTestAppPaths(coreBaseDir) { + var coreTestAppPathObj = {}; + var coreAppPaths = getCoreAppPaths(coreBaseDir); + var coreTestAppPaths = getCoreTestAppPaths(coreBaseDir); + + for (var key in coreAppPaths) { + if (coreAppPaths.hasOwnProperty(key)) { + var value = coreAppPaths[key]; + coreTestAppPathObj[key] = value; + } + } + + for (var key in coreTestAppPaths) { + if (coreTestAppPaths.hasOwnProperty(key)) { + var value = coreTestAppPaths[key]; + coreTestAppPathObj[key] = value; + } + } + + return coreTestAppPathObj; + }; + + function getCoreAppAndCoreTestAppShims() { + + var coreTestAppShims = {}; + + for (var key in coreAppShim) { + if (coreAppShim.hasOwnProperty(key)) { + var value = coreAppShim[key]; + coreTestAppShims[key] = value; + } + } + + for (var key in coreTestAppShim) { + if (coreTestAppShim.hasOwnProperty(key)) { + var value = coreTestAppShim[key]; + coreTestAppShims[key] = value; + } + } + + return coreTestAppShims; + }; + +}); diff --git a/webroot/test/ui/js/co.test.app.utils.js b/webroot/test/ui/js/co.test.app.utils.js index 02c28f757..28afe9983 100644 --- a/webroot/test/ui/js/co.test.app.utils.js +++ b/webroot/test/ui/js/co.test.app.utils.js @@ -11,13 +11,22 @@ function getCoreTestAppPaths(coreBaseDir) { 'co-test-constants' : coreTestAppBaseDir + '/co.test.constants', 'co-test-utils' : coreTestAppBaseDir + '/co.test.utils', 'co-test-messages' : coreTestAppBaseDir + '/co.test.messages', - 'co-test-mockdata' : coreTestAppBaseDir + '/co.test.mockdata', - 'co-unit-test' : coreTestAppBaseDir + '/co.unit.test', - 'co-test-grid-listmodel': coreTestAppBaseDir + '/grid/listmodel.test', - 'co-test-grid-gridview' : coreTestAppBaseDir + '/grid/gridview.test' + 'co-test-mockdata' : coreTestAppBaseDir + '/co.test.mock.data', + 'co-test-unit' : coreTestAppBaseDir + '/co.test.unit', + 'co-grid-contrail-list-model-test-suite' : coreTestAppBaseDir + '/grid/ContrailListModel.test.suite', + 'co-grid-view-test-suite' : coreTestAppBaseDir + '/grid/GridView.test.suite', + 'co-grid-contrail-list-model-lib-test-suite' : coreTestAppBaseDir + '/grid/ContrailListModel.lib.test.suite', + 'co-grid-view-lib-test-suite' : coreTestAppBaseDir + '/grid/GridView.lib.test.suite' }; } function coreTestAppShim() { - return {}; + return { + 'co-grid-contrail-list-model-lib-test-suite' : { + deps: ['slick.core', 'slick.dataview'] + }, + 'co-grid-view-lib-test-suite' : { + deps: ['slick.core', 'slick.grid', 'jquery-ui', 'slick.enhancementpager'] + } + }; } \ No newline at end of file diff --git a/webroot/test/ui/js/co.test.init.js b/webroot/test/ui/js/co.test.init.js index f0257b2e4..b59300dcc 100644 --- a/webroot/test/ui/js/co.test.init.js +++ b/webroot/test/ui/js/co.test.init.js @@ -2,12 +2,12 @@ * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. */ -var cowc, cowu, cowf, cowch, cowm, cotc; +var cowc, cowu, cowf, cowl, cowch, cowm, cotc; var allTestFiles = [], nmTestKarma = window.__karma__; for (var file in nmTestKarma.files) { - if (/Test\.js$/.test(file)) { + if (/\.test\.js$/.test(file)) { allTestFiles.push(file); } } @@ -62,6 +62,9 @@ function setFeaturePkgAndInit(featurePkg) { featurePkgObj.webServerInfo = 'smWebServerInfoMockData'; break; + case 'testLibApi': + return testLibApiAppInit({}); + } testAppInit(getTestAppConfig(featurePkgObj)); @@ -124,3 +127,44 @@ function testAppInit(testAppConfig) { }); }); } + +function testLibApiAppInit(testAppConfig) { + + require(['jquery', 'knockout', 'bezier'], function ($, Knockout, Bezier) { + window.ko = Knockout; + window.Bezier = Bezier; + + if (document.location.pathname.indexOf('/vcenter') == 0) { + $('head').append(''); + } + + require(depArray, function ($, _, validation, CoreConstants, CoreUtils, CoreFormatters, CoreMessages, CoreLabels, Knockout, Cache, + contrailCommon, CoreCommonTmpl, CoreTestUtils, CoreTestConstants, LayoutHandler) { + cowc = new CoreConstants(); + cowu = new CoreUtils(); + cowf = new CoreFormatters(); + cowm = new CoreMessages(); + cowl = new CoreLabels(); + cowch = new Cache(); + cotc = CoreTestConstants; + + $("body").addClass('navbar-fixed'); + $("body").append(CoreTestUtils.getPageHeaderHTML()); + $("body").append(CoreTestUtils.getSidebarHTML()); + $("body").append(CoreCommonTmpl); + + var cssList = CoreTestUtils.getCSSList(); + + for (var i = 0; i < cssList.length; i++) { + $("body").append(cssList[i]); + } + require(allTestFiles, function () { + requirejs.config({ + deps: allTestFiles, + callback: window.__karma__.start + }); + }); + }); + }); + +} \ No newline at end of file diff --git a/webroot/test/ui/js/co.test.mock.data.js b/webroot/test/ui/js/co.test.mock.data.js new file mode 100644 index 000000000..0aa76b2ed --- /dev/null +++ b/webroot/test/ui/js/co.test.mock.data.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. + */ +define(['underscore'], function (_) { + + //Compares client UTC time with the server UTC time and display alert if mismatch exceeds the threshold + var webServerInfoMockData = { + "orchestrationModel": [ + "openstack" + ], + "serverUTCTime": 1436203008000, + "hostName": "a7s14", + "role": [ + "superAdmin" + ], + "featurePkg": { + "webController": false, + "webStorage": false, + "serverManager": false + }, + "uiConfig": { + "nodemanager": { + "installed": true + } + }, + "loggedInOrchestrationMode": "openstack" + }; + + var disabledFeatureMockData = {"disabled":["config_alarms","mon_infra_mx"]}, + webControllerMockData = {"webController":{"path":"/usr/src/contrail-web-controller","enable":true}}, + ctWebServerInfoMockData = _.extend({}, webServerInfoMockData, {"featurePkg": { "webController": true }}), + smWebServerInfoMockData = _.extend({}, webServerInfoMockData, {"featurePkg": { "serverManager": true }}), + sWebServerInfoMockData = _.extend({}, webServerInfoMockData, {"featurePkg": { "webStorage": true }}); + + return { + ctWebServerInfoMockData: ctWebServerInfoMockData, + smWebServerInfoMockData: smWebServerInfoMockData, + sWebServerInfoMockData: sWebServerInfoMockData, + disabledFeatureMockData: disabledFeatureMockData, + webControllerMockData: webControllerMockData + } +}); \ No newline at end of file diff --git a/webroot/test/ui/js/co.test.unit.js b/webroot/test/ui/js/co.test.unit.js new file mode 100644 index 000000000..17d1d0fd1 --- /dev/null +++ b/webroot/test/ui/js/co.test.unit.js @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. + */ +define([ + 'jquery', + 'underscore', + 'co-test-utils', + 'co-test-constants' +], function ($, _, cotu, cotc) { + + var defaultTestSuiteConfig = { + class: '', + groups: [], + severity: cotc.SEVERITY_LOW + }; + + var createTestSuiteConfig = function (testClass, groups, severity) { + severity = ifNull(severity, cotc.SEVERITY_LOW); + groups = ifNull(groups, ['all']); + return $.extend({}, defaultTestSuiteConfig, {class: testClass, groups: groups, severity: severity}); + }; + + var createViewTestConfig = function (viewId, testSuiteConfig, mokDataConfig) { + var viewTestConfig = {}; + viewTestConfig.viewId = ifNull(viewId, ""); + viewTestConfig.testSuites = []; + if (testSuiteConfig != null) { + _.each(testSuiteConfig, function (suiteConfig) { + viewTestConfig.testSuites.push(suiteConfig); + }); + } + viewTestConfig.mockDataConfig = ifNull(mokDataConfig, {}); + + return viewTestConfig; + }; + + var defaultFakeServerConfig = { + options: { + autoRespondAfter: 100 + }, + responses: [], + getResponsesConfig: function () { + return []; + } + }; + + this.getDefaultFakeServerConfig = function () { + return defaultFakeServerConfig; + }; + + this.createFakeServerResponse = function (respObj) { + var defaultResponse = { + method: 'GET', + url: '/', + statusCode: 200, + headers: {"Content-Type": "application/json"}, + body: '' + }; + return $.extend({}, defaultResponse, respObj); + } + + var defaultPageConfig = { + hashParams: { + p: '' + }, + loadTimeout: 1000 + }; + + this.getDefaultPageConfig = function () { + return defaultPageConfig; + } + + var defaultPageTestConfig = { + moduleId: 'Set moduleId for your Test in pageTestConfig', + fakeServer: this.getDefaultFakeServerConfig(), + page: this.getDefaultPageConfig(), + getTestConfig: function () { + return {}; + } + }; + + this.createPageTestConfig = function (moduleId, fakeServerConfig, pageConfig, getTestConfigCB) { + var pageTestConfig = defaultPageTestConfig; + if (moduleId != null) { + pageTestConfig.moduleId = moduleId; + } + if (fakeServerConfig != null) { + pageTestConfig.fakeServer = $.extend({}, pageTestConfig.fakeServer, fakeServerConfig); + } + if (pageConfig != null) { + pageTestConfig.page = $.extend({}, pageTestConfig.page, pageConfig); + } + if (getTestConfigCB != null) { + pageTestConfig.getTestConfig = getTestConfigCB; + } + return pageTestConfig; + }; + + this.cTest = function (message, callback, severity) { + severity = ifNull(severity, cotc.SEVERITY_LOW); + return { + severity: severity, + test: function () { + return test(message, callback); + }, + type: cotc.TYPE_CONTRAIL_TEST + }; + }; + + var testGroup = function (name) { + this.name = ifNull(name, ''); + this.type = cotc.TYPE_CONTRAIL_TEST_GROUP; //set constant type. + this.tests = []; + + /** + * test is an object of CTest. + * @param test + */ + this.registerTest = function (testObj) { + if (testObj.type == cotc.TYPE_CONTRAIL_TEST) { + this.tests.push(testObj); + } else { + console.log("Test should be object of type CUnit.test"); + } + + } + + this.run = function (severity) { + _.each(this.tests, function (testObj) { + if (severity == cotc.SEVERITY_HIGH) { + if (testObj.severity == cotc.SEVERITY_HIGH) { + testObj.test(); + } + } else if (severity == cotc.SEVERITY_MEDIUM) { + if (testObj.severity == cotc.SEVERITY_HIGH || testObj.severity == cotc.SEVERITY_MEDIUM) { + testObj.test(); + } + } else if (severity == cotc.SEVERITY_LOW) { + testObj.test(); + } else { + } + }); + }; + }; + + this.createTestGroup = function (name) { + return new testGroup(name); + }; + + var testSuite = function (name) { + this.name = ifNull(name, ''); + this.groups = []; + this.type = cotc.TYPE_CONTRAIL_TEST_SUITE; //set constant type. + + this.createTestGroup = function (name) { + var group = new testGroup(name); + this.groups.push(group); + return group; + }; + + this.registerGroup = function (group) { + if (group.type == cotc.TYPE_CONTRAIL_TEST_GROUP) { + this.groups.push(group); + } else { + console.log("Group should be object of CUnit.testGroup.") + } + } + + this.run = function (groupNames, severity) { + var self = this; + _.each(groupNames, function (groupName) { + if (groupName == 'all') { + //run all the groups. + _.each(self.groups, function (group) { + group.run(severity); + }) + + } else { + //run only the group that matches name. + _.each(self.groups, function (group) { + if (group.name == groupName) { + group.run(severity); + } + }); + } + }); + } + } + + this.createTestSuite = function (name) { + return new testSuite(name); + } + + this.executeCommonTests = function (testConfigObj) { + _.each(testConfigObj, function (testConfig) { + + _.each(testConfig.suites, function (suiteConfig) { + if (contrail.checkIfExist(suiteConfig.class)) { + suiteConfig.class(testConfig.viewObj, suiteConfig); + } + }); + }); + }; + + this.executeLibTests = function (testConfig) { + _.each(testConfig.suites, function(suiteConfig) { + if (contrail.checkIfExist(suiteConfig.class)) { + suiteConfig.class(suiteConfig); + } + }); + } + + /** + * moduleId + * fakeServer.options {} + * fakeServer.responses + * page.hashParams + * page.loadTimeout + * rootView + * testConfig.getTestConfig() + * @param PageTestConfig + */ + this.startCommonTestRunner = function (pageTestConfig) { + var self = this, + fakeServer; + + module(pageTestConfig.moduleId, { + setup: function () { + fakeServer = cotu.getFakeServer(pageTestConfig.fakeServer.options); + _.each(pageTestConfig.fakeServer.responses, function (response) { + fakeServer.respondWith(response.method, response.url, [response.statusCode, response.headers, response.data]); + }); + + $.ajaxSetup({ + cache: true + }); + }, + teardown: function () { + fakeServer.restore(); + delete fakeServer; + } + }); + + asyncTest("Core Tests", function (assert) { + expect(0); + var loadingStartedDefObj = loadFeature(pageTestConfig.page.hashParams); + loadingStartedDefObj.done(function () { + //additional fake server response setup + var responses = pageTestConfig.fakeServer.getResponsesConfig(); + _.each(responses, function (response) { + fakeServer.respondWith(response.method, response.url, [response.statusCode, response.headers, response.body]); + }); + + var pageLoadTimeOut = pageTestConfig.page.loadTimeout; + + setTimeout(function () { + var testConfig = pageTestConfig.getTestConfig(); + var mockDataDefObj = $.Deferred(); + + cotu.setViewObjAndViewConfig4All(testConfig.rootView, testConfig.tests); + + //create and update mock data in test config + cotu.createMockData(testConfig.rootView, testConfig.tests, mockDataDefObj); + + $.when(mockDataDefObj).done(function () { + self.executeCommonTests(testConfig.tests); + QUnit.start(); + }); + + }, pageLoadTimeOut); + }); + }); + + }; + + this.startLibTestRunner = function(libTestConfig) { + var self = this; + asyncTest("Start Library Tests - " + ifNull(libTestConfig.libName, ""), function (assert) { + expect(0); + libTestConfig.testInitFn(); + setTimeout(function() { + self.executeLibTests(libTestConfig); + QUnit.start(); + }, 1000); + + }); + }; + + return { + getDefaultFakeServerConfig: getDefaultFakeServerConfig, + createFakeServerResponse: createFakeServerResponse, + getDefaultPageConfig: getDefaultPageConfig, + createTestSuiteConfig: createTestSuiteConfig, + createViewTestConfig: createViewTestConfig, + createPageTestConfig: createPageTestConfig, + executeCommonTests: executeCommonTests, + executeLibTests: executeLibTests, + test: cTest, + createTestGroup: createTestGroup, + createTestSuite: createTestSuite, + startTestRunner: startCommonTestRunner, + startCommonTestRunner : startCommonTestRunner, + startLibTestRunner: startLibTestRunner + }; +}); diff --git a/webroot/test/ui/js/grid/ContrailListModel.lib.test.suite.js b/webroot/test/ui/js/grid/ContrailListModel.lib.test.suite.js new file mode 100644 index 000000000..d13af2d0a --- /dev/null +++ b/webroot/test/ui/js/grid/ContrailListModel.lib.test.suite.js @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. + */ + +define([ + 'co-test-utils', + 'co-test-messages', + 'co-test-constants', + 'co-test-unit', +], function (cotu, cotm, cotc, CUnit) { + + //TODO update test groups and test cases. + + var libTestSuiteClass = function (suiteConfig) { + var mockData = ifNull(suiteConfig.mockData, []), + gridListModel = new Slick.Data.DataView, + dataParsers; + + if (contrail.checkIfExist(suiteConfig.modelConfig)) { + dataParsers = suiteConfig.modelConfig.dataParsers; + } + + module(cotu.formatTestModuleMessage(cotm.TEST_SLICKGRID_LISTMODEL, "GridView-Lib")); + + var gridListModelTestSuite = CUnit.createTestSuite('GridListModelTest'); + + var basicTestGroup = gridListModelTestSuite.createTestGroup('basic'); + + basicTestGroup.registerTest(CUnit.test(cotm.SLICKGRID_LISTMODEL_INITIAL_SETUP, function () { + if (mockData == null) { + assertEmpty(gridListModel); + } else { + assertEqual(gridListModel, mockData, dataParsers); + } + + }, cotc.SEVERITY_HIGH)); + + basicTestGroup.registerTest(CUnit.test(cotm.SLICKGRID_LISTMODEL_REFRESH, function () { + gridListModel.refresh(); + if (mockData == null) { + assertEmpty(gridListModel); + } else { + assertEqual(gridListModel, mockData, dataParsers); + } + }, cotc.SEVERITY_HIGH)); + + + gridListModelTestSuite.run(suiteConfig.groups, suiteConfig.severity); + }; + + function assertEmpty(gridListModel) { + expect(6); + deepEqual(0, gridListModel.getLength(), "rows is initialized to an empty array"); + deepEqual(gridListModel.getItems().length, 0, "getItems().length"); + deepEqual(undefined, gridListModel.getIdxById("id_0"), "getIdxById should return undefined if not found"); + deepEqual(undefined, gridListModel.getRowById("id_0"), "getRowById should return undefined if not found"); + deepEqual(undefined, gridListModel.getItemById("id_0"), "getItemById should return undefined if not found"); + deepEqual(undefined, gridListModel.getItemByIdx(0), "getItemByIdx should return undefined if not found"); + } + + function assertEqual(gridListModel, mockData, dataParsers) { + var gridListModelItems = gridListModel.getItems(); + if (dataParsers != null) { + if (contrail.checkIfExist(dataParsers.gridDataParseFn)) { + gridListModelItems = dataParsers.gridDataParseFn(gridListModelItems); + } + } + expect(6); + notDeepEqual(0, gridListModel.getLength(), "rows is initialized to an non-empty array"); + deepEqual(gridListModelItems.length, mockData.length, "getItems().length should equal with mockData.length"); + notDeepEqual(undefined, gridListModel.getIdxById("id_0"), "getIdxById should not be undefined"); + notDeepEqual(undefined, gridListModel.getRowById("id_0"), "getRowById should not be undefined"); + notDeepEqual(undefined, gridListModel.getItemById("id_0"), "getItemById should not be undefined"); + deepEqual(mockData[0], gridListModelItems[0], "getItemByIdx[0] (listmodel first item) should equal to mockData[0]"); + } + + return libTestSuiteClass; + +}); diff --git a/webroot/test/ui/js/grid/listmodel.test.js b/webroot/test/ui/js/grid/ContrailListModel.test.suite.js similarity index 99% rename from webroot/test/ui/js/grid/listmodel.test.js rename to webroot/test/ui/js/grid/ContrailListModel.test.suite.js index ce1d175a5..d38c60a8e 100644 --- a/webroot/test/ui/js/grid/listmodel.test.js +++ b/webroot/test/ui/js/grid/ContrailListModel.test.suite.js @@ -5,7 +5,7 @@ define([ 'co-test-utils', 'co-test-messages', - 'co-unit-test', + 'co-test-unit', ], function (cotu, cotm, CUnit) { var testSuiteClass = function (viewObj, suiteConfig) { diff --git a/webroot/test/ui/js/grid/GridView.lib.test.js b/webroot/test/ui/js/grid/GridView.lib.test.js new file mode 100644 index 000000000..a9eb15250 --- /dev/null +++ b/webroot/test/ui/js/grid/GridView.lib.test.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. + */ +define([ + 'co-test-constants', + 'co-grid-contrail-list-model-lib-test-suite', + 'co-grid-view-lib-test-suite', + 'co-test-unit' +], function (cotc, ContrailListModelLibTestSuite, GridViewLibTestSuite, CUnit) { + + var libTestConfig = { + libName: "GridView", + testInitFn : function() { + same = QUnit.deepEqual; + $('#content-container').append('
'); + }, + suites: [ + { + class: ContrailListModelLibTestSuite, + group: ['all'], + severity: cotc.SEVERITY_LOW + } + ] + }; + + CUnit.startLibTestRunner(libTestConfig); + +}); \ No newline at end of file diff --git a/webroot/test/ui/js/grid/GridView.lib.test.suite.js b/webroot/test/ui/js/grid/GridView.lib.test.suite.js new file mode 100644 index 000000000..f28027fac --- /dev/null +++ b/webroot/test/ui/js/grid/GridView.lib.test.suite.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. + */ + +define([ + 'underscore', + 'co-test-utils', + 'co-test-messages', + 'co-test-constants', + 'co-test-unit' +], function (_, cotu, cotm, cotc, CUnit) { + + var libTestSuiteClass = function (suiteConfig){ + + var gridViewTestSuite = CUnit.createTestSuite('LibGridViewTest'); + + //TODO add test groups and test cases + + + gridViewTestSuite.run(suiteConfig.groups, suiteConfig.severity); + + }; + + return libTestSuiteClass; +}); \ No newline at end of file diff --git a/webroot/test/ui/js/grid/gridview.test.js b/webroot/test/ui/js/grid/GridView.test.suite.js similarity index 99% rename from webroot/test/ui/js/grid/gridview.test.js rename to webroot/test/ui/js/grid/GridView.test.suite.js index fca878962..de3edfa74 100644 --- a/webroot/test/ui/js/grid/gridview.test.js +++ b/webroot/test/ui/js/grid/GridView.test.suite.js @@ -7,7 +7,7 @@ define([ 'co-test-utils', 'co-test-messages', 'co-test-constants', - 'co-unit-test' + 'co-test-unit' ], function (_, cotu, cotm, cotc, CUnit) { var testSuiteClass = function (viewObj, suiteConfig){ diff --git a/webroot/test/ui/karma.config.js b/webroot/test/ui/karma.config.js new file mode 100644 index 000000000..ebb91f783 --- /dev/null +++ b/webroot/test/ui/karma.config.js @@ -0,0 +1,63 @@ +/*/* + * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. + */ +module.exports = function (config) { + config.set({ + basePath: __dirname + '/../../../..', + autoWatch: false, + frameworks: ['qunit', 'sinon', 'requirejs'], + plugins: [ + 'karma-phantomjs-launcher', + 'karma-coverage', + 'karma-qunit', + 'karma-sinon', + 'karma-htmlfile-reporter', + //'karma-html-reporter', + 'karma-requirejs', + 'karma-junit-reporter', + 'karma-html2js-preprocessor', + 'karma-firefox-launcher', + 'karma-chrome-launcher', + ], + browsers: [ + 'PhantomJS', + //'PhantomJS_custom', + //'Firefox', + //'Chrome' + ], + customLaunchers: { + 'PhantomJS_custom': { + base: 'PhantomJS', + options: { + viewportSize: { + width: 1280, + height: 1024 + } + } + } + }, + + //port: 8143, + + reporters: ['progress', 'html', 'coverage', 'junit'], + // the default configuration + junitReporter: { + outputFile: __dirname + '/reports/test-results.xml', + suite: '' + }, + preprocessors: { + '*.view': ['html2js'], + '*.tmpl': ['html2js'] + }, + htmlReporter: { + outputFile: __dirname + '/reports/test-results.html' + }, + coverageReporter: { + type : 'html', + dir : __dirname + '/reports/coverage/' + }, + singleRun: false, + colors: true + }); +}; +