mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d9ade19b71
Summary:
changelog:
[General][Add] LogBox now makes URL links tappable.
Logbox messages may contain URLs with more information about the given error. Right now, they are not tappable or copyable. So engineers need to resort to manually retype the link to browser. This diff tries to address that.
Example of StrictMode error that has link in it.
{F798509909}
Reviewed By: yungsters
Differential Revision: D41305784
fbshipit-source-id: 456a9faf34f8b9e443759dd6903ba67d0b9de73c
254 lines
5.9 KiB
JavaScript
254 lines
5.9 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
* @oncall react_native
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const render = require('../../../../jest/renderer');
|
|
const LogBoxMessage = require('../LogBoxMessage').default;
|
|
const React = require('react');
|
|
|
|
describe('LogBoxMessage', () => {
|
|
it('should render message', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
message={{
|
|
content: 'Some kind of message',
|
|
substitutions: [],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render message truncated to 6 chars', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
maxLength={5}
|
|
message={{
|
|
content: 'Some kind of message',
|
|
substitutions: [],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render the whole message when maxLength = message length', () => {
|
|
const message = 'Some kind of message';
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
maxLength={message.length}
|
|
message={{
|
|
content: message,
|
|
substitutions: [],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render message with substitution', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
message={{
|
|
content: 'normal substitution normal',
|
|
substitutions: [{length: 12, offset: 7}],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render message with substitution, truncating the first word 3 letters in', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
maxLength={3}
|
|
message={{
|
|
content: 'normal substitution normal',
|
|
substitutions: [{length: 12, offset: 7}],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render message with substitution, truncating the second word 6 letters in', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
maxLength={13}
|
|
message={{
|
|
content: 'normal substitution normal',
|
|
substitutions: [{length: 12, offset: 7}],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render message with substitution, truncating the third word 2 letters in', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
maxLength={22}
|
|
message={{
|
|
content: 'normal substitution normal',
|
|
substitutions: [{length: 12, offset: 7}],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render the whole message with substitutions when maxLength = message length', () => {
|
|
const message = 'normal substitution normal';
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
maxLength={message.length}
|
|
message={{
|
|
content: message,
|
|
substitutions: [{length: 12, offset: 7}],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render a plaintext message with no substitutions', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
plaintext
|
|
style={{}}
|
|
message={{
|
|
content: 'normal substitution normal',
|
|
substitutions: [{length: 12, offset: 7}],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render a plaintext message and clean the content', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
plaintext
|
|
style={{}}
|
|
message={{
|
|
content: 'Error: This should not start with Error:',
|
|
substitutions: [],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('Should strip "TransformError " without breaking substitution', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
message={{
|
|
content: 'TransformError normal substitution normal',
|
|
substitutions: [{length: 12, offset: 22}],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('Should strip "Warning: " without breaking substitution', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
message={{
|
|
content: 'Warning: normal substitution normal',
|
|
substitutions: [{length: 12, offset: 16}],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('Should strip "Warning: Warning: " without breaking substitution', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
message={{
|
|
content: 'Warning: Warning: normal substitution normal',
|
|
substitutions: [{length: 12, offset: 25}],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('Should make links tappable', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
message={{
|
|
content: 'http://reactnative.dev',
|
|
substitutions: [],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('Should handle multiple links', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
message={{
|
|
content: 'http://reactnative.dev and http://reactjs.org',
|
|
substitutions: [],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('Should handle truncated links', () => {
|
|
const output = render.create(
|
|
<LogBoxMessage
|
|
style={{}}
|
|
maxLength={35}
|
|
message={{
|
|
content: 'http://reactnative.dev and http://reactjs.org',
|
|
substitutions: [],
|
|
}}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
});
|