Skip to content

Commit

Permalink
Merge pull request #2450 from jaswilli/issue-2273
Browse files Browse the repository at this point in the history
Add functional tests for admin navigation bar and menus
  • Loading branch information
ErisDS committed Apr 5, 2014
2 parents c38c778 + b460697 commit e86bb50
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 13 deletions.
69 changes: 56 additions & 13 deletions core/test/functional/admin/content_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*globals casper, __utils__, url, testPost */

CasperTest.begin("Content screen is correct", 20, function suite(test) {
CasperTest.begin("Content screen is correct", 12, function suite(test) {
// Create a sample post
casper.thenOpen(url + 'ghost/editor/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
Expand All @@ -27,18 +27,6 @@ CasperTest.begin("Content screen is correct", 20, function suite(test) {
test.assertUrlMatch(/ghost\/content\/$/, "Ghost doesn't require login this time");
});

casper.then(function testMenus() {
test.assertExists("#main-menu", "Main menu is present");
test.assertSelectorHasText("#main-menu .content a", "Content");
test.assertSelectorHasText("#main-menu .editor a", "New Post");
test.assertSelectorHasText("#main-menu .settings a", "Settings");

test.assertExists("#usermenu", "User menu is present");
test.assertSelectorHasText("#usermenu .usermenu-profile a", "Your Profile");
test.assertSelectorHasText("#usermenu .usermenu-help a", "Help / Support");
test.assertSelectorHasText("#usermenu .usermenu-signout a", "Sign Out");
});

casper.then(function testViews() {
test.assertExists(".content-view-container", "Content main view is present");
test.assertExists(".content-list-content", "Content list view is present");
Expand Down Expand Up @@ -129,4 +117,59 @@ CasperTest.begin("Posts can be marked as featured", 12, function suite(test) {
}, function onTimeout() {
test.assert(false, 'Success notification wont go away:(');
});
});

CasperTest.begin('Admin navigation bar is correct', 28, function suite(test) {
casper.thenOpen(url + 'ghost/content/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
test.assertUrlMatch(/ghost\/content\/$/, "Ghost doesn't require login this time");
});

casper.then(function testNavItems() {
test.assertExists('a.ghost-logo', 'Ghost logo home page link exists');
test.assertEquals(this.getElementAttribute('a.ghost-logo', 'href'), '/', 'Ghost logo href is correct');

test.assertExists('#main-menu li.content a', 'Content nav item exists');
test.assertSelectorHasText('#main-menu li.content a', 'Content', 'Content nav item has correct text');
test.assertEquals(this.getElementAttribute('#main-menu li.content a', 'href'), '/ghost/', 'Content href is correct');
test.assertEval(function testContentIsNotActive() {
return document.querySelector('#main-menu li.content').classList.contains('active');
}, 'Content nav item is marked active');

test.assertExists('#main-menu li.editor a', 'Editor nav item exists');
test.assertSelectorHasText('#main-menu li.editor a', 'New Post', 'Editor nav item has correct text');
test.assertEquals(this.getElementAttribute('#main-menu li.editor a', 'href'), '/ghost/editor/', 'Editor href is correct');
test.assertEval(function testEditorIsNotActive() {
return !document.querySelector('#main-menu li.editor').classList.contains('active');
}, 'Editor nav item is not marked active');

test.assertExists('#main-menu li.settings a', 'Settings nav item exists');
test.assertSelectorHasText('#main-menu li.settings a', 'Settings', 'Settings nav item has correct text');
test.assertEquals(this.getElementAttribute('#main-menu li.settings a', 'href'), '/ghost/settings/', 'Settings href is correct');
test.assertEval(function testSettingsIsActive() {
return !document.querySelector('#main-menu li.settings').classList.contains('active');
}, 'Settings nav item is not marked active');
});

casper.then(function testUserMenuNotVisible() {
test.assertExists('#usermenu', 'User menu nav item exists');
test.assertNotVisible('#usermenu ul.overlay', 'User menu should not be visible');
});

casper.thenClick('#usermenu a');
casper.waitForSelector('#usermenu ul.overlay', function then() {
test.assertVisible('#usermenu ul.overlay', 'User menu should be visible');

test.assertExists('#usermenu li.usermenu-profile a', 'Profile menu item exists');
test.assertSelectorHasText('#usermenu li.usermenu-profile a', 'Your Profile', 'Profile menu item has correct text');
test.assertEquals(this.getElementAttribute('li.usermenu-profile a', 'href'), '/ghost/settings/user/', 'Profile href is correct');

test.assertExists('#usermenu li.usermenu-help a', 'Help menu item exists');
test.assertSelectorHasText('#usermenu li.usermenu-help a', 'Help / Support', 'Help menu item has correct text');
test.assertEquals(this.getElementAttribute('li.usermenu-help a', 'href'), 'http://ghost.org/forum/', 'Help href is correct');

test.assertExists('#usermenu li.usermenu-signout a', 'Sign Out menu item exists');
test.assertSelectorHasText('#usermenu li.usermenu-signout a', 'Sign Out', 'Sign Out menu item has correct text');
test.assertEquals(this.getElementAttribute('#usermenu li.usermenu-signout a', 'href'), '/ghost/signout/', 'Sign Out href is correct');
});
});
55 changes: 55 additions & 0 deletions core/test/functional/admin/editor_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,58 @@ CasperTest.begin('Publish menu - existing post', 22, function suite(test) {
test.assert(false, 'Publish split button should have .splitbutton-delete');
});
});

CasperTest.begin('Admin navigation bar is correct', 28, function suite(test) {
casper.thenOpen(url + 'ghost/editor/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
test.assertUrlMatch(/ghost\/editor\/$/, "Ghost doesn't require login this time");
});

casper.then(function testNavItems() {
test.assertExists('a.ghost-logo', 'Ghost logo home page link exists');
test.assertEquals(this.getElementAttribute('a.ghost-logo', 'href'), '/', 'Ghost logo href is correct');

test.assertExists('#main-menu li.content a', 'Content nav item exists');
test.assertSelectorHasText('#main-menu li.content a', 'Content', 'Content nav item has correct text');
test.assertEquals(this.getElementAttribute('#main-menu li.content a', 'href'), '/ghost/', 'Content href is correct');
test.assertEval(function testContentIsNotActive() {
return !document.querySelector('#main-menu li.content').classList.contains('active');
}, 'Content nav item is not marked active');

test.assertExists('#main-menu li.editor a', 'Editor nav item exists');
test.assertSelectorHasText('#main-menu li.editor a', 'New Post', 'Editor nav item has correct text');
test.assertEquals(this.getElementAttribute('#main-menu li.editor a', 'href'), '/ghost/editor/', 'Editor href is correct');
test.assertEval(function testEditorIsNotActive() {
return document.querySelector('#main-menu li.editor').classList.contains('active');
}, 'Editor nav item is marked active');

test.assertExists('#main-menu li.settings a', 'Settings nav item exists');
test.assertSelectorHasText('#main-menu li.settings a', 'Settings', 'Settings nav item has correct text');
test.assertEquals(this.getElementAttribute('#main-menu li.settings a', 'href'), '/ghost/settings/', 'Settings href is correct');
test.assertEval(function testSettingsIsActive() {
return !document.querySelector('#main-menu li.settings').classList.contains('active');
}, 'Settings nav item is not marked active');
});

casper.then(function testUserMenuNotVisible() {
test.assertExists('#usermenu', 'User menu nav item exists');
test.assertNotVisible('#usermenu ul.overlay', 'User menu should not be visible');
});

casper.thenClick('#usermenu a');
casper.waitForSelector('#usermenu ul.overlay', function then() {
test.assertVisible('#usermenu ul.overlay', 'User menu should be visible');

test.assertExists('#usermenu li.usermenu-profile a', 'Profile menu item exists');
test.assertSelectorHasText('#usermenu li.usermenu-profile a', 'Your Profile', 'Profile menu item has correct text');
test.assertEquals(this.getElementAttribute('li.usermenu-profile a', 'href'), '/ghost/settings/user/', 'Profile href is correct');

test.assertExists('#usermenu li.usermenu-help a', 'Help menu item exists');
test.assertSelectorHasText('#usermenu li.usermenu-help a', 'Help / Support', 'Help menu item has correct text');
test.assertEquals(this.getElementAttribute('#usermenu li.usermenu-help a', 'href'), 'http://ghost.org/forum/', 'Help href is correct');

test.assertExists('#usermenu li.usermenu-signout a', 'Sign Out menu item exists');
test.assertSelectorHasText('#usermenu li.usermenu-signout a', 'Sign Out', 'Sign Out menu item has correct text');
test.assertEquals(this.getElementAttribute('#usermenu li.usermenu-signout a', 'href'), '/ghost/signout/', 'Sign Out href is correct');
});
});
57 changes: 57 additions & 0 deletions core/test/functional/admin/settings_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*globals casper, __utils__, url */

// var navTest = require('../partials/partial_test');

CasperTest.begin("Settings screen is correct", 18, function suite(test) {
casper.thenOpen(url + "ghost/settings/", function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
Expand Down Expand Up @@ -388,3 +390,58 @@ CasperTest.begin('Ensure user location field length validation', 3, function sui
test.fail('Location field length error did not appear');
}, 2000);
});

CasperTest.begin('Admin navigation bar is correct', 28, function suite(test) {
casper.thenOpen(url + 'ghost/settings/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
test.assertUrlMatch(/ghost\/settings\/general\/$/, "Ghost doesn't require login this time");
});

casper.then(function testNavItems() {
test.assertExists('a.ghost-logo', 'Ghost logo home page link exists');
test.assertEquals(this.getElementAttribute('a.ghost-logo', 'href'), '/', 'Ghost logo href is correct');

test.assertExists('#main-menu li.content a', 'Content nav item exists');
test.assertSelectorHasText('#main-menu li.content a', 'Content', 'Content nav item has correct text');
test.assertEquals(this.getElementAttribute('#main-menu li.content a', 'href'), '/ghost/', 'Content href is correct');
test.assertEval(function testContentIsNotActive() {
return !document.querySelector('#main-menu li.content').classList.contains('active');
}, 'Content nav item is not marked active');

test.assertExists('#main-menu li.editor a', 'Editor nav item exists');
test.assertSelectorHasText('#main-menu li.editor a', 'New Post', 'Editor nav item has correct text');
test.assertEquals(this.getElementAttribute('#main-menu li.editor a', 'href'), '/ghost/editor/', 'Editor href is correct');
test.assertEval(function testEditorIsNotActive() {
return !document.querySelector('#main-menu li.editor').classList.contains('active');
}, 'Editor nav item is not marked active');

test.assertExists('#main-menu li.settings a', 'Settings nav item exists');
test.assertSelectorHasText('#main-menu li.settings a', 'Settings', 'Settings nav item has correct text');
test.assertEquals(this.getElementAttribute('#main-menu li.settings a', 'href'), '/ghost/settings/', 'Settings href is correct');
test.assertEval(function testSettingsIsActive() {
return document.querySelector('#main-menu li.settings').classList.contains('active');
}, 'Settings nav item is marked active');
});

casper.then(function testUserMenuNotVisible() {
test.assertExists('#usermenu', 'User menu nav item exists');
test.assertNotVisible('#usermenu ul.overlay', 'User menu should not be visible');
});

casper.thenClick('#usermenu a');
casper.waitForSelector('#usermenu ul.overlay', function then() {
test.assertVisible('#usermenu ul.overlay', 'User menu should be visible');

test.assertExists('#usermenu li.usermenu-profile a', 'Profile menu item exists');
test.assertSelectorHasText('#usermenu li.usermenu-profile a', 'Your Profile', 'Profile menu item has correct text');
test.assertEquals(this.getElementAttribute('#usermenu li.usermenu-profile a', 'href'), '/ghost/settings/user/', 'Profile href is correct');

test.assertExists('#usermenu li.usermenu-help a', 'Help menu item exists');
test.assertSelectorHasText('#usermenu li.usermenu-help a', 'Help / Support', 'Help menu item has correct text');
test.assertEquals(this.getElementAttribute('#usermenu li.usermenu-help a', 'href'), 'http://ghost.org/forum/', 'Help href is correct');

test.assertExists('#usermenu li.usermenu-signout a', 'Sign Out menu item exists');
test.assertSelectorHasText('#usermenu li.usermenu-signout a', 'Sign Out', 'Sign Out menu item has correct text');
test.assertEquals(this.getElementAttribute('#usermenu li.usermenu-signout a', 'href'), '/ghost/signout/', 'Sign Out href is correct');
});
});

0 comments on commit e86bb50

Please sign in to comment.