Last active
October 21, 2016 20:03
-
-
Save lancegliser/a29dacb4f75f13195b5c to your computer and use it in GitHub Desktop.
AngularJS Hold Button Directive with feedback
This file contains 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
<button | |
hold-button | |
hold-button-success="holdAction()" <!-- this should be a $scope function, optionally with parameters --> | |
hold-button-delay="" <!-- number of milliseconds required, default 400 --> | |
hold-button-fill-color="" <!-- any acceptable css color string --> | |
>Hold to Activate | |
</button> |
This file contains 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
describe('hold buttons', function(){ | |
// You'll need to write the page definition yourself | |
var holdButton = page.getHoldButton(); | |
it('should give feedback on interaction', function(){ | |
browser.actions().mouseDown(holdButton).perform(); | |
browser.sleep(50); | |
expect(holdButton.getAttribute('class') ).toMatch('holding'); | |
browser.actions().mouseUp(holdButton).perform(); | |
}); | |
it('should not complete in under .5 seconds', function(){ | |
browser.actions().mouseDown(holdButton).perform(); | |
browser.sleep(50); | |
browser.actions().mouseUp(holdButton).perform(); | |
expect(holdButton.getAttribute('class') ).toMatch('hold-failure'); | |
}); | |
it('should complete eventually', function(){ | |
browser.actions().mouseDown(holdButton).perform(); | |
browser.sleep(2000); | |
browser.actions().mouseUp(holdButton).perform(); | |
expect(holdButton.getAttribute('class') ).toMatch('hold-success'); | |
}); | |
}); |
This file contains 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
button.holding { | |
border-style: dashed; | |
} | |
button.hold-success { | |
background-color: #43AC6A; | |
border-color: #368a55; | |
color: #fff; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment