* typescript and view component for permalink with user and message * Old post edited handling in permalink * Added test and update flag value to EnablePermalinkPreview * Added test for permalink_preview component * Added test for content/index.tsx for permalink * Addressed review comments * Unit test for missing file and review comments * Added test to check handlePostEdited permalink sync only calls one time only * Change TouchableOpacity to Pressable * When user not found fetch the user from the server * Removed the redundant test in the test for permalink_preview/index? * ts to tsx * Removed the circular dependency * Address review comments * displayname fallback * remove permalink when permalink post is deleted * UX review comments * Linter fixes * Test fixes * Address review comments * Minor * Some more review comments --------- Co-authored-by: yasserfaraazkhan <attitude3cena.yf@gmail.com>
128 lines
4.2 KiB
TypeScript
128 lines
4.2 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react';
|
|
|
|
import {Preferences} from '@constants';
|
|
import {renderWithIntlAndTheme} from '@test/intl-test-helper';
|
|
|
|
import EditedIndicator from './index';
|
|
|
|
describe('components/EditedIndicator', () => {
|
|
const baseProps = {
|
|
baseTextStyle: {fontSize: 16, color: '#000'},
|
|
theme: Preferences.THEMES.denim,
|
|
context: ['paragraph'],
|
|
testID: 'edited-indicator-test',
|
|
};
|
|
|
|
it('should render with default props', () => {
|
|
const {getByTestId} = renderWithIntlAndTheme(
|
|
<EditedIndicator {...baseProps}/>,
|
|
);
|
|
|
|
const indicator = getByTestId('edited-indicator-test');
|
|
expect(indicator).toBeTruthy();
|
|
expect(indicator.props.children).toEqual([
|
|
' ', // spacer for paragraph context
|
|
expect.objectContaining({
|
|
props: expect.objectContaining({
|
|
name: 'pencil-outline',
|
|
size: 14, // default icon size
|
|
}),
|
|
}),
|
|
expect.objectContaining({
|
|
props: expect.objectContaining({
|
|
id: 'post_message_view.edited',
|
|
defaultMessage: 'Edited',
|
|
}),
|
|
}),
|
|
]);
|
|
});
|
|
|
|
it('should render with custom icon size', () => {
|
|
const {getByTestId} = renderWithIntlAndTheme(
|
|
<EditedIndicator
|
|
{...baseProps}
|
|
iconSize={20}
|
|
/>,
|
|
);
|
|
|
|
const indicator = getByTestId('edited-indicator-test');
|
|
const icon = indicator.props.children[1];
|
|
expect(icon.props.size).toBe(20);
|
|
});
|
|
|
|
it('should render with custom testID', () => {
|
|
const {getByTestId} = renderWithIntlAndTheme(
|
|
<EditedIndicator
|
|
{...baseProps}
|
|
testID='custom-test-id'
|
|
/>,
|
|
);
|
|
|
|
expect(getByTestId('custom-test-id')).toBeTruthy();
|
|
});
|
|
|
|
describe('component structure', () => {
|
|
it('should render pencil-outline icon', () => {
|
|
const {getByTestId} = renderWithIntlAndTheme(
|
|
<EditedIndicator {...baseProps}/>,
|
|
);
|
|
|
|
const indicator = getByTestId('edited-indicator-test');
|
|
const icon = indicator.props.children[1];
|
|
expect(icon.props.name).toBe('pencil-outline');
|
|
});
|
|
|
|
it('should render "Edited" text with correct props', () => {
|
|
const {getByTestId} = renderWithIntlAndTheme(
|
|
<EditedIndicator {...baseProps}/>,
|
|
);
|
|
|
|
const indicator = getByTestId('edited-indicator-test');
|
|
const formattedText = indicator.props.children[2];
|
|
expect(formattedText.props.id).toBe('post_message_view.edited');
|
|
expect(formattedText.props.defaultMessage).toBe('Edited');
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle empty context array', () => {
|
|
const {getByTestId} = renderWithIntlAndTheme(
|
|
<EditedIndicator
|
|
{...baseProps}
|
|
context={[]}
|
|
/>,
|
|
);
|
|
|
|
const indicator = getByTestId('edited-indicator-test');
|
|
expect(indicator.props.children[0]).toBe('');
|
|
});
|
|
|
|
it('should handle undefined context elements', () => {
|
|
const {getByTestId} = renderWithIntlAndTheme(
|
|
<EditedIndicator
|
|
{...baseProps}
|
|
context={[undefined] as any}
|
|
checkHeadings={true}
|
|
/>,
|
|
);
|
|
|
|
const indicator = getByTestId('edited-indicator-test');
|
|
expect(indicator.props.children[0]).toBe('');
|
|
});
|
|
|
|
it('should handle context with multiple elements', () => {
|
|
const {getByTestId} = renderWithIntlAndTheme(
|
|
<EditedIndicator
|
|
{...baseProps}
|
|
context={['paragraph', 'strong', 'em']}
|
|
/>,
|
|
);
|
|
|
|
const indicator = getByTestId('edited-indicator-test');
|
|
expect(indicator.props.children[0]).toBe(' ');
|
|
});
|
|
});
|
|
});
|