org_switcher.jest.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. describe('OrgSwitcher', () => {
  9. describe('when switching org', () => {
  10. let expectedHref;
  11. let expectedUsingUrl;
  12. beforeEach(() => {
  13. const backendSrvStub: any = {
  14. get: url => {
  15. return q.resolve([]);
  16. },
  17. post: url => {
  18. expectedUsingUrl = url;
  19. return q.resolve({});
  20. },
  21. };
  22. const orgSwitcherCtrl = new OrgSwitchCtrl(backendSrvStub);
  23. orgSwitcherCtrl.getWindowLocationHref = () => 'http://localhost:3000?orgId=1&from=now-3h&to=now';
  24. orgSwitcherCtrl.setWindowLocationHref = href => (expectedHref = href);
  25. return orgSwitcherCtrl.setUsingOrg({ orgId: 2 });
  26. });
  27. it('should switch orgId in call to backend', () => {
  28. expect(expectedUsingUrl).toBe('/api/user/using/2');
  29. });
  30. it('should switch orgId in url', () => {
  31. expect(expectedHref).toBe('http://localhost:3000?orgId=2&from=now-3h&to=now');
  32. });
  33. });
  34. });