react-native-navigation的迁移库

OptionsProcessor.test.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const OptionsProcessor = require('./OptionsProcessor');
  2. const Options = require('./../params/options/Options');
  3. describe('navigation options', () => {
  4. let options;
  5. beforeEach(() => {
  6. options = {};
  7. });
  8. it('processes colors into numeric AARRGGBB', () => {
  9. options.someKeyColor = 'red';
  10. OptionsProcessor.processOptions(options);
  11. expect(options.someKeyColor).toEqual(0xffff0000);
  12. options.someKeyColor = 'yellow';
  13. OptionsProcessor.processOptions(options);
  14. expect(options.someKeyColor).toEqual(0xffffff00);
  15. });
  16. it('processes numeric colors', () => {
  17. options.someKeyColor = '#123456';
  18. OptionsProcessor.processOptions(options);
  19. expect(options.someKeyColor).toEqual(0xff123456);
  20. options.someKeyColor = 0x123456ff; // wut
  21. OptionsProcessor.processOptions(options);
  22. expect(options.someKeyColor).toEqual(0xff123456);
  23. });
  24. it('process colors with rgb functions', () => {
  25. options.someKeyColor = 'rgb(255, 0, 255)';
  26. OptionsProcessor.processOptions(options);
  27. expect(options.someKeyColor).toEqual(0xffff00ff);
  28. });
  29. it('process colors with special words', () => {
  30. options.someKeyColor = 'fuchsia';
  31. OptionsProcessor.processOptions(options);
  32. expect(options.someKeyColor).toEqual(0xffff00ff);
  33. });
  34. it('process colors with hsla functions', () => {
  35. options.someKeyColor = 'hsla(360, 100%, 100%, 1.0)';
  36. OptionsProcessor.processOptions(options);
  37. expect(options.someKeyColor).toEqual(0xffffffff);
  38. });
  39. it('unknown colors return undefined', () => {
  40. options.someKeyColor = 'wut';
  41. OptionsProcessor.processOptions(options);
  42. expect(options.someKeyColor).toEqual(undefined);
  43. });
  44. it('any keys ending with Color', () => {
  45. options.otherKeyColor = 'red';
  46. options.yetAnotherColor = 'blue';
  47. options.andAnotherColor = 'rgb(0, 255, 0)';
  48. OptionsProcessor.processOptions(options);
  49. expect(options.otherKeyColor).toEqual(0xffff0000);
  50. expect(options.yetAnotherColor).toEqual(0xff0000ff);
  51. expect(options.andAnotherColor).toEqual(0xff00ff00);
  52. });
  53. it('keys ending with Color case sensitive', () => {
  54. options.otherKey_color = 'red'; // eslint-disable-line camelcase
  55. OptionsProcessor.processOptions(options);
  56. expect(options.otherKey_color).toEqual('red');
  57. });
  58. it('any nested recursive keys ending with Color', () => {
  59. options.topBar = { textColor: 'red' };
  60. options.topBar.innerMostObj = { anotherColor: 'yellow' };
  61. OptionsProcessor.processOptions(options);
  62. expect(options.topBar.textColor).toEqual(0xffff0000);
  63. expect(options.topBar.innerMostObj.anotherColor).toEqual(0xffffff00);
  64. });
  65. it('resolve image sources with name/ending with icon', () => {
  66. options.icon = 'require("https://wix.github.io/react-native-navigation/_images/logo.png");';
  67. options.topBar = {
  68. myIcon: 'require("https://wix.github.io/react-native-navigation/_images/logo.png");',
  69. myOtherValue: 'value'
  70. };
  71. OptionsProcessor.processOptions(options);
  72. // As we can't import external images and we don't want to add an image here
  73. // I assign the icons to strings (what the require would generally look like)
  74. // and expect the value to be resovled, in this case it doesn't find anything and returns null
  75. expect(options.icon).toEqual(null);
  76. expect(options.topBar.myIcon).toEqual(null);
  77. expect(options.topBar.myOtherValue).toEqual('value');
  78. });
  79. it('processes NavigationOptions jsDoc object', () => {
  80. options.someKeyColor = 'rgb(255, 0, 255)';
  81. options.topBar = { textColor: 'red' };
  82. options.topBar.innerMostObj = { anotherColor: 'yellow' };
  83. const navigationOptionsObj = new Options(options);
  84. OptionsProcessor.processOptions(navigationOptionsObj);
  85. expect(navigationOptionsObj.topBar.textColor).toEqual(0xffff0000);
  86. });
  87. it('undefined value return undefined ', () => {
  88. options.someImage = undefined;
  89. OptionsProcessor.processOptions(options);
  90. expect(options.someImage).toEqual(undefined);
  91. });
  92. });