From 533892f080ebdf29173d11db4d12f92809d39b36 Mon Sep 17 00:00:00 2001 From: Tatiana Ovchinnikova Date: Tue, 22 Sep 2020 14:11:12 -0500 Subject: [PATCH] Make text download and load groups tests work Currently "then" callback functions for these tests aren't called since digest cycles were never triggered. Jasmine Spec Runner marks them 'passed' only adding "SPEC HAS NO EXPECTATIONS" into their names. This patch triggers a digest by calling a scope's $apply functions in a correct place, deals with timeout properly and makes the tests work. Closes-Bug: #1894127 Change-Id: I00acc4b13fa0cc05b8c6ccd2024084527562f001 --- .../framework/util/file/text-download.service.spec.js | 10 ++++++---- .../dashboard/identity/groups/groups.module.spec.js | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/horizon/static/framework/util/file/text-download.service.spec.js b/horizon/static/framework/util/file/text-download.service.spec.js index 796dc8bf89..971d3dbca8 100644 --- a/horizon/static/framework/util/file/text-download.service.spec.js +++ b/horizon/static/framework/util/file/text-download.service.spec.js @@ -23,12 +23,14 @@ $scope = $injector.get('$rootScope'); })); - it('should return promise and it resolve filename after starting download file', function() { + it('should return a promise that resolves to a download file name', inject(function($timeout) { var promise = textDownload.downloadTextFile('content', 'download_file_name.txt'); + promise.then(verifyContents); $scope.$apply(); - promise.then(function(contents) { + $timeout.flush(); + function verifyContents (contents) { expect(contents).toEqual('download_file_name.txt'); - }); - }); + } + })); }); })(); diff --git a/openstack_dashboard/dashboards/identity/static/dashboard/identity/groups/groups.module.spec.js b/openstack_dashboard/dashboards/identity/static/dashboard/identity/groups/groups.module.spec.js index fc64fc35a3..bb90af5067 100644 --- a/openstack_dashboard/dashboards/identity/static/dashboard/identity/groups/groups.module.spec.js +++ b/openstack_dashboard/dashboards/identity/static/dashboard/identity/groups/groups.module.spec.js @@ -50,10 +50,12 @@ }); it('should load groups', function () { - registry.getResourceType('OS::Keystone::Group').list().then(function(responses) { - $scope.$apply(); - expect(responses).toEqual(groups); - }); + var groupList = registry.getResourceType('OS::Keystone::Group').list(); + groupList.then(verifyResult); + $scope.$apply(); + function verifyResult (result) { + expect(result).toEqual(groups); + } }); }); })();