-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for styling dialog action buttons
- Loading branch information
1 parent
844a2b1
commit a0fe2d2
Showing
3 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React from 'react'; | ||
import { Text, StyleSheet } from 'react-native'; | ||
|
||
import { act, fireEvent, render } from '@testing-library/react-native'; | ||
|
||
import Dialog from '../../components/Dialog/Dialog'; | ||
import Button from '../Button/Button'; | ||
|
||
jest.mock('react-native-safe-area-context', () => ({ | ||
useSafeAreaInsets: () => ({ bottom: 44, left: 0, right: 0, top: 37 }), | ||
})); | ||
|
||
describe('Dialog', () => { | ||
it('should render passed children', () => { | ||
const { getByTestId } = render( | ||
<Dialog visible testID="dialog"> | ||
<Text>This is simple dialog</Text> | ||
</Dialog> | ||
); | ||
|
||
expect(getByTestId('dialog')).toHaveTextContent('This is simple dialog'); | ||
}); | ||
|
||
it('should call onDismiss when dismissable', () => { | ||
const onDismiss = jest.fn(); | ||
const { getByTestId } = render( | ||
<Dialog visible onDismiss={onDismiss} dismissable testID="dialog"> | ||
<Text>This is simple dialog</Text> | ||
</Dialog> | ||
); | ||
|
||
fireEvent.press(getByTestId('dialog-backdrop')); | ||
|
||
act(() => { | ||
jest.runAllTimers(); | ||
}); | ||
expect(onDismiss).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should apply top margin to the first child if the dialog is V3', () => { | ||
const { getByTestId } = render( | ||
<Dialog visible={true}> | ||
<Dialog.Title testID="dialog-content"> | ||
<Text>Test Dialog Content</Text> | ||
</Dialog.Title> | ||
</Dialog> | ||
); | ||
|
||
expect(getByTestId('dialog-content')).toHaveStyle({ | ||
marginTop: 24, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('DialogActions', () => { | ||
it('should render passed children', () => { | ||
const { getByTestId } = render( | ||
<Dialog.Actions> | ||
<Button testID="button-cancel">Cancel</Button> | ||
<Button testID="button-ok">Ok</Button> | ||
</Dialog.Actions> | ||
); | ||
|
||
expect(getByTestId('button-cancel')).toBeDefined(); | ||
expect(getByTestId('button-ok')).toBeDefined(); | ||
}); | ||
|
||
it('should apply default styles', () => { | ||
const { getByTestId } = render( | ||
<Dialog.Actions testID="dialog-actions"> | ||
<Button>Cancel</Button> | ||
<Button>Ok</Button> | ||
</Dialog.Actions> | ||
); | ||
|
||
const dialogActionsContainer = getByTestId('dialog-actions'); | ||
const dialogActionButtons = dialogActionsContainer.children; | ||
|
||
expect(dialogActionsContainer).toHaveStyle({ | ||
paddingBottom: 24, | ||
paddingHorizontal: 24, | ||
}); | ||
expect(dialogActionButtons[0]).toHaveStyle({ paddingRight: 8 }); | ||
expect(dialogActionButtons[1]).toHaveStyle({ paddingRight: 0 }); | ||
}); | ||
|
||
it('should apply custom styles', () => { | ||
const { getByTestId } = render( | ||
<Dialog.Actions testID="dialog-actions"> | ||
<Button style={styles.spacing}>Cancel</Button> | ||
<Button style={styles.noSpacing}>Ok</Button> | ||
</Dialog.Actions> | ||
); | ||
|
||
const dialogActionsContainer = getByTestId('dialog-actions'); | ||
const dialogActionButtons = dialogActionsContainer.children; | ||
|
||
expect(dialogActionButtons[0]).toHaveStyle({ margin: 10 }); | ||
expect(dialogActionButtons[1]).toHaveStyle({ margin: 0 }); | ||
}); | ||
}); | ||
|
||
const styles = StyleSheet.create({ | ||
spacing: { | ||
margin: 10, | ||
}, | ||
noSpacing: { | ||
margin: 0, | ||
}, | ||
}); |