diff --git a/testing/wicket-js-tests/Gruntfile.js b/testing/wicket-js-tests/Gruntfile.js index db599c74b7..1a6893b9da 100644 --- a/testing/wicket-js-tests/Gruntfile.js +++ b/testing/wicket-js-tests/Gruntfile.js @@ -47,6 +47,10 @@ module.exports = function(grunt) { "../../wicket-core/src/test/js/event.js", "../../wicket-core/src/test/js/timer.js" ], + extensionsTestsJs = [ + "../../wicket-extensions/src/test/js/palette-test.js", + "../../wicket-extensions/src/test/js/trapfocus-test.js" + ], gymTestsJs = [ "../../wicket-examples/src/main/webapp/js-test/tests/ajax/form.js", "../../wicket-examples/src/main/webapp/js-test/tests/bean-validation/birthdate.js", @@ -74,6 +78,7 @@ module.exports = function(grunt) { extensions: extensionsJs, nativeWebSocket: nativeWebSocketJs, testsJs: testsJs, + extensionsTestsJs: extensionsTestsJs, gymTestsJs: gymTestsJs, grunt: gruntJs, @@ -108,7 +113,9 @@ module.exports = function(grunt) { all: { options: { urls: [ - 'http://localhost:38887/test/js/all.html?4.0.0' + 'http://localhost:38887/test/js/all.html?4.0.0', + 'http://localhost:38888/wicket-extensions/src/test/js/palette.html?4.0.0', + 'http://localhost:38888/wicket-extensions/src/test/js/trap-focus.html?4.0.0' ], puppeteer: { headless: true, @@ -124,7 +131,9 @@ module.exports = function(grunt) { vanilla: { options: { urls: [ - 'http://localhost:38887/test/js/all.html?vanilla' + 'http://localhost:38887/test/js/all.html?vanilla', + 'http://localhost:38888/wicket-extensions/src/test/js/palette.html?vanilla', + 'http://localhost:38888/wicket-extensions/src/test/js/trap-focus.html?vanilla' ], puppeteer: { headless: true, @@ -152,6 +161,15 @@ module.exports = function(grunt) { }, base: '../../wicket-core/src' } + }, + // serves wicket-extensions' own JavaScript and its QUnit tests; a separate + // target because they live outside the wicket-core/src root above + extensions: { + options: { + port: 38888, + debug: true, + base: '../..' + } } } }); diff --git a/wicket-extensions/src/test/js/palette-test.js b/wicket-extensions/src/test/js/palette-test.js new file mode 100644 index 0000000000..2216658382 --- /dev/null +++ b/wicket-extensions/src/test/js/palette-test.js @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*global QUnit: true */ + +Wicket.Event.add(window, 'domready', function() { + "use strict"; + + const { module, test } = QUnit; + + function selectionOptionValues() { + var selection = document.getElementById('paletteSelection'); + return Array.prototype.map.call(selection.options, function(option) { + return option.value; + }); + } + + function selectOnly(selection, value) { + Array.prototype.forEach.call(selection.options, function(option) { + option.selected = (option.value === value); + }); + } + + module("Wicket.Palette", { + beforeEach: function() { + var selection = document.getElementById('paletteSelection'); + selection.innerHTML = + '' + + '' + + ''; + document.getElementById('paletteRecorder').value = '1,2,3'; + } + }); + + test("moveUp reorders the selected option without throwing", assert => { + var selection = document.getElementById('paletteSelection'); + selectOnly(selection, '3'); + + Wicket.Palette.moveUp('paletteChoices', 'paletteSelection', 'paletteRecorder'); + + assert.deepEqual(selectionOptionValues(), ['1', '3', '2'], + "moveUp did not move the selected option in front of its predecessor"); + }); + + test("moveUp updates the hidden recorder input", assert => { + var selection = document.getElementById('paletteSelection'); + selectOnly(selection, '3'); + + Wicket.Palette.moveUp('paletteChoices', 'paletteSelection', 'paletteRecorder'); + + assert.equal(document.getElementById('paletteRecorder').value, '1,3,2', + "the recorder was not updated, so the server never sees the new order"); + }); + + test("moveUp on the first option is a no-op and does not throw", assert => { + var selection = document.getElementById('paletteSelection'); + selectOnly(selection, '1'); + + Wicket.Palette.moveUp('paletteChoices', 'paletteSelection', 'paletteRecorder'); + + assert.deepEqual(selectionOptionValues(), ['1', '2', '3'], + "the order should not have changed"); + }); + + test("moveDown reorders the selected option without throwing", assert => { + var selection = document.getElementById('paletteSelection'); + selectOnly(selection, '1'); + + Wicket.Palette.moveDown('paletteChoices', 'paletteSelection', 'paletteRecorder'); + + assert.deepEqual(selectionOptionValues(), ['2', '1', '3'], + "moveDown did not move the selected option behind its successor"); + }); +}); diff --git a/wicket-extensions/src/test/js/palette.html b/wicket-extensions/src/test/js/palette.html new file mode 100644 index 0000000000..606c56358e --- /dev/null +++ b/wicket-extensions/src/test/js/palette.html @@ -0,0 +1,67 @@ + + + + +
+