1
1
import React from 'react' ;
2
+ import { ViewStyle } from 'react-native' ;
2
3
import { render } from '@testing-library/react-native' ;
3
- import FloatingButton /* , {FloatingButtonLayouts} */ from '../index' ;
4
+ import { Spacings } from '../../../style' ;
5
+ import FloatingButton , { FloatingButtonLayouts } from '../index' ;
4
6
import { ButtonDriver } from '../../button/Button.driver.new' ;
7
+ import { useComponentDriver , ComponentProps } from '../../../testkit/new/Component.driver' ;
5
8
6
9
const TEST_ID = 'floating_button' ;
7
10
const button = {
@@ -10,12 +13,15 @@ const button = {
10
13
const secondaryButton = {
11
14
label : 'Second'
12
15
} ;
13
- // buttonLayout={showVertical ? FloatingButtonLayouts.VERTICAL : FloatingButtonLayouts.HORIZONTAL}
14
-
15
16
16
17
const TestCase = ( props ) => {
17
18
return < FloatingButton { ...props } testID = { TEST_ID } /> ;
18
19
} ;
20
+ export const FloatingButtonDriver = ( props : ComponentProps ) => {
21
+ const driver = useComponentDriver ( props ) ;
22
+ const getStyle = ( ) => driver . getProps ( ) . style as ViewStyle ;
23
+ return { ...driver , getStyle} ;
24
+ } ;
19
25
20
26
describe ( 'FloatingButton' , ( ) => {
21
27
describe ( 'visible' , ( ) => {
@@ -59,4 +65,90 @@ describe('FloatingButton', () => {
59
65
expect ( await buttonDriver . getLabel ( ) . getText ( ) ) . toEqual ( secondaryButton . label ) ;
60
66
} ) ;
61
67
} ) ;
68
+
69
+ describe ( 'bottomMargin' , ( ) => {
70
+ it ( 'should have default bottom margin' , ( ) => {
71
+ const props = { visible : true } ;
72
+ const renderTree = render ( < TestCase { ...props } /> ) ;
73
+ const buttonDriver = ButtonDriver ( { renderTree, testID : `${ TEST_ID } .button` } ) ;
74
+
75
+ expect ( buttonDriver . getProps ( ) ?. style ?. marginBottom ) . toBe ( Spacings . s8 ) ;
76
+ } ) ;
77
+
78
+ it ( 'should have default bottom margin for both buttons' , ( ) => {
79
+ const props = { visible : true , secondaryButton} ;
80
+ const renderTree = render ( < TestCase { ...props } /> ) ;
81
+ const buttonDriver = ButtonDriver ( { renderTree, testID : `${ TEST_ID } .button` } ) ;
82
+ const buttonDriver2 = ButtonDriver ( { renderTree, testID : `${ TEST_ID } .secondaryButton` } ) ;
83
+
84
+ expect ( buttonDriver . getProps ( ) ?. style ?. marginBottom ) . toBe ( Spacings . s4 ) ;
85
+ expect ( buttonDriver2 . getProps ( ) ?. style ?. marginBottom ) . toBe ( Spacings . s7 ) ;
86
+ } ) ;
87
+
88
+ it ( 'should have bottom margin that match bottomMargin prop' , ( ) => {
89
+ const props = { visible : true , bottomMargin : 10 } ;
90
+ const renderTree = render ( < TestCase { ...props } /> ) ;
91
+ const buttonDriver = ButtonDriver ( { renderTree, testID : `${ TEST_ID } .button` } ) ;
92
+
93
+ expect ( buttonDriver . getProps ( ) ?. style ?. marginBottom ) . toBe ( 10 ) ;
94
+ } ) ;
95
+
96
+ it ( 'should have bottom margin for secondary button that match bottomMarginProp' , ( ) => {
97
+ const props = { visible : true , secondaryButton, bottomMargin : 10 } ;
98
+ const renderTree = render ( < TestCase { ...props } /> ) ;
99
+ const buttonDriver = ButtonDriver ( { renderTree, testID : `${ TEST_ID } .button` } ) ;
100
+ const buttonDriver2 = ButtonDriver ( { renderTree, testID : `${ TEST_ID } .secondaryButton` } ) ;
101
+
102
+ expect ( buttonDriver . getProps ( ) ?. style ?. marginBottom ) . toBe ( Spacings . s4 ) ;
103
+ expect ( buttonDriver2 . getProps ( ) ?. style ?. marginBottom ) . toBe ( 10 ) ;
104
+ } ) ;
105
+ } ) ;
106
+
107
+ describe ( 'buttonLayout' , ( ) => {
108
+ it ( 'should style vertical layout (default)' , ( ) => {
109
+ const props = { visible : true , secondaryButton} ;
110
+ const renderTree = render ( < TestCase { ...props } /> ) ;
111
+ const driver = FloatingButtonDriver ( { renderTree, testID : TEST_ID } ) ;
112
+
113
+ expect ( driver . getStyle ( ) ?. flexDirection ) . toBe ( undefined ) ;
114
+ expect ( driver . getStyle ( ) ?. alignItems ) . toBe ( 'center' ) ;
115
+ expect ( driver . getStyle ( ) ?. justifyContent ) . toBe ( 'center' ) ;
116
+ expect ( driver . getStyle ( ) ?. paddingHorizontal ) . toBe ( undefined ) ;
117
+ } ) ;
118
+
119
+ it ( 'should style horizontal layout' , ( ) => {
120
+ const props = { visible : true , secondaryButton, buttonLayout : FloatingButtonLayouts . HORIZONTAL } ;
121
+ const renderTree = render ( < TestCase { ...props } /> ) ;
122
+ const driver = FloatingButtonDriver ( { renderTree, testID : TEST_ID } ) ;
123
+
124
+ expect ( driver . getStyle ( ) ?. flexDirection ) . toBe ( 'row' ) ;
125
+ expect ( driver . getStyle ( ) ?. alignItems ) . toBe ( 'center' ) ;
126
+ expect ( driver . getStyle ( ) ?. justifyContent ) . toBe ( 'center' ) ;
127
+ expect ( driver . getStyle ( ) ?. paddingHorizontal ) . toBe ( undefined ) ;
128
+ } ) ;
129
+ } ) ;
130
+
131
+ describe ( 'fullWidth' , ( ) => {
132
+ it ( 'should style vertical layout (default) when fullWidth is true' , ( ) => {
133
+ const props = { visible : true , secondaryButton, fullWidth : true } ;
134
+ const renderTree = render ( < TestCase { ...props } /> ) ;
135
+ const driver = FloatingButtonDriver ( { renderTree, testID : TEST_ID } ) ;
136
+
137
+ expect ( driver . getStyle ( ) ?. flexDirection ) . toBe ( undefined ) ;
138
+ expect ( driver . getStyle ( ) ?. alignItems ) . toBe ( undefined ) ;
139
+ expect ( driver . getStyle ( ) ?. justifyContent ) . toBe ( undefined ) ;
140
+ expect ( driver . getStyle ( ) ?. paddingHorizontal ) . toBe ( 16 ) ;
141
+ } ) ;
142
+
143
+ it ( 'should style horizontal layout when fullWidth is true' , ( ) => {
144
+ const props = { visible : true , secondaryButton, buttonLayout : FloatingButtonLayouts . HORIZONTAL , fullWidth : true } ;
145
+ const renderTree = render ( < TestCase { ...props } /> ) ;
146
+ const driver = FloatingButtonDriver ( { renderTree, testID : TEST_ID } ) ;
147
+
148
+ expect ( driver . getStyle ( ) ?. flexDirection ) . toBe ( 'row' ) ;
149
+ expect ( driver . getStyle ( ) ?. alignItems ) . toBe ( 'center' ) ;
150
+ expect ( driver . getStyle ( ) ?. justifyContent ) . toBe ( 'center' ) ;
151
+ expect ( driver . getStyle ( ) ?. paddingHorizontal ) . toBe ( undefined ) ;
152
+ } ) ;
153
+ } ) ;
62
154
} ) ;
0 commit comments