Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Kurinnyi <[email protected]>
  • Loading branch information
akurinnoy committed Sep 4, 2019
1 parent 2ef0834 commit b5b70fc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {CheAPIBuilder} from '../../../components/api/builder/che-api-builder.fac
import {CheHttpBackend} from '../../../components/api/test/che-http-backend';
import IdeSvc from '../../ide/ide.service';
import {CheBranding} from '../../../components/branding/che-branding.factory';
import { NavbarRecentWorkspacesController } from './recent-workspaces.controller';

/**
* Test of the NavbarRecentWorkspacesController
Expand All @@ -23,7 +24,7 @@ describe('NavbarRecentWorkspacesController', () => {
/**
* NavbarRecentWorkspacesController
*/
let navbarRecentWorkspacesController;
let navbarRecentWorkspacesController: NavbarRecentWorkspacesController;

/**
* API builder
Expand Down Expand Up @@ -82,8 +83,7 @@ describe('NavbarRecentWorkspacesController', () => {
// setup backend
cheBackend.setup();

// fetch workspaces
cheWorkspace.fetchWorkspaces();
navbarRecentWorkspacesController.$onInit();

// flush command
httpBackend.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ describe(`WorkspaceDetailsController >`, () => {
}
subscriptions[workspaceId].push(action);
};
this.unsubscribeOnWorkspaceChange = (workspaceId: string, action: Function): void => {
const actions = subscriptions[workspaceId];
if (actions === undefined) {
return;
}
const index = actions.indexOf(action);
if (index === -1) {
return;
}
actions.splice(index, 1);
};
this.getWorkspaceById = (workspaceId: string): che.IWorkspace => {
return workspace;
};
Expand Down Expand Up @@ -286,7 +297,7 @@ describe(`WorkspaceDetailsController >`, () => {
describe(`overflow panel >`, () => {

function getOverlayPanelEl(): ng.IAugmentedJQuery {
return compiledDirective.find('.che-edit-mode-overlay');
return compiledDirective.find('che-edit-mode-overlay');
}
function getSaveButton(): ng.IAugmentedJQuery {
return compiledDirective.find('.save-button button');
Expand All @@ -300,7 +311,7 @@ describe(`WorkspaceDetailsController >`, () => {

it(`should be hidden initially >`, () => {
compileDirective();
expect(getOverlayPanelEl().length).toEqual(0);
expect(getOverlayPanelEl().children().length).toEqual(0);
});

describe(`when config is changed >`, () => {
Expand Down Expand Up @@ -343,7 +354,7 @@ describe(`WorkspaceDetailsController >`, () => {
});

it(`the overlay panel should be hidden >`, () => {
expect(getOverlayPanelEl().length).toEqual(0);
expect(getOverlayPanelEl().children().length).toEqual(0);
});

});
Expand All @@ -360,7 +371,7 @@ describe(`WorkspaceDetailsController >`, () => {
});

it(`the overlay panel should be hidden >`, () => {
expect(getOverlayPanelEl().length).toEqual(0);
expect(getOverlayPanelEl().children().length).toEqual(0);
});

});
Expand Down Expand Up @@ -403,7 +414,7 @@ describe(`WorkspaceDetailsController >`, () => {
});

it(`the overlay panel should be hidden >`, () => {
expect(getOverlayPanelEl().length).toEqual(0);
expect(getOverlayPanelEl().children().length).toEqual(0);
});

});
Expand Down Expand Up @@ -446,7 +457,7 @@ describe(`WorkspaceDetailsController >`, () => {
});

it(`the overlay panel should be hidden >`, () => {
expect(getOverlayPanelEl().length).toEqual(0);
expect(getOverlayPanelEl().children().length).toEqual(0);
});

});
Expand Down Expand Up @@ -497,7 +508,7 @@ describe(`WorkspaceDetailsController >`, () => {
});

it(`the overlay panel should be hidden >`, () => {
expect(getOverlayPanelEl().length).toEqual(0);
expect(getOverlayPanelEl().children().length).toEqual(0);
});

});
Expand All @@ -514,7 +525,7 @@ describe(`WorkspaceDetailsController >`, () => {
});

it(`the overlay panel should be hidden >`, () => {
expect(getOverlayPanelEl().length).toEqual(0);
expect(getOverlayPanelEl().children().length).toEqual(0);
});

});
Expand Down Expand Up @@ -554,7 +565,7 @@ describe(`WorkspaceDetailsController >`, () => {
});

it(`the overlay panel should be hidden >`, () => {
expect(getOverlayPanelEl().length).toEqual(0);
expect(getOverlayPanelEl().children().length).toEqual(0);
});

});
Expand All @@ -571,7 +582,7 @@ describe(`WorkspaceDetailsController >`, () => {
});

it(`the overlay panel should be hidden >`, () => {
expect(getOverlayPanelEl().length).toEqual(0);
expect(getOverlayPanelEl().children().length).toEqual(0);
});

});
Expand All @@ -589,7 +600,7 @@ describe(`WorkspaceDetailsController >`, () => {
.and
.callFake(() => {
return false;
});
});
controller.workspacesService.isSupportedRecipeType = jasmine.createSpy('workspaceDetailsController.isSupportedRecipeType')
.and
.callFake(() => {
Expand Down Expand Up @@ -627,7 +638,7 @@ describe(`WorkspaceDetailsController >`, () => {
});

it(`the overlay panel should be hidden >`, () => {
expect(getOverlayPanelEl().length).toEqual(0);
expect(getOverlayPanelEl().children().length).toEqual(0);
});

});
Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/components/api/che-team.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export class CheTeam implements che.api.ICheTeam {
cheTeamEventsManager.addNewTeamHandler(() => {
this.fetchTeams();
});

this.fetchTeams(); // this resolves `cheNamespaceRegistry.fetchNamespaces()` as well
}

/**
Expand Down
4 changes: 4 additions & 0 deletions dashboard/src/components/api/test/che-http-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export class CheHttpBackend {
* Setup all data that should be retrieved on calls
*/
setup(): void {
this.$httpBackend.when('GET', '/api/oauth/').respond(200, []);
this.$httpBackend.when('GET', 'https://api.github.com/user/orgs').respond(200, {});
this.$httpBackend.when('GET', 'https://api.github.com/user').respond(200, {});

this.$httpBackend.when('OPTIONS', '/api/').respond({});
this.$httpBackend.when('GET', '/api/').respond(200, {rootResources: []});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export class UniqueFactoryNameValidator implements ng.IDirective {
} else {
deferred.resolve(true);
}
}).catch(() => {
// this fixes unit test for the directive
});
}

Expand Down

0 comments on commit b5b70fc

Please sign in to comment.