diff --git a/app/constants/view.ts b/app/constants/view.ts index d42ab6914..5e77b1996 100644 --- a/app/constants/view.ts +++ b/app/constants/view.ts @@ -5,6 +5,9 @@ import {Platform} from 'react-native'; export const BOTTOM_TAB_HEIGHT = 52; export const BOTTOM_TAB_ICON_SIZE = 31.2; +export const BOTTOM_TAB_PROFILE_PHOTO_SIZE = 22; +export const BOTTOM_TAB_STATUS_SIZE = 12; + export const PROFILE_PICTURE_SIZE = 32; export const PROFILE_PICTURE_EMOJI_SIZE = 28; diff --git a/app/screens/home/tab_bar/account.test.tsx b/app/screens/home/tab_bar/account.test.tsx new file mode 100644 index 000000000..e73514dcc --- /dev/null +++ b/app/screens/home/tab_bar/account.test.tsx @@ -0,0 +1,93 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. +import React from 'react'; + +import {BOTTOM_TAB_PROFILE_PHOTO_SIZE, BOTTOM_TAB_STATUS_SIZE} from '@constants/view'; +import {renderWithEverything, renderWithIntl} from '@test/intl-test-helper'; +import TestHelper from '@test/test_helper'; +import {changeOpacity} from '@utils/theme'; + +import {Account, default as AccountWithDatabaseObservable} from './account'; + +import type {UserModel} from '@database/models/server'; +import type Database from '@nozbe/watermelondb/Database'; + +jest.mock('@components/profile_picture', () => 'ProfilePicture'); + +const currentUser = { + id: 'user1', + username: 'testuser', +} as UserModel; + +const theme = { + buttonBg: '#000', + centerChannelColor: '#fff', +} as Theme; + +describe('Account', () => { + const centerChannelColorWithOpacity = changeOpacity(theme.centerChannelColor, 0.48); + + it('should render correctly when focused', () => { + const wrapper = renderWithIntl( + , + ); + + const container = wrapper.getByTestId('account-container'); + expect(container.props.style).toContainEqual({borderColor: theme.buttonBg}); + }); + + it('should render correctly when unfocused', () => { + const {getByTestId} = renderWithIntl( + , + ); + + const container = getByTestId('account-container'); + expect(container.props.style).toContainEqual({borderColor: centerChannelColorWithOpacity}); + }); + + it('should render ProfilePicture with correct props', () => { + const {getByTestId} = renderWithIntl( + , + ); + + const profilePicture = getByTestId('account-profile-picture'); + + expect(profilePicture.props.author).toEqual({id: 'user1', username: 'testuser'}); + expect(profilePicture.props.showStatus).toBe(true); + expect(profilePicture.props.size).toBe(BOTTOM_TAB_PROFILE_PHOTO_SIZE); + expect(profilePicture.props.statusSize).toBe(BOTTOM_TAB_STATUS_SIZE); + }); +}); + +describe('Account with database observable', () => { + let database: Database; + + beforeAll(async () => { + const server = await TestHelper.setupServerDatabase(); + database = server.database; + }); + + it('should render with the correct fake user when observing data from the database', () => { + const wrapper = renderWithEverything( + , {database}); + + const profilePicture = wrapper.getByTestId('account-profile-picture'); + + expect(profilePicture.props.author.email).toContain('@simulator.amazonses.com'); + }); +}); diff --git a/app/screens/home/tab_bar/account.tsx b/app/screens/home/tab_bar/account.tsx index 84f019e28..ddce91e61 100644 --- a/app/screens/home/tab_bar/account.tsx +++ b/app/screens/home/tab_bar/account.tsx @@ -6,8 +6,9 @@ import React from 'react'; import {View} from 'react-native'; import ProfilePicture from '@components/profile_picture'; +import {BOTTOM_TAB_PROFILE_PHOTO_SIZE, BOTTOM_TAB_STATUS_SIZE} from '@constants/view'; import {observeCurrentUser} from '@queries/servers/user'; -import {makeStyleSheetFromTheme} from '@utils/theme'; +import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; import type {WithDatabaseArgs} from '@typings/database/database'; import type UserModel from '@typings/database/models/servers/user'; @@ -19,22 +20,32 @@ type Props = { } const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({ - selected: { + container: { borderWidth: 2, - borderColor: theme.buttonBg, borderRadius: 20, }, + focused: { + borderColor: theme.buttonBg, + }, + unfocused: { + borderColor: changeOpacity(theme.centerChannelColor, 0.48), + }, })); -const Account = ({currentUser, isFocused, theme}: Props) => { +export const Account = ({currentUser, isFocused, theme}: Props) => { const style = getStyleSheet(theme); return ( - + );