/** * 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 */ const {printOwnersList} = require('../devtools/utils'); const {getVersionedRenderImplementation} = require('./utils'); describe('Store owners list', () => { let React; let act; let store; beforeEach(() => { store = global.store; store.collapseNodesByDefault = false; React = require('react'); const utils = require('./utils'); act = utils.act; }); const {render} = getVersionedRenderImplementation(); function getFormattedOwnersList(elementID) { const ownersList = store.getOwnersListForElement(elementID); return printOwnersList(ownersList); } it('should drill through intermediate components', () => { const Root = () => (
); const Wrapper = ({children}) => children; const Leaf = () =>
Leaf
; const Intermediate = ({children}) => {children}; act(() => render()); expect(store).toMatchInlineSnapshot(` [root] ▾ `); const rootID = store.getElementIDAtIndex(0); expect(getFormattedOwnersList(rootID)).toMatchInlineSnapshot(` " ▾ " `); const intermediateID = store.getElementIDAtIndex(1); expect(getFormattedOwnersList(intermediateID)).toMatchInlineSnapshot(` " ▾ " `); }); it('should drill through interleaved intermediate components', () => { const Root = () => [ , , ]; const Wrapper = ({children}) => children; const Leaf = () =>
Leaf
; const Intermediate = ({children}) => [ , {children}, ]; act(() => render()); expect(store).toMatchInlineSnapshot(` [root] ▾ `); const rootID = store.getElementIDAtIndex(0); expect(getFormattedOwnersList(rootID)).toMatchInlineSnapshot(` " ▾ " `); const intermediateID = store.getElementIDAtIndex(1); expect(getFormattedOwnersList(intermediateID)).toMatchInlineSnapshot(` " ▾ " `); }); it('should show the proper owners list order and contents after insertions and deletions', () => { const Root = ({includeDirect, includeIndirect}) => (
{includeDirect ? : null} {includeIndirect ? ( ) : null}
); const Wrapper = ({children}) => children; const Leaf = () =>
Leaf
; const Intermediate = ({children}) => {children}; act(() => render()); const rootID = store.getElementIDAtIndex(0); expect(store).toMatchInlineSnapshot(` [root] ▾ `); expect(getFormattedOwnersList(rootID)).toMatchInlineSnapshot(` " ▾ " `); act(() => render()); expect(store).toMatchInlineSnapshot(` [root] ▾ `); expect(getFormattedOwnersList(rootID)).toMatchInlineSnapshot(` " ▾ " `); act(() => render()); expect(store).toMatchInlineSnapshot(` [root] ▾ `); expect(getFormattedOwnersList(rootID)).toMatchInlineSnapshot(` " ▾ " `); act(() => render()); expect(store).toMatchInlineSnapshot(` [root] `); expect(getFormattedOwnersList(rootID)).toMatchInlineSnapshot( `" "`, ); }); it('should show the proper owners list ordering after reordered children', () => { const Root = ({ascending}) => ascending ? [, , ] : [, , ]; const Leaf = () =>
Leaf
; act(() => render()); const rootID = store.getElementIDAtIndex(0); expect(store).toMatchInlineSnapshot(` [root] ▾ `); expect(getFormattedOwnersList(rootID)).toMatchInlineSnapshot(` " ▾ " `); act(() => render()); expect(store).toMatchInlineSnapshot(` [root] ▾ `); expect(getFormattedOwnersList(rootID)).toMatchInlineSnapshot(` " ▾ " `); }); });