team_details_ctrl_specs.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import '../team_details_ctrl';
  2. import {describe, beforeEach, it, expect, sinon, angularMocks} from 'test/lib/common';
  3. import TeamDetailsCtrl from '../team_details_ctrl';
  4. describe('TeamDetailsCtrl', () => {
  5. var ctx: any = {};
  6. var backendSrv = {
  7. searchUsers: sinon.stub().returns(Promise.resolve([])),
  8. get: sinon.stub().returns(Promise.resolve([])),
  9. post: sinon.stub().returns(Promise.resolve([]))
  10. };
  11. beforeEach(angularMocks.module('grafana.core'));
  12. beforeEach(angularMocks.module('grafana.controllers'));
  13. beforeEach(angularMocks.inject(($rootScope, $controller, $q) => {
  14. ctx.$q = $q;
  15. ctx.scope = $rootScope.$new();
  16. ctx.ctrl = $controller(TeamDetailsCtrl, {
  17. $scope: ctx.scope,
  18. backendSrv: backendSrv,
  19. $routeParams: {id: 1},
  20. navModelSrv: {getNav: sinon.stub()}
  21. });
  22. }));
  23. describe('when user is chosen to be added to team', () => {
  24. beforeEach(() => {
  25. const userItem = {
  26. id: 2,
  27. login: 'user2',
  28. };
  29. ctx.ctrl.userPicked(userItem);
  30. });
  31. it('should parse the result and save to db', () => {
  32. expect(backendSrv.post.getCall(0).args[0]).to.eql('/api/teams/1/members');
  33. expect(backendSrv.post.getCall(0).args[1].userId).to.eql(2);
  34. });
  35. it('should refresh the list after saving.', () => {
  36. expect(backendSrv.get.getCall(0).args[0]).to.eql('/api/teams/1');
  37. expect(backendSrv.get.getCall(1).args[0]).to.eql('/api/teams/1/members');
  38. });
  39. });
  40. });