Fix TabsAndPanelsController now that #! are removed from url

This PR https://github.com/openfoodfoundation/openfoodnetwork/pull/9729
remove #! from url. But unfortunately, AngularJs rewrite "example.com#panel"
as "example.com#/panel" thus breaking the original implementation.
This commit is contained in:
Gaetan Craig-Riou
2023-03-24 14:28:29 +11:00
parent 2e10336a47
commit e1845dddac
2 changed files with 8 additions and 2 deletions

View File

@@ -15,9 +15,15 @@ export default class extends Controller {
// Display panel specified in url anchor
const anchors = window.location.toString().split("#");
const anchor = anchors.length > 1 ? anchors.pop() : "";
let anchor = anchors.length > 1 ? anchors.pop() : "";
if (anchor != "") {
// Conveniently AngularJs rewrite "example.com#panel" to "example.com#/panel" :(
// strip the starting / if any
if (anchor[0] == "/") {
anchor = anchor.slice(1);
}
this.updateActivePanel(anchor);
// tab

View File

@@ -87,7 +87,7 @@ describe('TabsAndPanelsController', () => {
const { location } = window;
const mockLocationToString = (panel) => {
// Mocking window.location.toString()
const url = `http://localhost:3000/admin/enterprises/great-shop/edit#!#${panel}`
const url = `http://localhost:3000/admin/enterprises/great-shop/edit#/${panel}`
const mockedToString = jest.fn()
mockedToString.mockImplementation(() => (url))