adapter.test.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { variableAdapters } from '../adapters';
  2. import { textboxBuilder } from '../shared/testing/builders';
  3. import { VariableHide } from '../types';
  4. import { createTextBoxVariableAdapter } from './adapter';
  5. variableAdapters.setInit(() => [createTextBoxVariableAdapter()]);
  6. describe('createTextBoxVariableAdapter', () => {
  7. describe('getSaveModel', () => {
  8. describe('when called and query differs from the original query and not saving current as default', () => {
  9. it('then the model should be correct', () => {
  10. const text = textboxBuilder()
  11. .withId('text')
  12. .withRootStateKey('key')
  13. .withName('text')
  14. .withQuery('query')
  15. .withOriginalQuery('original')
  16. .withCurrent('query')
  17. .withOptions('query')
  18. .build();
  19. const adapter = variableAdapters.get('textbox');
  20. const result = adapter.getSaveModel(text, false);
  21. expect(result).toEqual({
  22. name: 'text',
  23. query: 'original',
  24. current: { selected: false, text: 'original', value: 'original' },
  25. options: [{ selected: false, text: 'original', value: 'original' }],
  26. type: 'textbox',
  27. hide: VariableHide.dontHide,
  28. skipUrlSync: false,
  29. error: null,
  30. description: null,
  31. });
  32. });
  33. });
  34. describe('when called and query differs from the original query and saving current as default', () => {
  35. it('then the model should be correct', () => {
  36. const text = textboxBuilder()
  37. .withId('text')
  38. .withRootStateKey('key')
  39. .withName('text')
  40. .withQuery('query')
  41. .withOriginalQuery('original')
  42. .withCurrent('query')
  43. .withOptions('query')
  44. .build();
  45. const adapter = variableAdapters.get('textbox');
  46. const result = adapter.getSaveModel(text, true);
  47. expect(result).toEqual({
  48. name: 'text',
  49. query: 'query',
  50. current: { selected: true, text: 'query', value: 'query' },
  51. options: [{ selected: false, text: 'query', value: 'query' }],
  52. type: 'textbox',
  53. hide: VariableHide.dontHide,
  54. skipUrlSync: false,
  55. error: null,
  56. description: null,
  57. });
  58. });
  59. });
  60. });
  61. describe('beforeAdding', () => {
  62. describe('when called', () => {
  63. it('then originalQuery should be same added', () => {
  64. const model = { name: 'text', query: 'a query' };
  65. const adapter = variableAdapters.get('textbox');
  66. const result = adapter.beforeAdding!(model);
  67. expect(result).toEqual({ name: 'text', query: 'a query', originalQuery: 'a query' });
  68. });
  69. });
  70. });
  71. });