From d58601b59f8c170df4c436ca84ead3bd96fe6bef Mon Sep 17 00:00:00 2001 From: Andrew Datsenko Date: Tue, 5 Aug 2025 07:05:54 -0700 Subject: [PATCH] Add base public API tests (#53040) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53040 Changelog: [Internal] Add base public API integration tests for Image component. Reviewed By: rubennorte Differential Revision: D79551685 fbshipit-source-id: 467d3573102675f4ad1e3757894795b0ad9a8413 --- .../Libraries/Image/__tests__/Image-itest.js | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 packages/react-native/Libraries/Image/__tests__/Image-itest.js diff --git a/packages/react-native/Libraries/Image/__tests__/Image-itest.js b/packages/react-native/Libraries/Image/__tests__/Image-itest.js new file mode 100644 index 00000000000..6abf505f5d7 --- /dev/null +++ b/packages/react-native/Libraries/Image/__tests__/Image-itest.js @@ -0,0 +1,140 @@ +/** + * 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 + */ + +import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; + +import type {HostInstance} from 'react-native'; + +import * as Fantom from '@react-native/fantom'; +import * as React from 'react'; +import {createRef} from 'react'; +import {Image} from 'react-native'; +import ensureInstance from 'react-native/src/private/__tests__/utilities/ensureInstance'; +import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement'; + +describe('', () => { + describe('props', () => { + it('renders an empty element when there are no props', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render(); + }); + + expect( + root.getRenderedOutput({includeLayoutMetrics: true}).toJSX(), + ).toEqual( + , + ); + }); + + describe('accessibility', () => { + describe('accessible', () => { + it('indicates that image is an accessibility element', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render(); + }); + + expect( + root.getRenderedOutput({props: ['accessible']}).toJSX(), + ).toEqual(); + }); + }); + + describe('accessibilityLabel', () => { + it('provides information for screen reader', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render(); + }); + + expect( + root.getRenderedOutput({props: ['accessibilityLabel']}).toJSX(), + ).toEqual(); + }); + }); + + describe('alt', () => { + it('provides information for screen reader', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render(React Native Logo); + }); + + expect(root.getRenderedOutput({props: ['^access']}).toJSX()).toEqual( + , + ); + }); + + it('can be set alongside accessibilityLabel, but accessibilityLabel has higher priority', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + React Native Logo, + ); + }); + + expect(root.getRenderedOutput({props: ['^access']}).toJSX()).toEqual( + , + ); + }); + }); + }); + }); + + describe('ref', () => { + describe('instance', () => { + it('is an element node', () => { + const elementRef = createRef(); + + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render(); + }); + + expect(elementRef.current).toBeInstanceOf(ReactNativeElement); + }); + + it('uses the "RN:Image" tag name', () => { + const elementRef = createRef(); + + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render(); + }); + + const element = ensureInstance(elementRef.current, ReactNativeElement); + expect(element.tagName).toBe('RN:Image'); + }); + }); + }); +});