mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-12 15:44:25 +02:00
sweet casper tests with keypresses
This commit is contained in:
parent
a1029e8f96
commit
61028608e6
4 changed files with 149 additions and 1 deletions
|
@ -31,6 +31,13 @@ var CasperUtils = {
|
|||
this.test.done();
|
||||
},
|
||||
|
||||
enterCommand: function(command) {
|
||||
return function then() {
|
||||
this.sendKeys('#commandTextField', command, { keepFocus: true });
|
||||
this.page.sendEvent('keypress', this.page.event.key.Enter);
|
||||
};
|
||||
},
|
||||
|
||||
multiAssert: function() {
|
||||
// Copy the args into a variable we can reference inside
|
||||
// our closure.
|
||||
|
@ -74,7 +81,8 @@ var CasperUtils = {
|
|||
selectorContainsText: function(selector, text) {
|
||||
return function then() {
|
||||
this.test.assertEvalEquals(function(selector) {
|
||||
return document.querySelector(selector).innerText;
|
||||
return document.querySelector(selector).innerText
|
||||
.replace(/^\s+/g, '').replace(/\s+$/g, '');
|
||||
},
|
||||
text,
|
||||
'Checking that selector "' + selector + '" contains "' +
|
||||
|
|
32
src/__tests__/casperjs/command_type_test.js
Normal file
32
src/__tests__/casperjs/command_type_test.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
var CasperUtils = require('./casperUtils').CasperUtils;
|
||||
|
||||
casper.start(
|
||||
CasperUtils.getUrl(),
|
||||
function() {
|
||||
this.test.assertTitle('Learn Git Branching');
|
||||
|
||||
casper.waitFor(CasperUtils.waits.jsMount)
|
||||
.wait(300)
|
||||
.then(CasperUtils.enterCommand('level intro1'))
|
||||
.wait(1500)
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView div h2',
|
||||
'Git Commits'
|
||||
))
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView.inFront div.inside p',
|
||||
"A commit in a git repository records a snapshot of all the files in your directory. It's like a giant copy and paste, but even better!"
|
||||
))
|
||||
.then(CasperUtils.screenshot.entirePage)
|
||||
.then(function() {
|
||||
this.page.sendEvent('keypress', this.page.event.key.Escape);
|
||||
})
|
||||
.wait(700)
|
||||
.then(CasperUtils.screenshot.entirePage)
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.levelNameWrapper',
|
||||
"Level Introduction to Git Commits"
|
||||
))
|
||||
.then(CasperUtils.testDone);
|
||||
|
||||
}).run();
|
46
src/__tests__/casperjs/level_dropdown_keyboard_test.js
Normal file
46
src/__tests__/casperjs/level_dropdown_keyboard_test.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
var CasperUtils = require('./casperUtils').CasperUtils;
|
||||
|
||||
casper.start(
|
||||
CasperUtils.getUrl(),
|
||||
function() {
|
||||
this.test.assertTitle('Learn Git Branching');
|
||||
|
||||
casper.waitFor(CasperUtils.waits.jsMount)
|
||||
.wait(300)
|
||||
.then(CasperUtils.enterCommand('levels'))
|
||||
.wait(800)
|
||||
.then(CasperUtils.screenshot.entirePage)
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView.inFront div.toolbar',
|
||||
'Select a level'
|
||||
))
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView.inFront div.displayName h3',
|
||||
'Introduction Sequence'
|
||||
))
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView.inFront div.seriesView p',
|
||||
"A nicely paced introduction to the majority of git commands"
|
||||
))
|
||||
.then(function() {
|
||||
this.page.sendEvent('keypress', this.page.event.key.Right);
|
||||
})
|
||||
.wait(700)
|
||||
.then(CasperUtils.screenshot.entirePage)
|
||||
// Now we have selected the first level
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView.inFront div.seriesView p',
|
||||
"Introduction to Git Commits"
|
||||
))
|
||||
.then(function() {
|
||||
this.page.sendEvent('keypress', this.page.event.key.Enter);
|
||||
})
|
||||
.wait(700)
|
||||
.then(CasperUtils.screenshot.entirePage)
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.levelNameWrapper',
|
||||
"Level Introduction to Git Commits"
|
||||
))
|
||||
.then(CasperUtils.testDone);
|
||||
|
||||
}).run();
|
62
src/__tests__/casperjs/level_dropdown_page_keyboard_test.js
Normal file
62
src/__tests__/casperjs/level_dropdown_page_keyboard_test.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
var CasperUtils = require('./casperUtils').CasperUtils;
|
||||
|
||||
casper.start(
|
||||
CasperUtils.getUrl(),
|
||||
function() {
|
||||
this.test.assertTitle('Learn Git Branching');
|
||||
|
||||
casper.waitFor(CasperUtils.waits.jsMount)
|
||||
.wait(300)
|
||||
.then(CasperUtils.enterCommand('levels'))
|
||||
.wait(800)
|
||||
.then(CasperUtils.screenshot.entirePage)
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView.inFront div.toolbar',
|
||||
'Select a level'
|
||||
))
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView.inFront div.displayName h3',
|
||||
'Introduction Sequence'
|
||||
))
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView.inFront div.seriesView p',
|
||||
"A nicely paced introduction to the majority of git commands"
|
||||
))
|
||||
// Hit right 5 times
|
||||
.then(function() {
|
||||
this.page.sendEvent('keypress', this.page.event.key.Right);
|
||||
})
|
||||
.then(function() {
|
||||
this.page.sendEvent('keypress', this.page.event.key.Right);
|
||||
})
|
||||
.then(function() {
|
||||
this.page.sendEvent('keypress', this.page.event.key.Right);
|
||||
})
|
||||
.then(function() {
|
||||
this.page.sendEvent('keypress', this.page.event.key.Right);
|
||||
})
|
||||
.then(function() {
|
||||
this.page.sendEvent('keypress', this.page.event.key.Right);
|
||||
})
|
||||
.wait(300)
|
||||
.then(CasperUtils.screenshot.entirePage)
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView.inFront div.displayName h3',
|
||||
"Push & Pull -- Git Remotes!"
|
||||
))
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.modalView.inFront div.seriesView p',
|
||||
"Clone Intro"
|
||||
))
|
||||
.then(function() {
|
||||
this.page.sendEvent('keypress', this.page.event.key.Enter);
|
||||
})
|
||||
.wait(700)
|
||||
.then(CasperUtils.screenshot.entirePage)
|
||||
.then(CasperUtils.asserts.selectorContainsText(
|
||||
'div.levelNameWrapper',
|
||||
"Level Clone Intro"
|
||||
))
|
||||
.then(CasperUtils.testDone);
|
||||
|
||||
}).run();
|
Loading…
Add table
Add a link
Reference in a new issue