team_details_ctrl_specs.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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(
  14. angularMocks.inject(($rootScope, $controller, $q) => {
  15. ctx.$q = $q;
  16. ctx.scope = $rootScope.$new();
  17. ctx.ctrl = $controller(TeamDetailsCtrl, {
  18. $scope: ctx.scope,
  19. backendSrv: backendSrv,
  20. $routeParams: { id: 1 },
  21. navModelSrv: { getNav: sinon.stub() },
  22. });
  23. })
  24. );
  25. describe('when user is chosen to be added to team', () => {
  26. beforeEach(() => {
  27. const userItem = {
  28. id: 2,
  29. login: 'user2',
  30. };
  31. ctx.ctrl.userPicked(userItem);
  32. });
  33. it('should parse the result and save to db', () => {
  34. expect(backendSrv.post.getCall(0).args[0]).to.eql('/api/teams/1/members');
  35. expect(backendSrv.post.getCall(0).args[1].userId).to.eql(2);
  36. });
  37. it('should refresh the list after saving.', () => {
  38. expect(backendSrv.get.getCall(0).args[0]).to.eql('/api/teams/1');
  39. expect(backendSrv.get.getCall(1).args[0]).to.eql('/api/teams/1/members');
  40. });
  41. });
  42. });