-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix previously ignored view-clipping
- Loading branch information
Showing
10 changed files
with
126 additions
and
35 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 |
---|---|---|
@@ -1,24 +1,41 @@ | ||
const fs = require('fs'); | ||
const { expectToThrow } = require('./utils/custom-expects'); | ||
|
||
describe(':android: Element screenshots', () => { | ||
const screenshotAssetPath = './e2e/assets/elementScreenshot-android.png'; | ||
|
||
beforeEach(async () => { | ||
await device.reloadReactNative(); | ||
await element(by.text('Matchers')).tap(); | ||
await element(by.text('Element-Screenshots')).tap(); | ||
}); | ||
|
||
it('should take a screenshot of an element', async () => { | ||
const bitmapPath = await element(by.id('Grandfather883')).takeScreenshot(); | ||
it('should take a screenshot of a vertically-clipped element', async () => { | ||
const screenshotAssetPath = './e2e/assets/elementScreenshot.android.vert.png'; | ||
|
||
const bitmapPath = await element(by.id('fancyElement')).takeScreenshot(); | ||
expectBitmapsToBeEqual(bitmapPath, screenshotAssetPath); | ||
}); | ||
|
||
it('should take a screenshot of a horizontally-clipped element', async () => { | ||
const screenshotAssetPath = './e2e/assets/elementScreenshot.android.horiz.png'; | ||
|
||
await element(by.id('switchOrientation')).tap(); | ||
|
||
const bitmapPath = await element(by.id('fancyElement')).takeScreenshot(); | ||
expectBitmapsToBeEqual(bitmapPath, screenshotAssetPath); | ||
}); | ||
|
||
it('should fail to take a screenshot of an off-screen element', async () => { | ||
await expectToThrow( | ||
() => element(by.id('offscreenElement')).takeScreenshot(), | ||
`Cannot take screenshot of a view that's out of screen's bounds`, | ||
); | ||
}); | ||
|
||
function expectBitmapsToBeEqual(bitmapPath, expectedBitmapPath) { | ||
const bitmapBuffer = fs.readFileSync(bitmapPath); | ||
const expectedBitmapBuffer = fs.readFileSync(screenshotAssetPath); | ||
const expectedBitmapBuffer = fs.readFileSync(expectedBitmapPath); | ||
if (!bitmapBuffer.equals(expectedBitmapBuffer)) { | ||
throw new Error([ | ||
`Bitmaps at (1) ${bitmapPath} and (2) ${screenshotAssetPath} are different!`, | ||
'(1): ' + JSON.stringify(bitmapBuffer), | ||
'VS.', | ||
'(2): ' + JSON.stringify(expectedBitmapBuffer), | ||
].join('\n')); | ||
} | ||
}); | ||
throw new Error(`Expected bitmap at ${bitmapPath} to be equal to ${expectedBitmapPath}, but it is different!`); | ||
} | ||
} | ||
}); |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,72 @@ | ||
import React, { Component } from 'react'; | ||
import { View, Dimensions, TouchableHighlight } from 'react-native'; | ||
|
||
const screenWidth = Dimensions.get('window').width; | ||
const screenHeight = Dimensions.get('window').height; | ||
|
||
class ArtisticRectangle extends Component { | ||
static defaultProps = { | ||
borderSizeV: 12, | ||
borderSizeH: 12, | ||
} | ||
|
||
render() { | ||
const paddingHorizontal = this.props.borderSizeH; | ||
const paddingVertical = this.props.borderSizeV; | ||
return ( | ||
<View testID={this.props.testID}> | ||
<View style={{paddingHorizontal, paddingVertical, backgroundColor: 'cyan'}}> | ||
<View style={{paddingHorizontal, paddingVertical, backgroundColor: 'magenta'}}> | ||
<View style={{paddingHorizontal, paddingVertical, backgroundColor: 'yellow'}}> | ||
<View style={{paddingHorizontal, paddingVertical, backgroundColor: 'black'}} /> | ||
</View> | ||
</View> | ||
</View> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
export default class ElementScreenshotScreen extends Component { | ||
static orientations = { | ||
'vertical': { | ||
borderSizeH: 12, | ||
borderSizeV: screenHeight * 1.5 / 8, | ||
}, | ||
'horizontal': { | ||
borderSizeH: screenWidth * 1.5 / 8, | ||
borderSizeV: 12, | ||
} | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.switchOrientation = this.switchOrientation.bind(this); | ||
|
||
this.state = { | ||
orientation: 'vertical', | ||
}; | ||
} | ||
|
||
render() { | ||
const { borderSizeH, borderSizeV } = ElementScreenshotScreen.orientations[this.state.orientation]; | ||
|
||
return ( | ||
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}> | ||
<TouchableHighlight testID='switchOrientation' onPress={this.switchOrientation}> | ||
<ArtisticRectangle testID='fancyElement' borderSizeH={borderSizeH} borderSizeV={borderSizeV} /> | ||
</TouchableHighlight> | ||
|
||
<View style={{position: 'absolute', left: -100, top: -100}}> | ||
<ArtisticRectangle testID='offscreenElement' /> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
switchOrientation() { | ||
this.setState({ | ||
orientation: this.state.orientation === 'vertical' ? 'horizontal' : 'vertical', | ||
}); | ||
} | ||
} |
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