Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/SidePanel/SidePanelContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function SidePanelContextProvider({children}: PropsWithChildren) {
const sidePanelWidth = shouldUseNarrowLayout ? windowWidth : dockedSidePanelWidth;

const [isSidePanelTransitionEnded, setIsSidePanelTransitionEnded] = useState(true);
const [isSidePanelClosing, setIsSidePanelClosing] = useState(false);
const {shouldHideSidePanel, shouldHideSidePanelBackdrop, shouldHideHelpButton, isSidePanelHiddenOrLargeScreen, sidePanelNVP} = useSidePanelDisplayStatus();
const shouldHideToolTip = isExtraLargeScreenWidth ? !isSidePanelTransitionEnded : !shouldHideSidePanel;

Expand Down Expand Up @@ -119,6 +120,8 @@ function SidePanelContextProvider({children}: PropsWithChildren) {

if (prevShouldHideSidePanel !== shouldHideSidePanel) {
setPrevShouldHideSidePanel(shouldHideSidePanel);
// The closed Onyx value arrives before the slide-out ends, so keep Help hidden until the animation completes.
setIsSidePanelClosing(shouldHideSidePanel);
if (!shouldHideSidePanel && !sessionStartTime) {
setSessionStartTime(getServerAnchoredDBTime());
}
Expand Down Expand Up @@ -157,6 +160,9 @@ function SidePanelContextProvider({children}: PropsWithChildren) {
}),
]).start(({finished}) => {
setIsSidePanelTransitionEnded(true);
if (finished) {
setIsSidePanelClosing(false);
}
// Clear the session after the slide-out, not when it starts: the panel stays mounted for the animation and
// a null session empties its message list. `finished` is false on an interrupted close, sparing the new session.
if (finished && shouldHideSidePanel) {
Expand Down Expand Up @@ -194,7 +200,7 @@ function SidePanelContextProvider({children}: PropsWithChildren) {
isSidePanelHiddenOrLargeScreen,
shouldHideSidePanel,
shouldHideSidePanelBackdrop,
shouldHideHelpButton,
shouldHideHelpButton: shouldHideHelpButton || isSidePanelClosing,
shouldHideToolTip,
sidePanelOffset,
sidePanelTranslateX,
Expand Down
95 changes: 92 additions & 3 deletions tests/unit/SidePanelSessionStartTimeTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

jest.mock('@hooks/useSidePanelDisplayStatus');

let mockIsExtraLargeScreenWidth = false;
jest.mock('@hooks/useResponsiveLayout', () => () => ({shouldUseNarrowLayout: false, isExtraLargeScreenWidth: mockIsExtraLargeScreenWidth}));

const mockUseSidePanelDisplayStatus = jest.mocked(useSidePanelDisplayStatus);

/** Drives the only input the provider's session logic reacts to, so the test needs no navigator and no viewport. */
function setSidePanelHidden(shouldHideSidePanel: boolean) {
function setSidePanelHidden(shouldHideSidePanel: boolean, shouldHideHelpButton = !shouldHideSidePanel) {
mockUseSidePanelDisplayStatus.mockReturnValue({
sidePanelNVP: {open: !shouldHideSidePanel, openNarrowScreen: false, forceConcierge: false},
shouldHideSidePanel,
isSidePanelHiddenOrLargeScreen: shouldHideSidePanel,
shouldHideHelpButton: !shouldHideSidePanel,
shouldHideHelpButton,
shouldHideSidePanelBackdrop: true,
});
}
Expand Down Expand Up @@ -68,7 +71,7 @@ function wrapper({children}: PropsWithChildren) {
return <SidePanelContextProvider>{children}</SidePanelContextProvider>;
}

describe('SidePanelContextProvider (Concierge session lifetime)', () => {
describe('SidePanelContextProvider (Concierge session lifetime and Help visibility)', () => {
beforeAll(() => {
Onyx.init({keys: ONYXKEYS});
});
Expand All @@ -77,6 +80,7 @@ describe('SidePanelContextProvider (Concierge session lifetime)', () => {
await Onyx.clear();
await waitForBatchedUpdates();
jest.restoreAllMocks();
mockIsExtraLargeScreenWidth = false;
setSidePanelHidden(true);
});

Expand Down Expand Up @@ -129,4 +133,89 @@ describe('SidePanelContextProvider (Concierge session lifetime)', () => {
finishInterruptedClose(false);
expect(result.current.sessionStartTime).toBe(openSessionStartTime);
});

it('keeps Help visible on initial mount while the hidden panel runs its initial animation', () => {
// Given a hidden panel whose mount animation has not finished
const takeLatestSlide = mockSlideAnimation();

// When the provider mounts
const {result} = renderHook(() => useSidePanelState(), {wrapper});

// Then Help is visible both before and after that no-op animation
expect(result.current.isSidePanelTransitionEnded).toBe(false);
expect(result.current.shouldHideHelpButton).toBe(false);
takeLatestSlide()(true);
expect(result.current.shouldHideHelpButton).toBe(false);
});

it('keeps Help hidden for the whole close animation and shows it after completion', () => {
// Given an open panel with its opening animation completed
const takeLatestSlide = mockSlideAnimation();
setSidePanelHidden(false);
const {result, rerender} = renderHook(() => useSidePanelState(), {wrapper});
takeLatestSlide()(true);

// When Onyx marks the panel closed before the slide-out finishes
setSidePanelHidden(true);
rerender({});

// Then Help stays hidden until the closing panel has left the screen
expect(result.current.shouldHideSidePanel).toBe(true);
expect(result.current.shouldHideHelpButton).toBe(true);
takeLatestSlide()(true);
expect(result.current.shouldHideHelpButton).toBe(false);
});

it('keeps Help visible when the hidden panel crosses the extra-large breakpoint', () => {
// Given a hidden panel with Help visible
const takeLatestSlide = mockSlideAnimation();
const {result, rerender} = renderHook(() => useSidePanelState(), {wrapper});
takeLatestSlide()(true);

// When the viewport crosses the breakpoint without opening the panel
mockIsExtraLargeScreenWidth = true;
rerender({});

// Then Help does not disappear on resize
expect(result.current.shouldHideHelpButton).toBe(false);
});

it('does not let an interrupted slide reveal Help during a subsequent close', () => {
// Given a close animation interrupted by reopening the panel
const takeLatestSlide = mockSlideAnimation();
setSidePanelHidden(false);
const {result, rerender} = renderHook(() => useSidePanelState(), {wrapper});
takeLatestSlide()(true);
setSidePanelHidden(true);
rerender({});
const finishInterruptedClose = takeLatestSlide();
setSidePanelHidden(false);
rerender({});

// When another close starts before the interrupted callback arrives
setSidePanelHidden(true);
rerender({});
finishInterruptedClose(false);

// Then only the completed current close can reveal Help
expect(result.current.shouldHideHelpButton).toBe(true);
takeLatestSlide()(true);
expect(result.current.shouldHideHelpButton).toBe(false);
});

it('preserves the display hook restrictions after the close animation', () => {
// Given an open panel on a screen where Help must remain hidden
const takeLatestSlide = mockSlideAnimation();
setSidePanelHidden(false);
const {result, rerender} = renderHook(() => useSidePanelState(), {wrapper});
takeLatestSlide()(true);

// When the panel closes but another restriction still hides Help
setSidePanelHidden(true, true);
rerender({});
takeLatestSlide()(true);

// Then finishing the animation does not override the existing restriction
expect(result.current.shouldHideHelpButton).toBe(true);
});
});
Loading