Skip to content

Instantly share code, notes, and snippets.

@erick2014
Last active April 23, 2018 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erick2014/b4621d517b9df3b25812edfcf25a3107 to your computer and use it in GitHub Desktop.
Save erick2014/b4621d517b9df3b25812edfcf25a3107 to your computer and use it in GitHub Desktop.
import clientThumbnailModule from './clientThumbnail'
import clientThumbnailController from './clientThumbnail.controller';
import clientThumbnailComponent from './clientThumbnail.component';
import clientThumbnailTemplate from './clientThumbnail.html';
describe('clientThumbnail', () => {
let $rootScope, $q, makeController;
beforeEach(window.module(clientThumbnailModule));
beforeEach(inject((_$rootScope_, _$q_) => {
$rootScope = _$rootScope_;
$q = _$q_;
makeController = (ClientFactory, $mdDialog, $state) => {
return new clientThumbnailController(ClientFactory, $mdDialog, $state);
};
}));
let ClientFactory = {
getClientId: () => {
return Symbol(':id');
},
getTiles: () => {
let tiles = [
{
"name": "CLIENT",
"iconUrl": "http://apvasclientportal.com/apvas-platform-api/session/bb021780-7f70-11e6-9818-29def4acb3e1/client/co_juliantest/icon",
"label": "JulianTest",
"redirect": false,
"actionUrl": "/client/co_juliantest",
"data": {
"id": "co_juliantest",
"commercialName": "JulianTest",
"companyName": "JulianTest",
"country": {"isoCode": "CO", "label": "Colombia"}
}
},
{
"name": "CLIENT",
"iconUrl": "http://apvasclientportal.com/apvas-platform-api/session/bb021780-7f70-11e6-9818-29def4acb3e1/client/do_orange/icon",
"label": "Orange",
"redirect": false,
"actionUrl": "/client/do_orange",
"data": {
"id": "do_orange", "commercialName": "Orange",
"companyName": "Orange",
"country": {"isoCode": "DO", "label": "República Dominicana"}
}
}];
return $q.resolve({data:tiles});
},
getClients: ()=> {
return $q.resolve([]);
}
},
$state={},
$mdDialog = {};
describe('Module', () => {
// top-level specs: i.e., routes, injection, naming
});
describe('Controller', () => {
// controller specs
it("should instantiate a ClientFactory", () => {
let controller = makeController(ClientFactory, $mdDialog, $state);
expect(controller.ClientFactory).to.not.be.undefined;
expect(controller.ClientFactory).to.be.an('object');
});
it('has a tiles property', () => {
let controller = makeController(ClientFactory, $mdDialog, $state);
expect(controller.tiles).to.be.undefined;
});
it('has a name property sortOptions', () => {
let controller = makeController(ClientFactory, $mdDialog, $state);
expect(controller).to.have.property('sortOptions');
});
it('sortOptions should have tree options ("Sort by","name","country")', () => {
let controller = makeController(ClientFactory, $mdDialog, $state);
expect(controller.sortOptions).to.be.an('object');
expect(controller.sortOptions).to.have.deep.property('Sort by');
expect(controller.sortOptions).to.have.deep.property('name');
expect(controller.sortOptions).to.have.deep.property('country');
});
it('sortOptions default values for ("Sort by","name","country") options', () => {
let controller = makeController(ClientFactory, $mdDialog, $state);
expect(controller.sortOptions).to.be.an('object');
expect(controller.sortOptions).to.have.deep.property('Sort by').to.be.a('string').equal('');
expect(controller.sortOptions).to.have.deep.property('name').to.be.a('string').equal('data.commercialName');
expect(controller.sortOptions).to.have.deep.property('country').to.be.a('string').equal('data.country.label');
});
it('should load tiles', ()=> {
let controller = makeController(ClientFactory, $mdDialog, $state);
//simulate a account manger controller
controller.accountManagerCtrl = {
showFeedback: (msj, time = 3000)=> {},
hideFeedback: () => { return $q.defer().promise; },
};
controller.loadTiles();
$rootScope.$digest();
expect(controller.tiles).not.to.be.undefined;
expect(controller.tiles).to.be.an('array');
});
});
describe('Component', () => {
// component/directive specs
let component = clientThumbnailComponent;
it('includes the intended template', () => {
expect(component.template).to.equal(clientThumbnailTemplate);
});
it('invokes the right controller', () => {
expect(component.controller).to.equal(clientThumbnailController);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment