org_switcher.jest.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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) => { return q.resolve([]); },
  15. post: (url) => { expectedUsingUrl = url; return q.resolve({}); }
  16. };
  17. const orgSwitcherCtrl = new OrgSwitchCtrl(backendSrvStub);
  18. orgSwitcherCtrl.getWindowLocationHref = () => 'http://localhost:3000?orgId=1';
  19. orgSwitcherCtrl.setWindowLocationHref = (href) => expectedHref = href;
  20. return orgSwitcherCtrl.setUsingOrg({orgId: 2});
  21. });
  22. it('should switch orgId in call to backend', () => {
  23. expect(expectedUsingUrl).toBe('/api/user/using/2');
  24. });
  25. it('should switch orgId in url', () => {
  26. expect(expectedHref).toBe('http://localhost:3000?orgId=2');
  27. });
  28. });
  29. });