-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 1.3] Switch to new tenant after loading a copied long URL (#…
…1450) (#1517) * Switch to new tenant after loading a copied long URL (#1450) Signed-off-by: leanneeliatra <leanne.laceybyrne@eliatra.com> Signed-off-by: Darshit Chanpura <dchanp@amazon.com> Signed-off-by: Darshit Chanpura <35282393+DarshitChanpura@users.noreply.github.com> Co-authored-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com>
- Loading branch information
1 parent
b914ecf
commit 390fd60
Showing
3 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import { reloadAfterTenantSwitch } from '../account-nav-button'; | ||
|
||
describe('Reload window after tenant switch', () => { | ||
const originalLocation = window.location; | ||
const mockSetWindowHref = jest.fn(); | ||
let pathname: string = ''; | ||
beforeAll(() => { | ||
pathname = '/app/myapp'; | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
get pathname() { | ||
return pathname; | ||
}, | ||
get href() { | ||
return '/app/dashboards?security_tenant=admin_tenant'; | ||
}, | ||
set href(value: string) { | ||
mockSetWindowHref(value); | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
window.location = originalLocation; | ||
}); | ||
|
||
it('should remove the tenant query parameter before reloading', () => { | ||
pathname = '/app/pathname-only'; | ||
reloadAfterTenantSwitch(); | ||
expect(mockSetWindowHref).toHaveBeenCalledWith(pathname); | ||
}); | ||
}); | ||
|
||
describe('Clear lastUrls after tenant switch', () => { | ||
afterAll(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should clear out keys with a lastUrl prefix', () => { | ||
window.sessionStorage.setItem('lastUrl:dashboard', '/dashboard1'); | ||
window.sessionStorage.setItem('lastUrl:otherApp', '/otherApp'); | ||
window.sessionStorage.setItem('somethingElse:here', '/random'); | ||
const mockRemoveItem = jest.spyOn(Object.getPrototypeOf(window.sessionStorage), 'removeItem'); | ||
reloadAfterTenantSwitch(); | ||
expect(mockRemoveItem).toHaveBeenCalledWith('lastUrl:dashboard'); | ||
expect(mockRemoveItem).toHaveBeenCalledWith('lastUrl:otherApp'); | ||
expect(mockRemoveItem).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it('should not clear out keys without a lastUrl prefix', () => { | ||
window.sessionStorage.setItem('somethingElse:here', '/random'); | ||
const mockRemoveItem = jest.spyOn(Object.getPrototypeOf(window.sessionStorage), 'removeItem'); | ||
|
||
reloadAfterTenantSwitch(); | ||
expect(mockRemoveItem).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |