Skip to content

Commit

Permalink
Merge pull request #36 from LarsHassler/feat/action-delay
Browse files Browse the repository at this point in the history
added option to add a delay into actions
  • Loading branch information
LarsHassler committed Feb 5, 2017
2 parents bd05c55 + fa30bfc commit 0775cdb
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/Actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ rendered as child nodes of the body.
An array of browsers to skip this action for.
See [Configuration](Configuration.md#skipBrowsers) for details on how to use this.

#### delay

A number of milliseconds to wait before the screenshot is taken. Useful for
css transitions and animations.

## hover

A particular element within a pattern will be tested while the mouse is hovering
Expand Down
4 changes: 4 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ PatternlabToNode.prototype.parseAction = function(pattern) {
'use ("' + validActions.join('", "') + '")'
);
}

if (action.delay) {
action.steps += '.wait(' + action.delay + ')';
}
})
}
};
Expand Down
36 changes: 36 additions & 0 deletions test/expectedTestFiles/generateTestsPatternActionsWithDelays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

gemini.suite('Patternlab - ', function(patternlabSuite) {
patternlabSuite.setUrl('/styleguide/html/styleguide.html');

gemini.suite('Pattern Name 1', function(suite) {
suite
.setCaptureElements(['#pattern-1 .sg-pattern-example'])
.capture('desktop', function(actions, find) {
actions.setWindowSize(1440, 900);
});
});


gemini.suite('Pattern Name 1 --- hovered', function(suite) {
suite
.before(function(actions, find) {
this.element = find('#pattern-1 .sg-pattern-example button')
})
.setCaptureElements(['#pattern-1 .sg-pattern-example'])
.capture('desktop', function(actions, find) {
actions.setWindowSize(1440, 900)
.moveMouse(this.element).wait(250);
});
});


gemini.suite('Pattern Name 2', function(suite) {
suite
.setCaptureElements(['#pattern-2 .sg-pattern-example'])
.capture('desktop', function(actions, find) {
actions.setWindowSize(1440, 900);
});
});


});
82 changes: 82 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ describe('main - ', () => {
shouldAddCorrectStepsForFocus
);

it("should add correct steps for delay",
shouldAddCorrectStepsForDelay
);

describe('skipBrowsers - ', function() {

it('should reject if its not an array',
Expand Down Expand Up @@ -382,6 +386,10 @@ describe('main - ', () => {
shouldWorkWithActionWithSelectors
);

it('should work with delays in actions',
shouldWorkWithDelaysInActions
);

it('should work with skipping multiple browsers',
shouldWorkWithSkippingMultipleBrowsers
);
Expand Down Expand Up @@ -720,6 +728,56 @@ describe('main - ', () => {
}



function shouldWorkWithDelaysInActions(done) {
setUpFsMock({
"config.json": path.resolve(__dirname, 'patternlab-to-geminiConfigs/definedPatternActionsWithDelays.json'),
"expectedTest.js": path.resolve(__dirname, 'expectedTestFiles/generateTestsPatternActionsWithDelays.js'),
"templates/main.ejs": path.resolve(__dirname, '../templates/main.ejs')
});
var instanceToTest = new patternlabToNode('config.json');
instanceToTest.getPatternsConfiguration = function() {
return new Promise((resolve) => {
resolve({
"_patternOrder": [
"pattern-1",
"pattern-2"
],
"patterns": {
"pattern-1": {
"id": "pattern-1",
"name": "Pattern Name 1",
"screenSizes": ["desktop"],
"actions": [
{
"action": "hover",
"name": "hovered",
"selector": "#pattern-1 .sg-pattern-example button",
"steps": ".moveMouse(this.element).wait(250)"
}
]
},
"pattern-2": {
"id": "pattern-2",
"name": "Pattern Name 2",
"screenSizes": ["desktop"]
}
}
});
})
};
instanceToTest.generateTests()
.then(() => {
asserts.assertEquals(
"wrong testFile generated",
fs.readFileSync('expectedTest.js').toString(),
fs.readFileSync('patternlabTests.js').toString()
)
})
.then(done, done);
}


function shouldWorkWithSkippingMultipleBrowsers(done) {
setUpFsMock({
"config.json": path.resolve(__dirname, 'patternlab-to-geminiConfigs/skipBrowsers.json'),
Expand Down Expand Up @@ -1718,6 +1776,30 @@ describe('main - ', () => {
}


function shouldAddCorrectStepsForDelay(done) {
setUpFsMock({
"config.json": path.resolve(__dirname, 'patternlab-to-geminiConfigs/actionFocusWithDelay.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',
'.focus(this.element).wait(500)',
patternConfig.patterns['pattern-1'].actions[0].steps
);
})
.then(done, done);
}


function shouldRejectIfACustomScreenSizeWasFoundButNotDefined(done) {
setUpFsMock({
"config.json": path.resolve(__dirname, 'patternlab-to-geminiConfigs/missingPatternScreenSizes.json'),
Expand Down
19 changes: 19 additions & 0 deletions test/patternlab-to-geminiConfigs/actionFocusWithDelay.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": "focus",
"name": "action 1",
"delay": 500
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"patternlabUrl": "http://localhost:3000",
"screenSizes": {
"desktop": {
"width": 1440,
"height": 900
}
},
"patterns": {
"pattern-1": {
"actions": [
{
"action": "hover",
"name": "hovered",
"selector": "button",
"delay": 250
}
]
}
}
}

0 comments on commit 0775cdb

Please sign in to comment.