From b460697a18be928a15455bcf01ab0e88c5198d51 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Wed, 19 Mar 2014 21:18:21 +0000 Subject: [PATCH] Add functional tests for admin navigation bar and menus issue #2273 - Check that menu nav items exist - Check that menu nav items are labeled correctly - Check that menu nav items have correct URLs --- core/test/functional/admin/content_test.js | 69 +++++++++++++++++---- core/test/functional/admin/editor_test.js | 55 ++++++++++++++++ core/test/functional/admin/settings_test.js | 57 +++++++++++++++++ 3 files changed, 168 insertions(+), 13 deletions(-) diff --git a/core/test/functional/admin/content_test.js b/core/test/functional/admin/content_test.js index ae03b8eb24..2ed67c05bb 100644 --- a/core/test/functional/admin/content_test.js +++ b/core/test/functional/admin/content_test.js @@ -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'); @@ -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"); @@ -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'); + }); }); \ No newline at end of file diff --git a/core/test/functional/admin/editor_test.js b/core/test/functional/admin/editor_test.js index ddfdb6b66c..29c82826cb 100644 --- a/core/test/functional/admin/editor_test.js +++ b/core/test/functional/admin/editor_test.js @@ -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'); + }); +}); diff --git a/core/test/functional/admin/settings_test.js b/core/test/functional/admin/settings_test.js index 48ec2d50bb..bd9fd99fad 100644 --- a/core/test/functional/admin/settings_test.js +++ b/core/test/functional/admin/settings_test.js @@ -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"); @@ -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'); + }); +});