@@ -3,7 +3,10 @@ import { LogControllerTestCase } from "../../cases/log_controller_test_case"
33import { Schema , defaultSchema } from "../../../core/schema"
44import { Application } from "../../../core/application"
55
6- const customSchema = { ...defaultSchema , keyMappings : { ...defaultSchema . keyMappings , a : "a" , b : "b" } }
6+ const customSchema = {
7+ ...defaultSchema ,
8+ keyMappings : { ...defaultSchema . keyMappings , a : "a" , b : "b" } as { [ key : string ] : string } ,
9+ }
710
811export default class ActionKeyboardFilterTests extends LogControllerTestCase {
912 schema : Schema = customSchema
@@ -22,6 +25,7 @@ export default class ActionKeyboardFilterTests extends LogControllerTestCase {
2225 <button id="button8" data-action="keydown.a->a#log keydown.b->a#log2"></button>
2326 <button id="button9" data-action="keydown.shift+a->a#log keydown.a->a#log2 keydown.ctrl+shift+a->a#log3">
2427 <button id="button10" data-action="jquery.custom.event->a#log jquery.a->a#log2">
28+ <button id="button11" data-action="keydown.mod+s->a#log">
2529 </div>
2630 `
2731
@@ -177,7 +181,7 @@ export default class ActionKeyboardFilterTests extends LogControllerTestCase {
177181 this . assertActions ( { name : "log2" , identifier : "a" , eventType : "keydown" , currentTarget : button } )
178182 }
179183
180- async "test ignore event handlers associated with modifiers other than ctrol +shift+a" ( ) {
184+ async "test ignore event handlers associated with modifiers other than ctrl +shift+a" ( ) {
181185 const button = this . findElement ( "#button9" )
182186 await this . nextFrame
183187 await this . triggerKeyboardEvent ( button , "keydown" , { key : "A" , ctrlKey : true , shiftKey : true } )
@@ -197,4 +201,53 @@ export default class ActionKeyboardFilterTests extends LogControllerTestCase {
197201 await this . triggerEvent ( button , "jquery.a" )
198202 this . assertActions ( { name : "log2" , identifier : "a" , eventType : "jquery.a" , currentTarget : button } )
199203 }
204+
205+ async "test that the default schema keyMappings.mod value is based on the platform" ( ) {
206+ const expectedKeyMapping = navigator . platform ?. match ( / M a c | i P o d | i P h o n e | i P a d / ) ? "Meta" : "Control"
207+ this . assert . equal ( defaultSchema . keyMappings . mod , expectedKeyMapping )
208+ }
209+
210+ async "test ignore event handlers associated with modifiers mod+<key> (dynamic based on platform)" ( ) {
211+ const button = this . findElement ( "#button11" )
212+ await this . nextFrame
213+ await this . triggerKeyboardEvent ( button , "keydown" , { key : "s" , ctrlKey : true } )
214+ await this . triggerKeyboardEvent ( button , "keydown" , { key : "s" , metaKey : true } )
215+ // We should only see one event using `mod` (which is dynamic based on platform)
216+ this . assertActions ( { name : "log" , identifier : "a" , eventType : "keydown" , currentTarget : button } )
217+
218+ customSchema . keyMappings . mod = "Control" // set up for next test
219+ }
220+
221+ async "test ignore event handlers associated with modifiers mod+<key> (set to 'Control')" ( ) {
222+ // see .mod setting in previous test (mocking Windows)
223+ this . schema = {
224+ ...this . application . schema ,
225+ keyMappings : { ...this . application . schema . keyMappings , mod : "Control" } ,
226+ }
227+ const button = this . findElement ( "#button11" )
228+ await this . nextFrame
229+ await this . triggerKeyboardEvent ( button , "keydown" , { key : "s" , metaKey : true } )
230+ this . assertNoActions ( )
231+ await this . triggerKeyboardEvent ( button , "keydown" , { key : "s" , ctrlKey : true } )
232+ this . assertActions ( { name : "log" , identifier : "a" , eventType : "keydown" , currentTarget : button } )
233+
234+ customSchema . keyMappings . mod = "Meta" // set up for next test
235+ }
236+
237+ async "test ignore event handlers associated with modifiers mod+<key> (set to 'Meta')" ( ) {
238+ // see .mod setting in previous test (mocking Windows)
239+ this . schema = {
240+ ...this . application . schema ,
241+ keyMappings : { ...this . application . schema . keyMappings , mod : "Meta" } ,
242+ }
243+ const button = this . findElement ( "#button11" )
244+ await this . nextFrame
245+ await this . triggerKeyboardEvent ( button , "keydown" , { key : "s" , ctrlKey : true } )
246+ this . assertNoActions ( )
247+ await this . triggerKeyboardEvent ( button , "keydown" , { key : "s" , metaKey : true } )
248+ this . assertActions ( { name : "log" , identifier : "a" , eventType : "keydown" , currentTarget : button } )
249+
250+ // Reset to default for any subsequent tests
251+ this . schema = customSchema
252+ }
200253}
0 commit comments