org_switcher.test.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { OrgSwitchCtrl } from '../components/org_switcher';
  2. import q from 'q';
  3. jest.mock('app/core/services/context_srv', () => ({
  4. contextSrv: {
  5. user: { orgId: 1 },
  6. },
  7. }));
  8. jest.mock('app/core/config', () => {
  9. return {
  10. appSubUrl: '/subUrl',
  11. };
  12. });
  13. describe('OrgSwitcher', () => {
  14. describe('when switching org', () => {
  15. let expectedHref;
  16. let expectedUsingUrl;
  17. beforeEach(() => {
  18. const backendSrvStub: any = {
  19. get: url => {
  20. return q.resolve([]);
  21. },
  22. post: url => {
  23. expectedUsingUrl = url;
  24. return q.resolve({});
  25. },
  26. };
  27. const orgSwitcherCtrl = new OrgSwitchCtrl(backendSrvStub);
  28. orgSwitcherCtrl.setWindowLocation = href => (expectedHref = href);
  29. return orgSwitcherCtrl.setUsingOrg({ orgId: 2 });
  30. });
  31. it('should switch orgId in call to backend', () => {
  32. expect(expectedUsingUrl).toBe('/api/user/using/2');
  33. });
  34. it('should switch orgId in url and redirect to home page', () => {
  35. expect(expectedHref).toBe('/subUrl/?orgId=2');
  36. });
  37. });
  38. });