No Description

reporter.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React, {Component} from 'react';
  2. import {
  3. AppRegistry,
  4. StyleSheet,
  5. Text,
  6. View,
  7. Platform,
  8. ScrollView,
  9. Image,
  10. } from 'react-native';
  11. import Assert from './assert.js'
  12. export default class Reporter extends Component {
  13. render() {
  14. return (
  15. <ScrollView key="rn-test-scroller" style={styles.container}>
  16. {this.renderTests()}
  17. </ScrollView>)
  18. }
  19. renderTests() {
  20. return this.props.context.tests.map((t, i) => {
  21. let pass = true
  22. let foundAssertions = false
  23. Array.isArray(t.result) && t.result.forEach((r) => {
  24. if(r.type.name === 'Assert') {
  25. foundAssertions = true
  26. pass = pass && (r.props.actual === r.props.expect)
  27. }
  28. })
  29. t.status = foundAssertions ? (pass ? 'pass' : 'fail') : t.status
  30. return (<View key={'rn-test-' + t.desc} style={{
  31. borderBottomWidth : 1.5,
  32. borderColor : '#DDD',
  33. }}>
  34. <View key={t.desc} style={{
  35. alignItems : 'center',
  36. flexDirection : 'row'
  37. }}>
  38. <Text style={[styles.badge, {flex : 1, borderWidth : 0}]}>{t.desc}</Text>
  39. <Text style={[styles.badge, this.getBadge(t.status)]}>{t.status}</Text>
  40. </View>
  41. <View key={t.desc + '-result'} style={{backgroundColor : '#F4F4F4'}}>
  42. {t.result}
  43. </View>
  44. </View>)
  45. })
  46. }
  47. getBadge(status) {
  48. if(status === 'running')
  49. return styles.badgeRunning
  50. else if(status === 'pass')
  51. return styles.badgePass
  52. else
  53. return styles.badgeFail
  54. }
  55. }
  56. const styles = StyleSheet.create({
  57. container: {
  58. flex: 1,
  59. marginTop : 40,
  60. },
  61. badge : {
  62. margin : 16,
  63. padding : 4,
  64. borderRadius : 4,
  65. borderWidth : 2,
  66. },
  67. badgePass: {
  68. borderColor : '#00a825',
  69. color : '#00a825'
  70. },
  71. badgeRunning: {
  72. borderColor : '#e3c423',
  73. color : '#e3c423'
  74. },
  75. badgeFail: {
  76. borderColor : '#ff0d0d',
  77. color : '#ff0d0d'
  78. }
  79. });