mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 04:34:23 -06:00
Merge branch 'develop' of github.com:grafana/grafana into develop
This commit is contained in:
commit
59ea19e03b
@ -61,10 +61,19 @@ export class OrgSwitchCtrl {
|
||||
}
|
||||
|
||||
setUsingOrg(org) {
|
||||
this.backendSrv.post('/api/user/using/' + org.orgId).then(() => {
|
||||
window.location.href = window.location.href;
|
||||
return this.backendSrv.post('/api/user/using/' + org.orgId).then(() => {
|
||||
const re = /orgId=\d+/gi;
|
||||
this.setWindowLocationHref(this.getWindowLocationHref().replace(re, 'orgId=' + org.orgId));
|
||||
});
|
||||
}
|
||||
|
||||
getWindowLocationHref() {
|
||||
return window.location.href;
|
||||
}
|
||||
|
||||
setWindowLocationHref(href: string) {
|
||||
window.location.href = href;
|
||||
}
|
||||
}
|
||||
|
||||
export function orgSwitcher() {
|
||||
|
38
public/app/core/specs/org_switcher.jest.ts
Normal file
38
public/app/core/specs/org_switcher.jest.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import {OrgSwitchCtrl} from '../components/org_switcher';
|
||||
import q from 'q';
|
||||
|
||||
jest.mock('app/core/services/context_srv', () => ({
|
||||
contextSrv: {
|
||||
user: {orgId: 1}
|
||||
}
|
||||
}));
|
||||
|
||||
describe('OrgSwitcher', () => {
|
||||
describe('when switching org', () => {
|
||||
let expectedHref;
|
||||
let expectedUsingUrl;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
const backendSrvStub: any = {
|
||||
get: (url) => { return q.resolve([]); },
|
||||
post: (url) => { expectedUsingUrl = url; return q.resolve({}); }
|
||||
};
|
||||
|
||||
const orgSwitcherCtrl = new OrgSwitchCtrl(backendSrvStub);
|
||||
|
||||
orgSwitcherCtrl.getWindowLocationHref = () => 'http://localhost:3000?orgId=1';
|
||||
orgSwitcherCtrl.setWindowLocationHref = (href) => expectedHref = href;
|
||||
|
||||
return orgSwitcherCtrl.setUsingOrg({orgId: 2});
|
||||
});
|
||||
|
||||
it('should switch orgId in call to backend', () => {
|
||||
expect(expectedUsingUrl).toBe('/api/user/using/2');
|
||||
});
|
||||
|
||||
it('should switch orgId in url', () => {
|
||||
expect(expectedHref).toBe('http://localhost:3000?orgId=2');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user