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
9 changes: 6 additions & 3 deletions src/pages/home/ForYouSection/ConciergePromptBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {isSafari} from '@libs/Browser';
import {canSkipTriggerHotkeys} from '@libs/ComposerUtils';
import DateUtils from '@libs/DateUtils';
import getButtonState from '@libs/getButtonState';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';

import SubmitDraftButton from '@pages/inbox/report/ReportActionCompose/SubmitDraftButton';

Expand Down Expand Up @@ -117,8 +118,10 @@ function ConciergePromptBox({isMenuVisible, setIsMenuVisible}: ConciergePromptBo
if (!canSubmit) {
return;
}
askConcierge(value);
clearInput();
interceptAnonymousUser(() => {
askConcierge(value);
clearInput();
});
};

const handleKeyPress = (event: TextInputKeyPressEvent) => {
Expand Down Expand Up @@ -163,7 +166,7 @@ function ConciergePromptBox({isMenuVisible, setIsMenuVisible}: ConciergePromptBo
onPress={(e) => {
e?.preventDefault();
actionButtonRef.current?.blur();
setIsMenuVisible((prev) => !prev);
interceptAnonymousUser(() => setIsMenuVisible((prev) => !prev));
}}
style={({hovered, pressed}) => [
styles.composerSizeButton,
Expand Down
53 changes: 53 additions & 0 deletions tests/ui/ConciergePromptBoxTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {isSafari} from '@libs/Browser';
import ConciergePromptBox from '@pages/home/ForYouSection/ConciergePromptBox';

import {close} from '@userActions/Modal';
import {isAnonymousUser, signOutAndRedirectToSignIn} from '@userActions/Session';

import CONST from '@src/CONST';
import type {FileObject} from '@src/types/utils/Attachment';
Expand Down Expand Up @@ -88,11 +89,18 @@ jest.mock('@userActions/Modal', () => ({
close: jest.fn(),
}));

jest.mock('@userActions/Session', () => ({
isAnonymousUser: jest.fn(() => false),
signOutAndRedirectToSignIn: jest.fn(),
}));

const mockUseAskConcierge = jest.mocked(useAskConcierge);
const mockUseResponsiveLayout = jest.mocked(useResponsiveLayout);
const mockUseKeyboardState = jest.mocked(useKeyboardState);
const mockIsSafari = jest.mocked(isSafari);
const mockClose = jest.mocked(close);
const mockIsAnonymousUser = jest.mocked(isAnonymousUser);
const mockSignOutAndRedirectToSignIn = jest.mocked(signOutAndRedirectToSignIn);

function ConciergePromptBoxWrapper() {
const [isMenuVisible, setIsMenuVisible] = useState(false);
Expand Down Expand Up @@ -162,6 +170,7 @@ describe('ConciergePromptBox', () => {
setResponsiveLayout(false);
setKeyboardShown(false);
mockIsSafari.mockReturnValue(false);
mockIsAnonymousUser.mockReturnValue(false);
});

describe('sending a message', () => {
Expand Down Expand Up @@ -310,6 +319,50 @@ describe('ConciergePromptBox', () => {
});
});

describe('anonymous user', () => {
beforeEach(() => {
mockIsAnonymousUser.mockReturnValue(true);
});

it('asks to sign in instead of sending on the send button', () => {
// Given an anonymous user with a typed message
render(<ConciergePromptBoxWrapper />);
fireEvent.changeText(getInput(), 'Where is my expense?');

// When the send button is pressed
fireEvent.press(screen.getByLabelText(SEND_BUTTON));

// Then nothing is sent and the sign in flow opens
expect(mockAskConcierge).not.toHaveBeenCalled();
expect(mockSignOutAndRedirectToSignIn).toHaveBeenCalled();
});

it('asks to sign in instead of sending on Enter', () => {
// Given an anonymous user with a typed message
render(<ConciergePromptBoxWrapper />);
fireEvent.changeText(getInput(), 'Where is my expense?');

// When Enter is pressed
pressEnter();

// Then nothing is sent and the sign in flow opens
expect(mockAskConcierge).not.toHaveBeenCalled();
expect(mockSignOutAndRedirectToSignIn).toHaveBeenCalled();
});

it('asks to sign in instead of opening the actions menu', () => {
// Given an anonymous user
render(<ConciergePromptBoxWrapper />);

// When the "+" button is pressed
fireEvent.press(screen.getByLabelText(PLUS_BUTTON));

// Then the menu stays closed and the sign in flow opens
expect(screen.queryByLabelText(ADD_ATTACHMENT)).toBeNull();
expect(mockSignOutAndRedirectToSignIn).toHaveBeenCalled();
});
});

describe('placeholder', () => {
it('uses the long copy only once it is known to fit one line', () => {
// Given a wide layout
Expand Down
Loading