Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
willdoran committed Oct 13, 2016
1 parent fde1f9c commit 10bf408
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app/common/controllers/intercom.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ function (
$window
) {
var pattern = /^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)/g;

$rootScope.$on('event:authentication:login:succeeded', function () {
if (!$rootScope.globalEmbed) {
if ($window.self === $window.top) {
$scope.startIntercom();
}
});
Expand Down
5 changes: 2 additions & 3 deletions app/common/directives/embed-only.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ function EmbedOnlyDirective() {

EmbedOnlyController.$inject = ['$scope', '$element', '$attrs', '$rootScope', '_', '$window'];
function EmbedOnlyController($scope, $element, $attrs, $rootScope, _, $window) {

var globalEmbed = ($window.self !== $window.top) ? true : false;
if (globalEmbed) {
$rootScope.setLayout('layout-embed');
}
if (globalEmbed && !$attrs.embedOnly) {
if (globalEmbed && ($attrs.embedOnly === 'false')) {
$element.addClass('hidden');
} else if (!globalEmbed && $attrs.embedOnly) {
} else if (!globalEmbed && ($attrs.embedOnly === 'true')) {
$element.addClass('hidden');
}
}
2 changes: 1 addition & 1 deletion app/common/directives/ush-logo.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a embed-only=true href="https://www.ushahidi.com" class="ushahidi-bug" target="_blank">
<ng-include src="'templates/common/directives/mode-bar/ushahidi-logo.html'"></ng-include>
<ng-include include-replace src="'templates/common/directives/mode-bar/ushahidi-logo.html'"></ng-include>
<span class="hidden">Powered by Ushahidi</span>
</a>
4 changes: 3 additions & 1 deletion app/common/services/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = [
'MediaEndpoint',
'$compile',
'$rootScope',
'$window',
'CONST',
function (
$q,
Expand All @@ -25,6 +26,7 @@ function (
MediaEndpoint,
$compile,
$rootScope,
$window,
CONST
) {
var layers = {
Expand Down Expand Up @@ -116,7 +118,7 @@ function (
maps: {},
config: undefined,
getZoomControlPosition: function () {
return $rootScope.globalEmbed ? 'bottomleft' : 'bottomright';
return $window.self !== $window.top ? 'bottomleft' : 'bottomright';
},
getMap: function (name) {
if (!this.maps[name]) {
Expand Down
5 changes: 4 additions & 1 deletion test/unit/common/controllers/intercom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ describe('intercom controller', function () {
ushahidi: {
intercomAppId: 'test',
apiUrl: 'test'
}
},
self: 'top',
top: 'top'
};

beforeEach(function () {
Expand All @@ -30,6 +32,7 @@ describe('intercom controller', function () {
beforeEach(inject(function (_$rootScope_, _$controller_) {
$rootScope = _$rootScope_;
$controller = _$controller_;

$scope = _$rootScope_.$new();
}));

Expand Down
46 changes: 46 additions & 0 deletions test/unit/common/directives/embed-only.directive.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var ROOT_PATH = '../../../../';

describe('embed only directive', function () {

var $rootScope,
$compile,
$scope,
$window,
element;

beforeEach(function () {
fixture.setBase('mocked_backend/api/v3');

require(ROOT_PATH + 'test/unit/mock/mock-modules.js');

var testApp = angular.module('testApp', [
'ushahidi.mock'
]);

testApp.directive('embedOnly', require(ROOT_PATH + 'app/common/directives/embed-only.directive'));

require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp);

angular.mock.module('testApp');
});

beforeEach(angular.mock.module('client-templates'));

beforeEach(inject(function (_$rootScope_, _$compile_, _Notify_, _GlobalFilter_, _$window_) {
$rootScope = _$rootScope_;
$compile = _$compile_;
$window = _$window_;
$scope = _$rootScope_.$new();
$window.self = 'frame';
$rootScope.setLayout = function () {};
spyOn($rootScope, 'setLayout').and.callThrough();
}));

it('should set the layout', function () {
element = '<div embed-only></div>';
element = $compile(element)($scope);
$scope.$digest();

expect($rootScope.setLayout).toHaveBeenCalledWith('layout-embed');
});
});

0 comments on commit 10bf408

Please sign in to comment.