-
Notifications
You must be signed in to change notification settings - Fork 415
Add regression tests for Wicket.Palette and Wicket.trapFocus focus handling #1621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
reiern70
wants to merge
2
commits into
master
Choose a base branch
from
reiern70/issue-1618-master-palette-trapfocus-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 = | ||
| '<option value="1">one</option>' + | ||
| '<option value="2">two</option>' + | ||
| '<option value="3">three</option>'; | ||
| 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"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <html> | ||
|
|
||
| <head> | ||
| <title id="titleId">Wicket.Palette JavaScript tests</title> | ||
| <meta http-equiv="content-type" content="text/html; charset=UTF-8"> | ||
| <link rel="stylesheet" href="/wicket-core/src/test/js/qunit/qunit.css" type="text/css" media="screen" /> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="qunit"></div> | ||
|
|
||
| <div id="qunit-fixture"> | ||
| <select id="paletteChoices" multiple="multiple"> | ||
| <option value="4">four</option> | ||
| </select> | ||
| <select id="paletteSelection" multiple="multiple"> | ||
| <option value="1">one</option> | ||
| <option value="2">two</option> | ||
| <option value="3">three</option> | ||
| </select> | ||
| <input type="hidden" id="paletteRecorder" value="1,2,3"/> | ||
| </div> | ||
|
|
||
| <script> | ||
| // version lies between question mark and first ampersand (or end). | ||
| // 'vanilla' (palette.html?vanilla) selects the jQuery-free wicket-ajax.js | ||
| // engine instead of the default JQuery + wicket-ajax-jquery.js combination | ||
| // (palette.html?4.0.0, palette.html?3.7.1, ...). | ||
| var version = location.search.match(/\?(.*?)(&|$)/)[1]; | ||
| var useVanilla = (version === 'vanilla'); | ||
|
|
||
| if (!useVanilla) { | ||
| document.write("<scr"+"ipt src='/wicket-core/src/main/java/org/apache/wicket/resource/jquery/jquery-"+version+".js'></scr"+"ipt>"); | ||
| } | ||
| </script> | ||
| <script> | ||
| if (!useVanilla) { | ||
| document.write("<scr"+"ipt src='/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js'></scr"+"ipt>"); | ||
| } else { | ||
| document.write("<scr"+"ipt src='/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax.js'></scr"+"ipt>"); | ||
| } | ||
| </script> | ||
| <script type="text/javascript" src="/wicket-core/src/test/js/qunit/qunit.js"></script> | ||
|
|
||
| <!-- the module under test --> | ||
| <script type="text/javascript" src="/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js"></script> | ||
|
|
||
| <script type="text/javascript" src="palette-test.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <html> | ||
|
|
||
| <head> | ||
| <title id="titleId">Wicket.trapFocus JavaScript tests</title> | ||
| <meta http-equiv="content-type" content="text/html; charset=UTF-8"> | ||
| <link rel="stylesheet" href="/wicket-core/src/test/js/qunit/qunit.css" type="text/css" media="screen" /> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="qunit"></div> | ||
|
|
||
| <div id="qunit-fixture"> | ||
| <div id="trapFocusContainer"> | ||
| <a id="trapFocusFirst" href="#first">first</a> | ||
| <a id="trapFocusLast" href="#last">last</a> | ||
| </div> | ||
| </div> | ||
|
|
||
| <script> | ||
| // version lies between question mark and first ampersand (or end). | ||
| // 'vanilla' (trap-focus.html?vanilla) selects the jQuery-free wicket-ajax.js | ||
| // engine instead of the default JQuery + wicket-ajax-jquery.js combination | ||
| // (trap-focus.html?4.0.0, trap-focus.html?3.7.1, ...). | ||
| var version = location.search.match(/\?(.*?)(&|$)/)[1]; | ||
| var useVanilla = (version === 'vanilla'); | ||
|
|
||
| if (!useVanilla) { | ||
| document.write("<scr"+"ipt src='/wicket-core/src/main/java/org/apache/wicket/resource/jquery/jquery-"+version+".js'></scr"+"ipt>"); | ||
| } | ||
| </script> | ||
| <script> | ||
| if (!useVanilla) { | ||
| document.write("<scr"+"ipt src='/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js'></scr"+"ipt>"); | ||
| } else { | ||
| document.write("<scr"+"ipt src='/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax.js'></scr"+"ipt>"); | ||
| } | ||
| </script> | ||
| <script type="text/javascript" src="/wicket-core/src/test/js/qunit/qunit.js"></script> | ||
|
|
||
| <!-- the module under test --> | ||
| <script type="text/javascript" src="/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/trap-focus.js"></script> | ||
|
|
||
| <script type="text/javascript" src="trapfocus-test.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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, KeyboardEvent: true */ | ||
|
|
||
| Wicket.Event.add(window, 'domready', function() { | ||
| "use strict"; | ||
|
|
||
| const { module, test } = QUnit; | ||
|
|
||
| const TAB_KEYCODE = 9; | ||
|
|
||
| function tab(target, shiftKey) { | ||
| target.dispatchEvent(new KeyboardEvent('keydown', { | ||
| key: 'Tab', | ||
| code: 'Tab', | ||
| keyCode: TAB_KEYCODE, | ||
| which: TAB_KEYCODE, | ||
| shiftKey: !!shiftKey, | ||
| bubbles: true, | ||
| cancelable: true | ||
| })); | ||
| } | ||
|
|
||
| module("Wicket.trapFocus"); | ||
|
|
||
| test("Tab on the last focusable element wraps focus to the first, without throwing", assert => { | ||
| window.Wicket.trapFocus('trapFocusContainer', 'wicket-trap-focus-test'); | ||
|
|
||
| var first = document.getElementById('trapFocusFirst'); | ||
| var last = document.getElementById('trapFocusLast'); | ||
| last.focus(); | ||
|
|
||
| var threw = false; | ||
| try { | ||
| tab(last, false); | ||
| } catch (e) { | ||
| threw = true; | ||
| } | ||
|
|
||
| assert.notOk(threw, "tabbing past the last focusable element threw an exception"); | ||
| assert.equal(document.activeElement, first, | ||
| "focus did not wrap around to the first focusable element"); | ||
| }); | ||
|
|
||
| test("Shift+Tab on the first focusable element wraps focus to the last, without throwing", assert => { | ||
| window.Wicket.trapFocus('trapFocusContainer', 'wicket-trap-focus-test'); | ||
|
|
||
| var first = document.getElementById('trapFocusFirst'); | ||
| var last = document.getElementById('trapFocusLast'); | ||
| first.focus(); | ||
|
|
||
| var threw = false; | ||
| try { | ||
| tab(first, true); | ||
| } catch (e) { | ||
| threw = true; | ||
| } | ||
|
|
||
| assert.notOk(threw, "shift-tabbing past the first focusable element threw an exception"); | ||
| assert.equal(document.activeElement, last, | ||
| "focus did not wrap around to the last focusable element"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these versions need to be manually maintained?
Can it be automated somehow? :)