diff --git a/frontend/tests/tests/test_analytics.js b/frontend/tests/tests/test_analytics.js index cfca6070b..947bf9b47 100644 --- a/frontend/tests/tests/test_analytics.js +++ b/frontend/tests/tests/test_analytics.js @@ -1,10 +1,5 @@ var gamodule = require("gamodule"); -window.apidata = { - base_url: "/", - prefix: "/" -}; - QUnit.module("Google Analytics"); QUnit.test("test without analytics", function (assert) { var result=[]; diff --git a/frontend/tests/tests/user/mock_jsapi.js b/frontend/tests/tests/user/mock_jsapi.js index baa23da3f..d84d81d50 100644 --- a/frontend/tests/tests/user/mock_jsapi.js +++ b/frontend/tests/tests/user/mock_jsapi.js @@ -8,7 +8,7 @@ module.exports = { name: "app1", ui_name: "Application 1", icon_128: "", - description: "description", + description: "This is obviously application 1", policy: { allow_home: true, volume_source: "", @@ -33,8 +33,26 @@ module.exports = { volume_mode: "" }, configurables: [] + }, + container: { + url_id: "654321" } - } + }, + "51993": { + image: { + name: "app3", + ui_name: "Application 3", + icon_128: "", + description: "This is application 3", + policy: { + allow_home: false, + volume_source: "foo", + volume_target: "bar", + volume_mode: "baz" + }, + configurables: [] + } + }, }, create: function() { }, diff --git a/frontend/tests/tests/user/test_application_label.js b/frontend/tests/tests/user/test_application_label.js index fe8857e7d..a23d3e38c 100644 --- a/frontend/tests/tests/user/test_application_label.js +++ b/frontend/tests/tests/user/test_application_label.js @@ -1,106 +1,89 @@ -var Vue = require("vuejs"); -var ApplicationListModel = require("user/ApplicationListModel"); -var ApplicationLabel = require("user/vue-components/ApplicationLabel"); +let Vue = require("vuejs"); +let ApplicationListModel = require("user/ApplicationListModel"); +let ApplicationLabel = require("user/vue-components/ApplicationLabel"); require("filters"); -QUnit.module("user.app_label"); -QUnit.test("application name", function(assert) { - var done = assert.async(); - - var model = new ApplicationListModel(); - var appLabel = new ApplicationLabel({ - data: function() { return { model: model }; } - }).$mount(); - - model.update().done(function() { - Vue.nextTick(function() { - assert.equal( - appLabel.$el.querySelector('li > a > span').innerHTML, - model.appList[0].appData.image.ui_name - ); - - // Simulate changing currentApp - model.selectedIndex = 1; - - Vue.nextTick(function() { - assert.equal( - appLabel.$el.querySelector('li > a > span').innerHTML, - model.appList[1].appData.image.ui_name - ); - - done(); - }); +let model, appLabel; + +QUnit.module("user.app_label", { + beforeEach: function(assert) { + let done = assert.async(); + + model = new ApplicationListModel(); + appLabel = new ApplicationLabel({ + data: function() { return { model: model }; } + }).$mount(); + + model.update().done(function() { + Vue.nextTick(function() {done();}); }); + } +}); + +QUnit.test("application name", function(assert) { + let done = assert.async(); + + assert.equal( + appLabel.$el.querySelector('li > a > span').innerHTML, + model.appList[0].appData.image.ui_name + ); + + // Simulate changing currentApp + model.selectedIndex = 1; + + Vue.nextTick(function() { + assert.equal( + appLabel.$el.querySelector('li > a > span').innerHTML, + model.appList[1].appData.image.ui_name + ); + + done(); }); }); QUnit.test("rendering stop button", function (assert) { - var done = assert.async(); - - var model = new ApplicationListModel(); - var appLabel = new ApplicationLabel({ - data: function() { return { model: model }; } - }).$mount(); - - model.update().done(function() { - // Simulate application stopped - model.appList[0].status = 'STOPPED'; - - Vue.nextTick(function() { - assert.equal( - appLabel.$el.querySelector('li > a > span').innerHTML, - model.appList[0].appData.image.ui_name - ); - - // Test stop button disabled - assert.ok( - appLabel.$el.querySelector('#stop-button').classList.contains('disabled') - ); - - // Simulate application running - model.appList[0].status = 'RUNNING'; - - // Test stop button enabled - Vue.nextTick(function() { - assert.notOk( - appLabel.$el.querySelector('#stop-button').classList.contains('disabled') - ); - - done(); - }); - }); + let done = assert.async(); + + assert.equal( + appLabel.$el.querySelector('li > a > span').innerHTML, + model.appList[0].appData.image.ui_name + ); + + // Test stop button disabled + assert.ok( + appLabel.$el.querySelector('#stop-button').classList.contains('disabled') + ); + + // Select running application + model.selectedIndex = 1; + + // Test stop button enabled + Vue.nextTick(function() { + assert.notOk( + appLabel.$el.querySelector('#stop-button').classList.contains('disabled') + ); + + done(); }); }); QUnit.test("rendering share button", function (assert) { - var done = assert.async(); - - var model = new ApplicationListModel(); - var appLabel = new ApplicationLabel({ - data: function() { return { model: model }; } - }).$mount(); - - model.update().done(function() { - // Simulate application stopped - model.appList[0].status = 'STOPPED'; - - Vue.nextTick(function() { - // Test share button disabled - assert.ok( - appLabel.$el.querySelector('#share-button').classList.contains('disabled') - ); - - // Simulate application running - model.appList[0].status = 'RUNNING'; - - // Test share button disabled (Because clipboard save is not supported in test environment) - Vue.nextTick(function() { - assert.ok( - appLabel.$el.querySelector('#share-button').classList.contains('disabled') - ); - - done(); - }); - }); + let done = assert.async(); + + // Test share button disabled + assert.ok( + appLabel.$el.querySelector('#share-button').classList.contains('disabled') + ); + + // Select running application + model.selectedIndex = 1; + + // Test share button disabled (Because clipboard save is not supported in test environment) + Vue.nextTick(function() { + assert.ok( + appLabel.$el.querySelector('#share-button').classList.contains('disabled') + ); + + done(); }); }); diff --git a/frontend/tests/tests/user/test_application_list_view.js b/frontend/tests/tests/user/test_application_list_view.js index 5b746ac2f..e78b0fa69 100644 --- a/frontend/tests/tests/user/test_application_list_view.js +++ b/frontend/tests/tests/user/test_application_list_view.js @@ -1,16 +1,21 @@ -var Vue = require("vuejs"); -var ApplicationListModel = require("user/ApplicationListModel"); -var ApplicationListView = require("user/vue-components/ApplicationListView"); +let Vue = require("vuejs"); +let ApplicationListModel = require("user/ApplicationListModel"); +let ApplicationListView = require("user/vue-components/ApplicationListView"); require("filters"); -QUnit.module("user.app_list_view"); -QUnit.test("rendering list", function (assert) { - var done = assert.async(); +let model, appListView; + +QUnit.module("user.app_list_view", { + beforeEach: function() { + model = new ApplicationListModel(); + appListView = new ApplicationListView({ + data: function() { return { model: model }; } + }).$mount(); + } +}); - var model = new ApplicationListModel(); - var appListView = new ApplicationListView({ - data: function() { return { model: model }; } - }).$mount(); +QUnit.test("rendering list", function (assert) { + let done = assert.async(); assert.ok(model.loading); assert.equal( @@ -37,12 +42,7 @@ QUnit.test("rendering list", function (assert) { }); QUnit.test("rendering nothing in the list", function (assert) { - var done = assert.async(); - - var model = new ApplicationListModel(); - var appListView = new ApplicationListView({ - data: function() { return { model: model }; } - }).$mount(); + let done = assert.async(); model.loading = false; @@ -65,12 +65,7 @@ QUnit.test("rendering nothing in the list", function (assert) { }); QUnit.test("search form", function (assert) { - var done = assert.async(); - - var model = new ApplicationListModel(); - var appListView = new ApplicationListView({ - data: function() { return { model: model }; } - }).$mount(); + let done = assert.async(); model.update().done(function() { Vue.nextTick(function() { assert.notEqual(appListView.visibleList.length, 0); diff --git a/frontend/tests/tests/user/test_application_view.js b/frontend/tests/tests/user/test_application_view.js index 0a763405f..93fded0b1 100644 --- a/frontend/tests/tests/user/test_application_view.js +++ b/frontend/tests/tests/user/test_application_view.js @@ -1,70 +1,181 @@ -var Vue = require("vuejs"); -var ApplicationListModel = require("user/ApplicationListModel"); -var ApplicationView = require("user/vue-components/ApplicationView"); +let Vue = require("vuejs"); +let ApplicationListModel = require("user/ApplicationListModel"); +let ApplicationView = require("user/vue-components/ApplicationView"); require("filters"); -QUnit.module("user.app_view"); -QUnit.test("rendering form", function (assert) { - var done = assert.async(); +let model, appView; - var model = new ApplicationListModel(); - var appView = new ApplicationView({ - data: function() { return { model: model }; } - }).$mount(); +QUnit.module("user.app_view", { + beforeEach: function(assert) { + let done = assert.async(); - model.update().done(function() { Vue.nextTick(function() { - assert.equal(appView.$el.children[0].tagName, 'DIV'); - assert.ok(appView.$el.children[0].classList.contains('row')); + model = new ApplicationListModel(); + appView = new ApplicationView({ + data: function() { return { model: model }; } + }).$mount(); + model.update().done(function() { + Vue.nextTick(function() {done();}); + }); + } +}); + +QUnit.test("rendering title and description", function (assert) { + let done = assert.async(); + assert.equal(appView.$el.children[0].tagName, 'DIV'); + assert.ok(appView.$el.children[0].classList.contains('row')); + + assert.equal( + appView.$el.querySelector('.box-title').innerHTML, + model.appList[0].appData.image.ui_name + ); + + assert.equal( + appView.$el.querySelector('#app-description').innerHTML, + model.appList[0].appData.image.description + ); + + // Select other application + model.selectedIndex = 2; + + Vue.nextTick(function() { assert.equal( appView.$el.querySelector('.box-title').innerHTML, - model.appList[0].appData.image.ui_name + model.appList[2].appData.image.ui_name ); - // Simulate application starting - model.appList[0].status = 'STARTING'; + assert.equal( + appView.$el.querySelector('#app-description').innerHTML, + model.appList[2].appData.image.description + ); + + done(); + }); +}); + +QUnit.test("rendering policy", function (assert) { + let done = assert.async(); + + assert.equal( + appView.$el.querySelector('.policy').children[0].innerHTML.trim(), + 'Workspace accessible' + ); + + assert.equal( + appView.$el.querySelector('.policy').children[1].innerHTML.trim(), + 'No volumes mounted' + ); + // Select other application + model.selectedIndex = 2; + + Vue.nextTick(function() { assert.equal( - appView.$el.querySelector('.box-title').innerHTML, - model.appList[0].appData.image.ui_name + appView.$el.querySelector('.policy').children[0].innerHTML.trim(), + 'Workspace not accessible' ); + + assert.notEqual( + appView.$el.querySelector('.policy').children[1].innerHTML.indexOf('Volume mounted: foo'), + -1 + ); + + assert.notEqual( + appView.$el.querySelector('.policy').children[1].innerHTML.indexOf(' bar (baz)'), + -1 + ); + + done(); + }); +}); + +QUnit.test("rendering configurables", function (assert) { + let done = assert.async(); + + assert.notEqual( + appView.$el.querySelector('.configuration').children[0].innerHTML.trim(), + 'No configurable options for this image' + ); + + // Select other application + model.selectedIndex = 2; + + Vue.nextTick(function() { assert.equal( - appView.$el.querySelector('#app-description').innerHTML, - model.appList[0].appData.image.description + appView.$el.querySelector('.configuration').children[0].innerHTML.trim(), + 'No configurable options for this image' ); done(); - });}); + }); }); -QUnit.test("rendering iframe", function (assert) { - var done = assert.async(); +QUnit.test("rendering start button", function (assert) { + let done = assert.async(); + + assert.equal( + appView.$el.querySelector('.start-button').innerHTML.trim(), + 'Start' + ); + + assert.notOk( + appView.$el.querySelector('.start-button').disabled + ); - var model = new ApplicationListModel(); - var appView = new ApplicationView({ - data: function() { return { model: model }; } - }).$mount(); + assert.notOk( + appView.$el.querySelector('.configuration > fieldset').disabled + ); - model.update().done(function() { - // Simulate application running - model.appList[0].status = 'RUNNING'; - model.appList[0].appData.container = {}; - model.appList[0].appData.container.url_id = 'https://127.0.0.1:1234/'; + // Simulate application starting + model.appList[0].status = 'STARTING'; + + Vue.nextTick(function() { + assert.equal( + appView.$el.querySelector('.start-button').innerHTML.trim(), + 'Starting' + ); + + assert.ok( + appView.$el.querySelector('.start-button').disabled + ); + + // Simulate application stopping + model.appList[0].status = 'STOPPING'; Vue.nextTick(function() { - assert.equal(appView.$el.children[0].tagName, 'IFRAME'); + assert.equal( + appView.$el.querySelector('.start-button').innerHTML.trim(), + 'Stopping' + ); + + assert.ok( + appView.$el.querySelector('.start-button').disabled + ); + + done(); + }); + }); +}); + +QUnit.test("rendering iframe", function (assert) { + let done = assert.async(); + // Switch to a running application + model.selectedIndex = 1; + + Vue.nextTick(function() { + assert.equal(appView.$el.children[0].tagName, 'IFRAME'); + assert.equal(appView.$el.children[0].getAttribute('src'), '/user/lambda/containers/654321/'); - // Render form again by selecting the other application which is stopped - model.selectedIndex = 1; + // Render form again by selecting the other application which is stopped + model.selectedIndex = 0; - Vue.nextTick(function() { - assert.equal( - appView.$el.querySelector('.box-title').innerHTML, - model.appList[1].appData.image.ui_name - ); + Vue.nextTick(function() { + assert.equal( + appView.$el.querySelector('.box-title').innerHTML, + model.appList[0].appData.image.ui_name + ); - done(); - }); + done(); }); }); }); diff --git a/frontend/tests/tests/user/test_models.js b/frontend/tests/tests/user/test_models.js index 175daf577..2dfa076cc 100644 --- a/frontend/tests/tests/user/test_models.js +++ b/frontend/tests/tests/user/test_models.js @@ -8,7 +8,7 @@ QUnit.test("instantiation", function (assert) { assert.equal(model.selectedIndex, null); model.update().done(function() { - assert.equal(model.appList.length, 2); + assert.equal(model.appList.length, 3); assert.equal(model.selectedIndex, 0); assert.equal(model.appList[0].appData.image.configurables[0], "resolution"); diff --git a/frontend/tests/testsuite.js b/frontend/tests/testsuite.js index 99a8c716b..db8440526 100644 --- a/frontend/tests/testsuite.js +++ b/frontend/tests/testsuite.js @@ -1,3 +1,8 @@ +window.apidata = { + base_url: "/user/lambda", + prefix: "/" +}; + require("./tests/user/test_configurables.js"); require("./tests/user/test_models.js"); require("./tests/user/test_application_list_view.js"); diff --git a/frontend/user/vue-components/ApplicationView.vue b/frontend/user/vue-components/ApplicationView.vue index 8ce369efe..8dcba6645 100644 --- a/frontend/user/vue-components/ApplicationView.vue +++ b/frontend/user/vue-components/ApplicationView.vue @@ -38,7 +38,7 @@