Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
get ShareType test passing
Browse files Browse the repository at this point in the history
Signed-off-by: Kerry Archibald <[email protected]>
  • Loading branch information
Kerry Archibald committed Mar 1, 2022
1 parent 70504c9 commit 33bb372
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/components/views/location/LocationShareMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Props = Omit<ILocationPickerProps, 'onChoose'> & {
};

const useEnabledShareTypes = (): LocationShareType[] => {
const isPinDropLocationShareEnabled = SettingsStore.getValue("feature_location_share_pin_drop") || true;
const isPinDropLocationShareEnabled = SettingsStore.getValue("feature_location_share_pin_drop");

if (isPinDropLocationShareEnabled) {
return [LocationShareType.Own, LocationShareType.Pin];
Expand Down
25 changes: 11 additions & 14 deletions src/components/views/location/ShareType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

import React, { HTMLAttributes, useContext } from 'react';
import MatrixClientContext from '../../../contexts/MatrixClientContext';

import MatrixClientContext from '../../../contexts/MatrixClientContext';
import { _t } from '../../../languageHandler';
import { OwnProfileStore } from '../../../stores/OwnProfileStore';
import { getUserNameColorClass } from '../../../utils/FormattingUtils';
Expand All @@ -42,11 +42,9 @@ const UserAvatar = () => {
resizeMethod="crop"
className="mx_UserMenu_userAvatar_BaseAvatar"
/></div>;
}

const LocationPinIcon = () => <div className={`mx_ShareType_option-icon ${LocationShareType.Pin}`}>
</div>;
};

const LocationPinIcon = () => <div className={`mx_ShareType_option-icon ${LocationShareType.Pin}`} />;

// TODO this will be defined somewhere better
export enum LocationShareType {
Expand All @@ -64,11 +62,11 @@ const ShareTypeOption: React.FC<ShareTypeOptionProps> = ({
disabled={shareType !== LocationShareType.Own}
{...rest}>

{shareType === LocationShareType.Own && <UserAvatar />}
{shareType === LocationShareType.Pin && <LocationPinIcon />}
{ shareType === LocationShareType.Own && <UserAvatar /> }
{ shareType === LocationShareType.Pin && <LocationPinIcon /> }

{label}
</button>;
{ label }
</button>;

interface Props {
setShareType: (shareType: LocationShareType) => void;
Expand All @@ -83,18 +81,17 @@ const ShareType: React.FC<Props> = ({
[LocationShareType.Pin]: _t('Drop a Pin'),
};
return <div className='mx_ShareType'>
<div className='mx_ShareType_badge'>
</div>
<Heading className='mx_ShareType_heading' size='h3'>{_t("What location type do you want to share?")}</Heading>
{enabledShareTypes.map((type) =>
<div className='mx_ShareType_badge' />
<Heading className='mx_ShareType_heading' size='h3'>{ _t("What location type do you want to share?") }</Heading>
{ enabledShareTypes.map((type) =>
<ShareTypeOption
key={type}
onClick={() => setShareType(type)}
label={labels[type]}
shareType={type}
data-test-id={`share-location-option-${type}`}
/>,
)}
) }
</div>;
};

Expand Down
13 changes: 12 additions & 1 deletion test/components/views/location/LocationShareMenu-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,20 @@ jest.mock('../../../../src/settings/SettingsStore', () => ({
monitorSetting: jest.fn(),
}));

jest.mock('../../../../src/stores/OwnProfileStore', () => ({
OwnProfileStore: {
instance: {
displayName: 'Ernie',
getHttpAvatarUrl: jest.fn().mockReturnValue('image.com/img'),
},
},
}));

describe('<LocationShareMenu />', () => {
const userId = '@ernie:server.org';
const mockClient = {
on: jest.fn(),
getUserId: jest.fn().mockReturnValue(userId),
getClientWellKnown: jest.fn().mockResolvedValue({
map_style_url: 'maps.com',
}),
Expand All @@ -50,7 +61,7 @@ describe('<LocationShareMenu />', () => {
onFinished: jest.fn(),
openMenu: jest.fn(),
roomId: '!room:server.org',
sender: new RoomMember('!room:server.org', '@ernie:server.org'),
sender: new RoomMember('!room:server.org', userId),
};
const getComponent = (props = {}) =>
mount(<LocationShareMenu {...defaultProps} {...props} />, {
Expand Down
34 changes: 31 additions & 3 deletions test/components/views/location/ShareType-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,40 @@ import React from 'react';
import { mount } from 'enzyme';

import '../../../skinned-sdk';
import ShareType from '../../../../src/components/views/location/ShareType';
import ShareType, { LocationShareType } from '../../../../src/components/views/location/ShareType';
import MatrixClientContext from '../../../../src/contexts/MatrixClientContext';

jest.mock('../../../../src/stores/OwnProfileStore', () => ({
OwnProfileStore: {
instance: {
displayName: 'Ernie',
getHttpAvatarUrl: jest.fn().mockReturnValue('image.com/img'),
},
},
}));

describe('<ShareType />', () => {
const defaultProps = {};
const userId = '@ernie:server.org';
const mockClient = {
on: jest.fn(),
getUserId: jest.fn().mockReturnValue(userId),
getClientWellKnown: jest.fn().mockResolvedValue({
map_style_url: 'maps.com',
}),
};

const defaultProps = {
setShareType: jest.fn(),
enabledShareTypes: [
LocationShareType.Own,
LocationShareType.Pin,
],
};
const getComponent = (props = {}) =>
mount(<ShareType {...defaultProps} {...props} />);
mount(<ShareType {...defaultProps} {...props} />, {
wrappingComponent: MatrixClientContext.Provider,
wrappingComponentProps: { value: mockClient },
});

it('renders', () => {
const component = getComponent();
Expand Down

0 comments on commit 33bb372

Please sign in to comment.