mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-03-22 19:05:56 -04:00
Fix admin panel space remaining after logging out
This commit is contained in:
parent
03ce4470a4
commit
1cace60ebd
2 changed files with 19 additions and 2 deletions
|
@ -48,8 +48,11 @@ const StudioAdminPanel = ({studioId, showAdminPanel}) => {
|
|||
const [adminPanelOpen, setAdminPanelOpen] = useState(getAdminPanelOpen());
|
||||
|
||||
useEffect(() => {
|
||||
storeAdminPanelOpen(adminPanelOpen);
|
||||
}, [adminPanelOpen]);
|
||||
// This effect will both keep localStorage up-to-date AND cause
|
||||
// the spacing to change to allow for the open admin panel, so make
|
||||
// sure the admin panel should be visible at all before making any changes.
|
||||
if (showAdminPanel) storeAdminPanelOpen(adminPanelOpen);
|
||||
}, [showAdminPanel, adminPanelOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showAdminPanel) return;
|
||||
|
|
|
@ -39,6 +39,20 @@ describe('Studio comments', () => {
|
|||
expect(child.prop('isOpen')).toBe(false);
|
||||
});
|
||||
});
|
||||
describe('non admins', () => {
|
||||
test('should not have localStorage set with a false value', () => {
|
||||
mountWithIntl(<StudioAdminPanel showAdminPanel={false} />);
|
||||
expect(global.localStorage.getItem(adminPanelOpenKey)).toBe(null);
|
||||
});
|
||||
test('should not have css class set even if localStorage contains open key', () => {
|
||||
// Regression test for situation where admin logs out but localStorage still
|
||||
// contains "open", causing extra space to appear
|
||||
global.localStorage.setItem(adminPanelOpenKey, 'open');
|
||||
const component = mountWithIntl(<StudioAdminPanel showAdminPanel={false} />);
|
||||
const child = component.find(AdminPanel);
|
||||
expect(viewEl.classList.contains(adminPanelOpenClass)).toBe(false);
|
||||
});
|
||||
});
|
||||
test('calling onOpen sets a class on the #viewEl and records in local storage', () => {
|
||||
const component = mountWithIntl(<StudioAdminPanel showAdminPanel />);
|
||||
let child = component.find(AdminPanel);
|
||||
|
|
Loading…
Reference in a new issue