Merge pull request #3046 from ErisDS/issue-2988

Update shortcut for zen mode
This commit is contained in:
Hannah Wolfe 2014-06-23 23:36:48 +01:00
commit c385ebc654
3 changed files with 45 additions and 9 deletions

View File

@ -21,12 +21,12 @@ var EditorRouteBase = Ember.Mixin.create(styleBody, ShortcutsRoute, loadingIndic
this.get('controller.codemirror').shortcut(options.type);
}
},
shortcuts: {
//General Editor shortcuts
'ctrl+s, command+s': 'save',
'ctrl+alt+p': 'publish',
'ctrl+alt+z': 'toggleZenMode',
'alt+shift+z': 'toggleZenMode',
//CodeMirror Markdown Shortcuts
'ctrl+alt+u': {action: 'codeMirrorShortcut', options: {type: 'strike'}},
'ctrl+alt+1': {action: 'codeMirrorShortcut', options: {type: 'h1'}},

View File

@ -61,17 +61,17 @@ casper.writeContentToCodeMirror = function (content) {
}, 2000);
};
casper.waitForOpaque = function (classname, then, timeout) {
timeout = timeout || casper.failOnTimeout(casper.test, 'waitForOpaque failed on ' + classname);
casper.waitForOpacity = function (classname, opacity, then, timeout) {
timeout = timeout || casper.failOnTimeout(casper.test, 'waitForOpacity failed on ' + classname + ' ' + opacity);
casper.waitForSelector(classname).then(function () {
casper.waitFor(function checkOpaque() {
var value = this.evaluate(function (element) {
var value = this.evaluate(function (element, opacity) {
var target = document.querySelector(element);
if (target === null) {
return null;
}
return window.getComputedStyle(target).getPropertyValue('opacity') === '1';
}, classname);
return window.getComputedStyle(target).getPropertyValue('opacity') === opacity;
}, classname, opacity);
if (value !== true && value !== false) {
casper.test.fail('Unable to find element: ' + classname);
}
@ -80,6 +80,15 @@ casper.waitForOpaque = function (classname, then, timeout) {
});
};
casper.waitForOpaque = function (classname, then, timeout) {
casper.waitForOpacity(classname, '1', then, timeout);
};
casper.waitForTransparent = function (classname, then, timeout) {
casper.waitForOpacity(classname, '0', then, timeout);
};
// ### Then Open And Wait For Page Load
// Always wait for the `#main` element as some indication that the ember app has loaded.
casper.thenOpenAndWaitForPageLoad = function (screen, then, timeout) {
@ -97,7 +106,7 @@ casper.thenOpenAndWaitForPageLoad = function (screen, then, timeout) {
},
'editor': {
url: 'ghost/ember/editor/',
selector: '#main-menu .editor.active'
selector: '#entry-title'
},
'settings': {
url: 'ghost/ember/settings/',

View File

@ -2,7 +2,7 @@
// Test the editor screen works as expected
/*globals casper, __utils__, url, testPost */
CasperTest.emberBegin('Ghost editor functions correctly', 15, function suite(test) {
CasperTest.emberBegin('Ghost editor functions correctly', 19, function suite(test) {
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
@ -85,6 +85,33 @@ CasperTest.emberBegin('Ghost editor functions correctly', 15, function suite(tes
casper.waitForSelectorTextChange('.entry-word-count', function onSuccess() {
test.assertSelectorHasText('.entry-word-count', '2 words', 'count of 2 produces plural "words".');
});
// Part 5: Editor global shortcuts
casper.then(function tryZenShortcut() {
casper.sendKeys('#main', 'z', {modifiers: 'alt+shift'});
});
casper.waitForSelector('.editor.zen', function then() {
casper.waitForTransparent('#global-header', function then() {
test.assert(true, 'header becomes transparent');
});
casper.waitForTransparent('#publish-bar', function then() {
test.assert(true, 'publish bar becomes transparent');
});
});
casper.then(function tryZenShortcut() {
casper.sendKeys('#main', 'z', {modifiers: 'alt+shift'});
});
casper.waitWhileSelector('.editor.zen', function then() {
casper.waitForOpaque('#global-header', function then() {
test.assert(true, 'header becomes opaque');
});
casper.waitForOpaque('#publish-bar', function then() {
test.assert(true, 'publish bar becomes opaque');
});
});
});
// TODO: Expand markdown tests to cover more markdown, and keyboard shortcuts