From c38d48149ff355c0aaa8f4db5b0be7a8774b26e7 Mon Sep 17 00:00:00 2001 From: Reid Barber Date: Wed, 4 May 2022 17:50:09 -0500 Subject: [PATCH] ListView SSR tests (#3094) * add listview ssr test * remove export of useListLayout * update export to * * add aria-label * use explicit export * rename css file to fix ssr test on mac Co-authored-by: Daniel Lu --- .../@react-spectrum/list/src/DragPreview.tsx | 2 +- .../@react-spectrum/list/src/ListView.tsx | 4 +-- .../@react-spectrum/list/src/ListViewItem.tsx | 2 +- .../list/src/{listview.css => styles.css} | 0 .../list/test/ListView.ssr.test.js | 31 +++++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) rename packages/@react-spectrum/list/src/{listview.css => styles.css} (100%) create mode 100644 packages/@react-spectrum/list/test/ListView.ssr.test.js diff --git a/packages/@react-spectrum/list/src/DragPreview.tsx b/packages/@react-spectrum/list/src/DragPreview.tsx index dae423ce942..be332bfdac5 100644 --- a/packages/@react-spectrum/list/src/DragPreview.tsx +++ b/packages/@react-spectrum/list/src/DragPreview.tsx @@ -13,7 +13,7 @@ import {classNames, SlotProvider} from '@react-spectrum/utils'; import {Content} from '@react-spectrum/view'; import {Grid} from '@react-spectrum/layout'; import {GridNode} from '@react-types/grid'; -import listStyles from './listview.css'; +import listStyles from './styles.css'; import {Provider} from '@react-spectrum/provider'; import {ProviderContext} from '@react-types/provider'; import React from 'react'; diff --git a/packages/@react-spectrum/list/src/ListView.tsx b/packages/@react-spectrum/list/src/ListView.tsx index c2fd4e81952..f9ebf69a83d 100644 --- a/packages/@react-spectrum/list/src/ListView.tsx +++ b/packages/@react-spectrum/list/src/ListView.tsx @@ -30,7 +30,7 @@ import {GridCollection, GridState, useGridState} from '@react-stately/grid'; import intlMessages from '../intl/*.json'; import {ListLayout} from '@react-stately/layout'; import {ListState, useListState} from '@react-stately/list'; -import listStyles from './listview.css'; +import listStyles from './styles.css'; import {ListViewItem} from './ListViewItem'; import {ProgressCircle} from '@react-spectrum/progress'; import React, {ReactElement, useContext, useMemo, useRef} from 'react'; @@ -63,7 +63,7 @@ const ROW_HEIGHTS = { } }; -export function useListLayout(state: ListState, density: ListViewProps['density']) { +function useListLayout(state: ListState, density: ListViewProps['density']) { let {scale} = useProvider(); let collator = useCollator({usage: 'search', sensitivity: 'base'}); let isEmpty = state.collection.size === 0; diff --git a/packages/@react-spectrum/list/src/ListViewItem.tsx b/packages/@react-spectrum/list/src/ListViewItem.tsx index 971c567c16a..d7e0612656a 100644 --- a/packages/@react-spectrum/list/src/ListViewItem.tsx +++ b/packages/@react-spectrum/list/src/ListViewItem.tsx @@ -18,7 +18,7 @@ import type {DraggableItemResult} from '@react-aria/dnd'; import {FocusRing, useFocusRing} from '@react-aria/focus'; import {Grid} from '@react-spectrum/layout'; import ListGripper from '@spectrum-icons/ui/ListGripper'; -import listStyles from './listview.css'; +import listStyles from './styles.css'; import {ListViewContext} from './ListView'; import {mergeProps} from '@react-aria/utils'; import React, {useContext, useRef} from 'react'; diff --git a/packages/@react-spectrum/list/src/listview.css b/packages/@react-spectrum/list/src/styles.css similarity index 100% rename from packages/@react-spectrum/list/src/listview.css rename to packages/@react-spectrum/list/src/styles.css diff --git a/packages/@react-spectrum/list/test/ListView.ssr.test.js b/packages/@react-spectrum/list/test/ListView.ssr.test.js new file mode 100644 index 00000000000..9f2e6566a8e --- /dev/null +++ b/packages/@react-spectrum/list/test/ListView.ssr.test.js @@ -0,0 +1,31 @@ +/* + * Copyright 2020 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +import {testSSR} from '@react-spectrum/test-utils'; + +describe('ListView SSR', function () { + it('should render without errors', async function () { + await testSSR(__filename, ` + import {Provider} from '@react-spectrum/provider'; + import {theme} from '@react-spectrum/theme-default'; + import {ListView, Item} from '../'; + + + + One + Two + Three + + + `); + }); +});