Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
FaiChou committed May 5, 2018
1 parent 869f8d2 commit 291125b
Show file tree
Hide file tree
Showing 7 changed files with 6,221 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["react-native"]
}
208 changes: 208 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@

# Created by https://www.gitignore.io/api/reactnative

### ReactNative ###
# React Native Stack Base
### ReactNative.Linux Stack ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### ReactNative.Xcode Stack ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

### ReactNative.Node Stack ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


### ReactNative.Buck Stack ###
buck-out/
.buckconfig.local
.buckd/
.buckversion
.fakebuckversion

### ReactNative.Android Stack ###
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Intellij
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Freeline
freeline.py
freeline/
freeline_project_description.json

### ReactNative.Gradle Stack ###
.gradle
**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

### ReactNative.macOS Stack ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


# End of https://www.gitignore.io/api/reactnative
22 changes: 22 additions & 0 deletions __tests__/ImagePreviewer-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'React';
import ReactTestRenderer from 'react-test-renderer';
import ImagePreviewer from '../index';
const ImgWidth = 300;
const ImgHeight = ImgWidth * 0.6;

describe('ImagePreviewer', () => {
it('renders correctly', () => {
const instance = ReactTestRenderer.create(
<ImagePreviewer
source={{uri: 'http://o7bkcj7d7.bkt.clouddn.com/2.png'}}
style={{
width: ImgWidth,
height: ImgHeight,
}}
resizeMode="stretch"
/>
);

expect(instance.toJSON()).toMatchSnapshot();
});
});
100 changes: 100 additions & 0 deletions __tests__/__snapshots__/ImagePreviewer-test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ImagePreviewer renders correctly 1`] = `
<View>
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
nativeID={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"height": 180,
"width": 300,
}
}
testID={undefined}
>
<Image
resizeMode="stretch"
source={
Object {
"uri": "http://o7bkcj7d7.bkt.clouddn.com/2.png",
}
}
style={
Object {
"flex": 1,
"height": 180,
"width": 300,
}
}
/>
</View>
<Modal
animationType="fade"
hardwareAccelerated={false}
onRequestClose={[Function]}
transparent={true}
visible={false}
>
<View
onMoveShouldSetResponder={[Function]}
onMoveShouldSetResponderCapture={[Function]}
onResponderEnd={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderReject={[Function]}
onResponderRelease={[Function]}
onResponderStart={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
onStartShouldSetResponderCapture={[Function]}
style={
Object {
"backgroundColor": "black",
"bottom": 0,
"left": 0,
"position": "absolute",
"right": 0,
"top": 0,
}
}
>
<Image
resizeMode="contain"
source={
Object {
"uri": "http://o7bkcj7d7.bkt.clouddn.com/2.png",
}
}
style={
Object {
"flex": 1,
"height": "100%",
"left": 0,
"position": "absolute",
"top": 0,
"transform": Array [
Object {
"scale": 1,
},
],
"width": "100%",
}
}
/>
</View>
</Modal>
</View>
`;
23 changes: 21 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,31 @@
"homepage": "https://github.com/FaiChou/ImagePreviewer",
"main": "index.js",
"peerDependencies": {
"react": "*",
"react-native": "*"
},
"dependencies": {
"prop-types": "^15.5.8"
"prop-types": "^15.5.8",
"react": "^16.3.2",
"react-native": "^0.55.3",
"react-test-renderer": "^16.3.2"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-eslint": "^6.1.2",
"babel-jest": "^22.4.3",
"babel-preset-env": "^1.6.1",
"babel-preset-react-native": "^4.0.0",
"eslint": "^2.13.1",
"eslint-plugin-react": "^4.3.0",
"jest": "^22.4.3",
"regenerator-runtime": "^0.11.1"
},
"scripts": {
"lint": "eslint ./"
"lint": "eslint ./",
"test": "jest"
},
"jest": {
"preset": "react-native"
}
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
View,
Modal,
Image,
Platform,
PanResponder,
TouchableWithoutFeedback,
} from 'react-native';
Expand Down
Loading

0 comments on commit 291125b

Please sign in to comment.