@controleonline/ui-default 1.0.274 → 1.0.275
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -18,6 +18,9 @@ import {
|
|
|
18
18
|
import styles from './DefaultTable.styles';
|
|
19
19
|
import useDefaultTableTheme from './useDefaultTableTheme';
|
|
20
20
|
|
|
21
|
+
// Vertical cards must keep their intrinsic height; zero basis is only for grid rows.
|
|
22
|
+
const intrinsicHeight = {flexBasis: 'auto', flexGrow: 0, flexShrink: 0};
|
|
23
|
+
|
|
21
24
|
const DefaultTableCards = ({ storeName }) => {
|
|
22
25
|
const store = useStore(storeName);
|
|
23
26
|
const configs = store?.getters?.configs || {};
|
|
@@ -105,11 +108,12 @@ const DefaultTableCards = ({ storeName }) => {
|
|
|
105
108
|
key={row?.['@id'] || row?.id}
|
|
106
109
|
style={[
|
|
107
110
|
styles.cardItem,
|
|
111
|
+
(flatListProps.numColumns || 1) === 1 ? intrinsicHeight : null,
|
|
108
112
|
hasRowActions ? styles.cardItemWithActions : null,
|
|
109
113
|
rowStyleValue,
|
|
110
114
|
]}
|
|
111
115
|
>
|
|
112
|
-
<View style={styles.cardContent}>
|
|
116
|
+
<View style={[styles.cardContent, hasRowActions ? null : intrinsicHeight]}>
|
|
113
117
|
{configs.renderCard({
|
|
114
118
|
item: row,
|
|
115
119
|
openEdit: () => configs.onEditRow?.(row),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// fluxo: outros | etapa: order-history-page-filtro | https://github.com/ControleOnline/app-community/wiki/Smoke-Test-Flows
|
|
2
2
|
import React from 'react';
|
|
3
|
+
/* The repository flat config does not count JSX identifiers as variable usage. */
|
|
4
|
+
/* eslint-disable no-unused-vars */
|
|
3
5
|
import { Text, TouchableOpacity } from 'react-native';
|
|
4
6
|
import Icon from 'react-native-vector-icons/Feather';
|
|
5
7
|
import { useStore } from '@store';
|
|
@@ -7,6 +9,7 @@ import DefaultColumnMenu from './DefaultColumnMenu';
|
|
|
7
9
|
import DefaultDebug from './DefaultDebug';
|
|
8
10
|
import DefaultFiltersModal from './DefaultFiltersModal';
|
|
9
11
|
import DefaultModalButton from './DefaultModalButton';
|
|
12
|
+
/* eslint-enable no-unused-vars */
|
|
10
13
|
import styles from './DefaultTable.styles';
|
|
11
14
|
import { normalizeText } from '../inputs/defaultInputUtils';
|
|
12
15
|
import {
|
|
@@ -47,7 +50,6 @@ const DefaultTableControls = ({ storeName }) => {
|
|
|
47
50
|
const {
|
|
48
51
|
backgroundColor,
|
|
49
52
|
borderColor,
|
|
50
|
-
iconColor,
|
|
51
53
|
pressedBackgroundColor,
|
|
52
54
|
pressedBorderColor,
|
|
53
55
|
pressedIconColor,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const React = require('react');
|
|
2
|
+
const renderer = require('react-test-renderer');
|
|
3
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
4
|
+
let mockStore;
|
|
5
|
+
jest.mock('@store', () => ({useStore: () => mockStore}));
|
|
6
|
+
jest.mock('@controleonline/ui-common/src/react/utils/storeColumns', () => ({formatStoreColumnLabel: () => ''}));
|
|
7
|
+
jest.mock('react-native', () => {
|
|
8
|
+
const React = require('react');
|
|
9
|
+
return {
|
|
10
|
+
View: props => React.createElement('View', props, props.children),
|
|
11
|
+
Text: props => React.createElement('Text', props, props.children),
|
|
12
|
+
FlatList: props => React.createElement('List', {}, props.data.map((item, index) => props.renderItem({item, index}))),
|
|
13
|
+
StyleSheet: {create: value => value},
|
|
14
|
+
Platform: {select: value => value.web},
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
jest.mock('../../../../react/components/table/DefaultTableInput', () => () => null);
|
|
18
|
+
jest.mock('../../../../react/components/table/DefaultTableEmptyState', () => () => null);
|
|
19
|
+
jest.mock('../../../../react/components/table/DefaultTableRowActions', () => ({__esModule: true, default: () => null, hasDefaultTableRowActionsComponent: () => false}));
|
|
20
|
+
jest.mock('../../../../react/components/table/useDefaultTableTheme', () => () => ({palette: {}}));
|
|
21
|
+
const Cards = require('../../../../react/components/table/DefaultTableCards').default;
|
|
22
|
+
const flatten = style => Object.assign({}, ...[style].flat(Infinity).filter(Boolean));
|
|
23
|
+
it.each([1, 2, 3])('preserves content height and column sizing for %i columns', numColumns => {
|
|
24
|
+
const onPress = jest.fn();
|
|
25
|
+
mockStore = {getters: {items: [{id: 1}, {id: 2}], configs: {
|
|
26
|
+
cardListProps: {numColumns}, onRowPress: onPress,
|
|
27
|
+
renderCard: ({item, openRow}) => React.createElement('Card', {onPress: openRow, id: item.id}),
|
|
28
|
+
}}};
|
|
29
|
+
let tree;
|
|
30
|
+
renderer.act(() => {tree = renderer.create(React.createElement(Cards, {storeName: 'people'}));});
|
|
31
|
+
const cards = tree.root.findAllByType('Card');
|
|
32
|
+
expect(cards).toHaveLength(2);
|
|
33
|
+
for (const card of cards) {
|
|
34
|
+
const content = flatten(card.parent.props.style);
|
|
35
|
+
const outer = flatten(card.parent.parent.parent.props.style);
|
|
36
|
+
expect(content.flexBasis).toBe('auto');
|
|
37
|
+
expect(content.flexShrink).toBe(0);
|
|
38
|
+
expect(outer.flexBasis).toBe(numColumns === 1 ? 'auto' : 0);
|
|
39
|
+
expect(outer.flexGrow).toBe(numColumns === 1 ? 0 : 1);
|
|
40
|
+
expect(outer.width).toBe('100%');
|
|
41
|
+
}
|
|
42
|
+
renderer.act(() => cards[1].props.onPress());
|
|
43
|
+
expect(onPress).toHaveBeenCalledWith({id: 2});
|
|
44
|
+
renderer.act(() => tree.unmount());
|
|
45
|
+
});
|