|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @flow strict-local |
| 8 | + * @format |
| 9 | + */ |
| 10 | + |
| 11 | +import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; |
| 12 | + |
| 13 | +import * as Fantom from '@react-native/fantom'; |
| 14 | +import LogBoxLog from 'react-native/Libraries/LogBox/Data/LogBoxLog'; |
| 15 | +import LogBoxInspector from 'react-native/Libraries/LogBox/UI/LogBoxInspector'; |
| 16 | +import * as React from 'react'; |
| 17 | + |
| 18 | +describe('LogBoxInspector', () => { |
| 19 | + it('should render nothing with no logs', () => { |
| 20 | + const root = Fantom.createRoot(); |
| 21 | + |
| 22 | + Fantom.runTask(() => { |
| 23 | + root.render( |
| 24 | + <LogBoxInspector |
| 25 | + onDismiss={() => {}} |
| 26 | + onMinimize={() => {}} |
| 27 | + onChangeSelectedIndex={() => {}} |
| 28 | + logs={[]} |
| 29 | + selectedIndex={0} |
| 30 | + />, |
| 31 | + ); |
| 32 | + }); |
| 33 | + |
| 34 | + // LogBoxInspector returns null when logs is empty, so nothing is rendered. |
| 35 | + expect(root.getRenderedOutput({props: []}).toJSX()).toEqual(null); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should render inspector with a warn log', () => { |
| 39 | + const root = Fantom.createRoot(); |
| 40 | + |
| 41 | + const logs = [ |
| 42 | + new LogBoxLog({ |
| 43 | + level: 'warn', |
| 44 | + isComponentError: false, |
| 45 | + message: { |
| 46 | + content: 'Some kind of message (first)', |
| 47 | + substitutions: [], |
| 48 | + }, |
| 49 | + stack: [], |
| 50 | + category: 'Some kind of message (first)', |
| 51 | + componentStack: [], |
| 52 | + }), |
| 53 | + ]; |
| 54 | + |
| 55 | + Fantom.runTask(() => { |
| 56 | + root.render( |
| 57 | + <LogBoxInspector |
| 58 | + onDismiss={() => {}} |
| 59 | + onMinimize={() => {}} |
| 60 | + onChangeSelectedIndex={() => {}} |
| 61 | + logs={logs} |
| 62 | + selectedIndex={0} |
| 63 | + />, |
| 64 | + ); |
| 65 | + }); |
| 66 | + |
| 67 | + // When there is a log, the inspector renders a root view with id logbox_inspector. |
| 68 | + // Verify the top-level view is present by checking the JSON type. |
| 69 | + const output = root.getRenderedOutput({props: []}).toJSONObject(); |
| 70 | + expect(output.type).toEqual('View'); |
| 71 | + }); |
| 72 | +}); |
0 commit comments