Commit 1b25b808 authored by Robert Knight's avatar Robert Knight

Add unit test for Groups List dropdown controller

Add a test for the controller part of the <groups-list> directive.

We have a couple of different patterns for testing directive
controllers in the code, the approach taken here follows the privacy
dropdown's directive in simply exporting the controller's constructor
as a 'private' export and referencing it directly in the test.

 * Rename the exports in the 'directive/privacy' module for consistency
parent 08ced29b
......@@ -134,7 +134,7 @@ module.exports = angular.module('h', [
.directive('deepCount', require('./directive/deep-count'))
.directive('formInput', require('./directive/form-input'))
.directive('formValidate', require('./directive/form-validate'))
.directive('groupList', require('./directive/group-list'))
.directive('groupList', require('./directive/group-list').directive)
.directive('markdown', require('./directive/markdown'))
.directive('privacy', require('./directive/privacy').directive)
.directive('simpleSearch', require('./directive/simple-search'))
......
......@@ -32,7 +32,7 @@ function GroupsListController($scope) {
* @description Displays a list of groups of which the user is a member.
*/
// @ngInject
module.exports = function (groups, $window) {
function GroupsListDirective(groups, $window) {
return {
controller: GroupsListController,
link: function ($scope, elem, attrs) {
......@@ -59,3 +59,8 @@ module.exports = function (groups, $window) {
templateUrl: 'group_list.html'
};
};
module.exports = {
directive: GroupsListDirective,
_Controller: GroupsListController
};
......@@ -125,6 +125,7 @@ var directive = function () {
};
};
exports.PrivacyController = PrivacyController;
exports.directive = directive;
module.exports = {
directive: directive,
_Controller: PrivacyController
};
'use strict';
var groupsList = require('../group-list');
describe('GroupsListController', function () {
var controller;
var $scope;
beforeEach(function () {
$scope = {};
controller = new groupsList._Controller($scope);
});
it('toggles share links', function () {
$scope.toggleShareLink('group-a');
assert.equal($scope.expandedGroupId, 'group-a');
$scope.toggleShareLink('group-a');
assert.equal($scope.expandedGroupId, undefined);
$scope.toggleShareLink('group-b');
assert.equal($scope.expandedGroupId, 'group-b');
$scope.toggleShareLink('group-c');
assert.equal($scope.expandedGroupId, 'group-c');
});
it('shows share link for selected group', function () {
assert.equal($scope.shouldShowShareLink('group-a'), false);
$scope.toggleShareLink('group-a');
assert.equal($scope.shouldShowShareLink('group-a'), true);
$scope.toggleShareLink('group-b');
assert.equal($scope.shouldShowShareLink('group-a'), false);
assert.equal($scope.shouldShowShareLink('group-b'), true);
});
});
// <groups-list> directive
// - check that it renders all visible groups
// - check that share links visible for non-public groups
// - check that share link is focused after toggling share link
// TODO
// - read Angular unit testing guide
// - read Angular E2E testing guides
// - grok an existing directive test
// - get a trivial <groups-list> directive test failing, then make it work
'use strict';
var PrivacyController = require('../privacy').PrivacyController;
var PrivacyController = require('../privacy')._Controller;
describe('PrivacyController', function () {
var fakeScope;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment