-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Splitting Profile in separate components for accessibility snapshot testing #4
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,30 @@ | ||
import Foundation | ||
import XCTest | ||
import React | ||
|
||
@objc(SnapshotTests) | ||
class SnapshotTests: NSObject, RCTBridgeModule { | ||
static func moduleName() -> String! { | ||
"SnapshotTests" | ||
} | ||
|
||
var items: [String]? = [] | ||
|
||
@objc(registerName:) | ||
func register(name: String) -> NSNumber? { | ||
guard let items = items else { | ||
return nil | ||
} | ||
|
||
if items.contains(name) { | ||
self.items = nil | ||
NSException.raise(.init(rawValue: "Name already registered"), | ||
format: "%@ already registered", | ||
arguments: getVaList([name])) | ||
print("\(name) already registered") | ||
} | ||
|
||
self.items!.append(name) | ||
return NSNumber(booleanLiteral: true) | ||
} | ||
} |
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,7 @@ | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface RCT_EXTERN_MODULE(SnapshotTests, NSObject) | ||
|
||
RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(registerName:(NSString *)name) | ||
|
||
@end |
Binary file added
BIN
+74.9 KB
...s/__Snapshots__/AccessibilitySnapshotTests/accessibility.ProfileButtonsTest.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+66.8 KB
...s/__Snapshots__/AccessibilitySnapshotTests/accessibility.ProfilePictureTest.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+77.5 KB
...sts/__Snapshots__/AccessibilitySnapshotTests/accessibility.ProfileStatsTest.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
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,23 +1,24 @@ | ||
import React from 'react'; | ||
import { | ||
AppRegistry, | ||
Image, | ||
StyleSheet, | ||
Text, | ||
TouchableOpacity, | ||
View, | ||
} from 'react-native'; | ||
import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native'; | ||
import registerAccessibilitySnapshotNode from './utils/registerAccessibilitySnapshotNode'; | ||
|
||
const tomProfilePicture = | ||
'https://images.unsplash.com/photo-1569591159212-b02ea8a9f239?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MzN8fGNhdHxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=900&q=60'; | ||
|
||
export default function Profile({ | ||
picture = tomProfilePicture, | ||
}: { | ||
picture: string; | ||
}) { | ||
export default function Profile({picture}: {picture?: string}) { | ||
return ( | ||
<View style={styles.container}> | ||
<ProfilePicture picture={picture} /> | ||
<Text style={styles.text}>Tom</Text> | ||
<Stats /> | ||
<Buttons /> | ||
</View> | ||
); | ||
} | ||
|
||
function ProfilePicture({picture = tomProfilePicture}: {picture?: string}) { | ||
return ( | ||
<> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fragments were used in order to have a simpler diff |
||
<TouchableOpacity | ||
aria-label="Profile picture" | ||
accessibilityHint="Double tap to edit" | ||
|
@@ -31,8 +32,13 @@ export default function Profile({ | |
</Text> | ||
</View> | ||
</TouchableOpacity> | ||
<Text style={styles.text}>Tom</Text> | ||
</> | ||
); | ||
} | ||
|
||
function Stats() { | ||
return ( | ||
<> | ||
<View style={styles.stats}> | ||
<View style={styles.stat} accessible aria-label="Games: 15"> | ||
<Text style={styles.statNumber} maxFontSizeMultiplier={3}> | ||
|
@@ -55,7 +61,13 @@ export default function Profile({ | |
<Text maxFontSizeMultiplier={2.7}>Points</Text> | ||
</View> | ||
</View> | ||
</> | ||
); | ||
} | ||
|
||
function Buttons() { | ||
return ( | ||
<> | ||
<View style={styles.buttons}> | ||
<TouchableOpacity | ||
style={styles.button} | ||
|
@@ -70,10 +82,9 @@ export default function Profile({ | |
<Text style={styles.buttonText}>Delete Profile</Text> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
</> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
|
@@ -148,7 +159,11 @@ const styles = StyleSheet.create({ | |
}); | ||
|
||
if (__DEV__) { | ||
AppRegistry.registerComponent('ProfileTest', () => () => ( | ||
<Profile picture="" /> | ||
)); | ||
registerAccessibilitySnapshotNode('ProfileTest', <Profile picture="" />); | ||
registerAccessibilitySnapshotNode( | ||
'ProfilePictureTest', | ||
<ProfilePicture picture="" />, | ||
); | ||
registerAccessibilitySnapshotNode('ProfileStatsTest', <Stats />); | ||
registerAccessibilitySnapshotNode('ProfileButtonsTest', <Buttons />); | ||
} |
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,17 @@ | ||
import {AppRegistry, NativeModules} from 'react-native'; | ||
|
||
export default function registerAccessibilitySnapshotNode( | ||
name: string, | ||
node: JSX.Element, | ||
) { | ||
AppRegistry.registerComponent(name, () => () => node); | ||
const {SnapshotTests} = NativeModules; | ||
if (!SnapshotTests) { | ||
return; | ||
} | ||
|
||
const result = SnapshotTests.registerName(name); | ||
if (!result) { | ||
throw new Error(`Couldn't register ${name}`); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.