From 4afbc997f65458221aa7f456a19f37a667cc203d Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Thu, 3 Dec 2015 11:45:19 -0500 Subject: [PATCH] Added unit test for the main menu template. This tests the length of the mobile menu items against the length of the non-menu items. --- .../main-menu/main-menu.template-test.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 awx/ui/client/tests/main-menu/main-menu.template-test.js diff --git a/awx/ui/client/tests/main-menu/main-menu.template-test.js b/awx/ui/client/tests/main-menu/main-menu.template-test.js new file mode 100644 index 0000000000..a692f19bc6 --- /dev/null +++ b/awx/ui/client/tests/main-menu/main-menu.template-test.js @@ -0,0 +1,51 @@ +import '../support/node'; + +describe("mainMenuTemplate", function() { + + // Define local variables. The template path is basically the key + // used as a reference to track the template within the $templateCache; + var viewHtml; + var templateUrl = '/static/main-menu/main-menu.partial.html'; + var $rootScope; + var $scope; + var $compile; + var mainMenuElement; + + // The templates module gets defined during the build process + // and including it gives us access to the templates that get + // stuffed into $templateCache + beforeEach("instantiate the templates module", function() { + angular.mock.module("templates"); + }); + + beforeEach(inject(function($templateCache) { + // All of our templates should have been pre-loaded into $templateCache + // during the build process. Leverage $templateCache.get to retrieve + // it into memory + viewHtml = $templateCache.get(templateUrl); + })); + + beforeEach(inject(function(_$compile_, _$rootScope_){ + $compile = _$compile_; + $rootScope = _$rootScope_; + $scope = $rootScope.$new(); + + // If we needed to stub any scope variables we could do it here + + // Wrap HTML string as jQuery object + mainMenuElement = angular.element(viewHtml); + })); + + it('mobile menu items match non-mobile menu items', function() { + compileElement(); + var mobileMenuItems = mainMenuElement.find("#main_menu_mobile_items > .MainMenu-item").length; + var nonMobileMenuItems = mainMenuElement.find(".MainMenu-item--notMobile").length; + expect(mobileMenuItems).to.equal(nonMobileMenuItems); + }); + + function compileElement() { + $compile(mainMenuElement)($scope); + $rootScope.$digest(); + } + +});