Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util-rewire.spec.ts 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { seedTokens, rewireSource, rewireSpecs } from '../../src/util';
  2. test('source to spec', () => {
  3. const block = {
  4. description: '',
  5. tags: [
  6. {
  7. tag: 'my-tag',
  8. name: '',
  9. type: '',
  10. optional: false,
  11. description: '',
  12. problems: [],
  13. source: [
  14. {
  15. number: 2,
  16. source: '...changed in spec...',
  17. tokens: seedTokens({ name: '...changed in spec...' }),
  18. },
  19. ],
  20. },
  21. ],
  22. source: [
  23. {
  24. number: 1,
  25. source: 'source line 1',
  26. tokens: seedTokens(),
  27. },
  28. {
  29. number: 2,
  30. source: 'source line 2',
  31. tokens: seedTokens({ name: 'source' }),
  32. },
  33. ],
  34. problems: [],
  35. };
  36. // source is unsynced
  37. expect(block.source[1] === block.tags[0].source[0]).toBe(false);
  38. rewireSource(block);
  39. // source is referenced
  40. expect(block.source[1] === block.tags[0].source[0]).toBe(true);
  41. // non-tag line stays unchanged
  42. expect(block.source[0].source).toEqual('source line 1');
  43. // tag-holding source line stays unchanged
  44. expect(block.source[1].source).toEqual('source line 2');
  45. expect(block.source[1].tokens.name).toEqual('source');
  46. // tag source inherits block source
  47. expect(block.tags[0].source[0].source).toEqual('source line 2');
  48. expect(block.tags[0].source[0].tokens.name).toEqual('source');
  49. });
  50. test('spec to source', () => {
  51. const block = {
  52. description: '',
  53. tags: [
  54. {
  55. tag: 'my-tag',
  56. name: '',
  57. type: '',
  58. optional: false,
  59. description: '',
  60. problems: [],
  61. source: [
  62. {
  63. number: 2,
  64. source: '...changed in spec...',
  65. tokens: seedTokens({ name: '...changed in spec...' }),
  66. },
  67. ],
  68. },
  69. ],
  70. source: [
  71. {
  72. number: 1,
  73. source: 'source line 1',
  74. tokens: seedTokens(),
  75. },
  76. {
  77. number: 2,
  78. source: 'source line 2',
  79. tokens: seedTokens({ name: 'source' }),
  80. },
  81. ],
  82. problems: [],
  83. };
  84. // source is unsynced
  85. expect(block.source[1] === block.tags[0].source[0]).toBe(false);
  86. rewireSpecs(block);
  87. // source is referenced
  88. expect(block.source[1] === block.tags[0].source[0]).toBe(true);
  89. // non-tag line stays unchanged
  90. expect(block.source[0].source).toEqual('source line 1');
  91. // tag-holding source line inherits spec source
  92. expect(block.source[1].source).toEqual('...changed in spec...');
  93. expect(block.source[1].tokens.name).toEqual('...changed in spec...');
  94. // tag source inherits block source
  95. expect(block.tags[0].source[0].source).toEqual('...changed in spec...');
  96. expect(block.tags[0].source[0].tokens.name).toEqual('...changed in spec...');
  97. });