Skip to content

Commit

Permalink
ListView SSR tests (#3094)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
reidbarber and LFDanLu authored May 4, 2022
1 parent 5917acf commit c38d481
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/@react-spectrum/list/src/DragPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/list/src/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -63,7 +63,7 @@ const ROW_HEIGHTS = {
}
};

export function useListLayout<T>(state: ListState<T>, density: ListViewProps<T>['density']) {
function useListLayout<T>(state: ListState<T>, density: ListViewProps<T>['density']) {
let {scale} = useProvider();
let collator = useCollator({usage: 'search', sensitivity: 'base'});
let isEmpty = state.collection.size === 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-spectrum/list/src/ListViewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
31 changes: 31 additions & 0 deletions packages/@react-spectrum/list/test/ListView.ssr.test.js
Original file line number Diff line number Diff line change
@@ -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 '../';
<Provider theme={theme}>
<ListView aria-label="List view">
<Item>One</Item>
<Item>Two</Item>
<Item>Three</Item>
</ListView>
</Provider>
`);
});
});

0 comments on commit c38d481

Please sign in to comment.