-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHE-1687 fix sorting rule for recent workspaces
Signed-off-by: Oleksii Orel <oorel@codenvy.com>
- Loading branch information
Oleksii Orel
committed
Mar 1, 2017
1 parent
94b9418
commit 51b6abe
Showing
7 changed files
with
206 additions
and
22 deletions.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
src/app/navbar/recent-workspaces/recent-workspaces.controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* Copyright (c) 2015-2017 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*/ | ||
'use strict'; | ||
import {CheWorkspace} from '../../../components/api/che-workspace.factory'; | ||
import {CheAPIBuilder} from '../../../components/api/builder/che-api-builder.factory'; | ||
import {CheHttpBackend} from '../../../components/api/test/che-http-backend'; | ||
import IdeSvc from '../../ide/ide.service'; | ||
|
||
|
||
/** | ||
* Test of the NavbarRecentWorkspacesController | ||
*/ | ||
describe('NavbarRecentWorkspacesController', () => { | ||
/** | ||
* NavbarRecentWorkspacesController | ||
*/ | ||
let navbarRecentWorkspacesController; | ||
|
||
/** | ||
* API builder | ||
*/ | ||
let apiBuilder: CheAPIBuilder; | ||
|
||
/** | ||
* Backend for handling http operations | ||
*/ | ||
let httpBackend: ng.IHttpBackendService; | ||
|
||
/** | ||
* Che backend | ||
*/ | ||
let cheBackend: CheHttpBackend; | ||
|
||
|
||
let workspaces: Array<che.IWorkspace>; | ||
|
||
/** | ||
* setup module | ||
*/ | ||
beforeEach(angular.mock.module('userDashboard')); | ||
|
||
/** | ||
* Inject factory and http backend | ||
*/ | ||
beforeEach(inject(($rootScope: ng.IRootScopeService, cheWorkspace: CheWorkspace, cheAPIBuilder: CheAPIBuilder, cheHttpBackend: CheHttpBackend, $controller: any, ideSvc: IdeSvc, $window: ng.IWindowService, $log: ng.ILogService) => { | ||
apiBuilder = cheAPIBuilder; | ||
cheBackend = cheHttpBackend; | ||
httpBackend = cheHttpBackend.getHttpBackend(); | ||
|
||
let scope = $rootScope.$new(); | ||
navbarRecentWorkspacesController = $controller('NavbarRecentWorkspacesController', { | ||
ideSvc: IdeSvc, cheWorkspace: cheWorkspace, $window: $window, $log: $log, $scope: scope, $rootScope: $rootScope | ||
}); | ||
|
||
workspaces = []; | ||
for (let i = 0; i < 20; ++i) { | ||
let wrkspId = 'workspaceId' + i; | ||
let wrkspName = 'testName' + i; | ||
let wrkspCreateDate = new Date(2001, 1, 1, i, 1).toString(); | ||
let wrkspUpdateDate = new Date(2001, 1, 1, i, 2).toString(); | ||
let wrkspAttr = {'created': Date.parse(wrkspCreateDate), 'updated': Date.parse(wrkspUpdateDate)}; | ||
let workspace = apiBuilder.getWorkspaceBuilder().withId(wrkspId).withAttributes(wrkspAttr).withName(wrkspName).build(); | ||
workspaces.push(workspace); | ||
} | ||
// shuffle the workspaces | ||
workspaces.sort(() => { | ||
return 0.5 - Math.random(); | ||
}); | ||
// providing request | ||
// add workspaces on Http backend | ||
cheBackend.addWorkspaces(workspaces); | ||
|
||
// setup backend | ||
cheBackend.setup(); | ||
|
||
// fetch workspaces | ||
cheWorkspace.fetchWorkspaces(); | ||
|
||
// flush command | ||
httpBackend.flush(); | ||
})); | ||
|
||
/** | ||
* Check assertion after the test | ||
*/ | ||
afterEach(() => { | ||
httpBackend.verifyNoOutstandingExpectation(); | ||
httpBackend.verifyNoOutstandingRequest(); | ||
}); | ||
|
||
/** | ||
* Check sorting rule for recent workspaces | ||
*/ | ||
it('Check very recent workspaces', inject(() => { | ||
// get recentWorkspaces | ||
let recentWorkspaces = navbarRecentWorkspacesController.getRecentWorkspaces(); | ||
|
||
// check max length | ||
expect(recentWorkspaces.length).toEqual(navbarRecentWorkspacesController.maxItemsNumber); | ||
|
||
// prepare test objects | ||
let testWorkspaces: Array<che.IWorkspace> = angular.copy(workspaces); | ||
testWorkspaces.sort((workspace1: che.IWorkspace, workspace2: che.IWorkspace) => { | ||
return workspace2.attributes.updated - workspace1.attributes.updated; | ||
}); | ||
let veryRecentWorkspaceId = testWorkspaces[testWorkspaces.length - 1].id; | ||
|
||
// check default sorting | ||
let lastPosition = recentWorkspaces.length - 1; | ||
for (let i = 0; i < lastPosition; i++) { | ||
expect(recentWorkspaces[i].id).toEqual(testWorkspaces[i].id); | ||
} | ||
// check the last one workspace is equal to the last test workspace and not equal to the very recent workspace, | ||
// because we are going to update very recent workspace in controller and sorting rule should be changed | ||
expect(recentWorkspaces[lastPosition].id).toEqual(testWorkspaces[lastPosition].id); | ||
expect(recentWorkspaces[lastPosition].id).not.toEqual(veryRecentWorkspaceId); | ||
|
||
// update very recent workspace | ||
navbarRecentWorkspacesController.updateRecentWorkspace(veryRecentWorkspaceId); | ||
recentWorkspaces = navbarRecentWorkspacesController.getRecentWorkspaces(); | ||
|
||
// check sorting with veryRecentWorkspace | ||
for (let i = 0; i < lastPosition; i++) { | ||
expect(recentWorkspaces[i].id).toEqual(testWorkspaces[i].id); | ||
} | ||
// check the last one workspace is equal to the very recent workspace and not equal to the last test workspace | ||
expect(recentWorkspaces[lastPosition].id).not.toEqual(testWorkspaces[lastPosition].id); | ||
expect(recentWorkspaces[lastPosition].id).toEqual(veryRecentWorkspaceId); | ||
}) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters