Skip to content

Commit

Permalink
feat(actions): added sendKeys functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsHassler committed Oct 16, 2016
1 parent 465e6bb commit cedb7d0
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ PatternlabToNode.prototype.loadPatternConfig_ = function() {

PatternlabToNode.prototype.parseAction = function(pattern) {

const validActions = ['hover', 'focus'];
const validActions = ['hover', 'focus', 'sendKeys'];

/* istanbul ignore else */
if (pattern.actions &&
Expand All @@ -346,7 +346,17 @@ PatternlabToNode.prototype.parseAction = function(pattern) {
}
else if (action.action === 'focus') {
action.steps = '.focus(this.element)';
} else {
}
else if (action.action === 'sendKeys') {
if (!action.keys) {
throw new Error(
'PatternlabToNode - config error - ' +
pattern.id + ' is missing "keys" option required for sendKeys'
);
}
action.steps = '.sendKeys(this.element, \'' + action.keys + '\')';
}
else {
throw new Error(
'PatternlabToNode - config error - ' +
pattern.id + ' has unknown action identifier ' +
Expand Down
63 changes: 62 additions & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,17 @@ describe('main - ', () => {
it('should add correct steps for focus',
shouldAddCorrectStepsForFocus
);

describe('sendKeys - ', function() {

it('should fail if keys are missing',
shouldFailIfKeysAreMissing
);

it('should add correct steps for send keys',
shouldAddCorrectStepsForSendKeys
);
});
});

});
Expand Down Expand Up @@ -772,7 +783,33 @@ describe('main - ', () => {
}, (error) => {
asserts.assertEquals(
'wrong error message',
'PatternlabToNode - config error - pattern-1 has unknown action identifier "unknownAction", use ("hover", "focus")',
'PatternlabToNode - config error - pattern-1 has unknown action identifier "unknownAction", use ("hover", "focus", "sendKeys")',
error.message
);
})
.then(done, done);
}


function shouldFailIfKeysAreMissing(done) {
setUpFsMock({
"config.json": path.resolve(__dirname, 'patternlab-to-geminiConfigs/missingKeysOptionForSendKeys.json'),
'dummyhtml/patterns.html': __dirname + '/dummyhtml/patterns.html'
});
var instanceToTest = new patternlabToNode(
'config.json'
);
setUpPatternlabResponse(
'http://localhost:3000',
'dummyhtml/patterns.html'
);
instanceToTest.getPatternsConfiguration()
.then(() => {
throw new Error('should not resolve');
}, (error) => {
asserts.assertEquals(
'wrong error message',
'PatternlabToNode - config error - pattern-1 is missing "keys" option required for sendKeys',
error.message
);
})
Expand Down Expand Up @@ -878,6 +915,30 @@ describe('main - ', () => {
}


function shouldAddCorrectStepsForSendKeys(done) {
setUpFsMock({
"config.json": path.resolve(__dirname, 'patternlab-to-geminiConfigs/actionSendKeys.json'),
'dummyhtml/patterns.html': __dirname + '/dummyhtml/patterns.html'
});
var instanceToTest = new patternlabToNode(
'config.json'
);
setUpPatternlabResponse(
'http://localhost:3000',
'dummyhtml/patterns.html'
);
instanceToTest.getPatternsConfiguration()
.then((patternConfig) => {
asserts.assertEquals(
'wrong steps for action',
'.sendKeys(this.element, \'dummyString\')',
patternConfig.patterns['pattern-1'].actions[0].steps
);
})
.then(done, done);
}


function shouldAddCorrectStepsForFocus(done) {
setUpFsMock({
"config.json": path.resolve(__dirname, 'patternlab-to-geminiConfigs/actionFocus.json'),
Expand Down
19 changes: 19 additions & 0 deletions test/patternlab-to-geminiConfigs/actionSendKeys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"screenSizes": {
"desktop": {
"width": 1440,
"height": 900
}
},
"patterns": {
"pattern-1": {
"actions": [
{
"action": "sendKeys",
"name": "action 1",
"keys": "dummyString"
}
]
}
}
}
26 changes: 26 additions & 0 deletions test/patternlab-to-geminiConfigs/missingKeysOptionForSendKeys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"screenSizes": {
"desktop": {
"width": 1440,
"height": 900
}
},
"patterns": {
"pattern-1": {
"actions": [
{
"name": "action 1",
"action": "sendKeys"
}
]
},
"pattern-2": {
"actions": [
{
"name": "action 2",
"action": "hover"
}
]
}
}
}

0 comments on commit cedb7d0

Please sign in to comment.