|
1 | 1 | const j = require('jscodeshift').withParser('ts'); |
2 | 2 |
|
3 | | -const { findTagName, findElementId } = require('../transform'); |
| 3 | +const { |
| 4 | + findTagName, |
| 5 | + findElementId, |
| 6 | + findAttributeBindings, |
| 7 | + findClassNames, |
| 8 | + findClassNameBindings, |
| 9 | +} = require('../transform'); |
4 | 10 |
|
5 | 11 | describe('findTagName()', () => { |
6 | 12 | const TESTS = [ |
@@ -51,3 +57,90 @@ describe('findElementId()', () => { |
51 | 57 | }); |
52 | 58 | } |
53 | 59 | }); |
| 60 | + |
| 61 | +describe('findAttributeBindings()', () => { |
| 62 | + const TESTS = [ |
| 63 | + ['', new Map()], |
| 64 | + ["attributeBindings: ['foo']", new Map([['foo', 'foo']])], |
| 65 | + ["attributeBindings: ['foo:bar', 'BAZ']", new Map([['foo', 'bar'], ['BAZ', 'BAZ']])], |
| 66 | + ["attributeBindings: ''", /Unexpected `attributeBindings` value: ''/], |
| 67 | + ['attributeBindings: 5', /Unexpected `attributeBindings` value: 5/], |
| 68 | + ['attributeBindings: foo', /Unexpected `attributeBindings` value: foo/], |
| 69 | + ['attributeBindings: [42]', /Unexpected `attributeBindings` value: \[42]/], |
| 70 | + ]; |
| 71 | + |
| 72 | + for (let [input, expected] of TESTS) { |
| 73 | + test(input || 'empty', () => { |
| 74 | + let props = j(`export default {${input}};`) |
| 75 | + .find(j.ExportDefaultDeclaration) |
| 76 | + .get('declaration', 'properties'); |
| 77 | + |
| 78 | + if (expected instanceof RegExp) { |
| 79 | + expect(() => findAttributeBindings(props)).toThrow(expected); |
| 80 | + } else { |
| 81 | + expect(findAttributeBindings(props)).toEqual(expected); |
| 82 | + } |
| 83 | + }); |
| 84 | + } |
| 85 | +}); |
| 86 | + |
| 87 | +describe('findClassNames()', () => { |
| 88 | + const TESTS = [ |
| 89 | + ['', []], |
| 90 | + ["classNames: ['foo']", ['foo']], |
| 91 | + ["classNames: ['foo', 'bar']", ['foo', 'bar']], |
| 92 | + ["classNames: ['foo', 'bar', 'BAZ']", ['foo', 'bar', 'BAZ']], |
| 93 | + ["classNames: ''", /Unexpected `classNames` value: ''/], |
| 94 | + ['classNames: 5', /Unexpected `classNames` value: 5/], |
| 95 | + ['classNames: foo', /Unexpected `classNames` value: foo/], |
| 96 | + ['classNames: [42]', /Unexpected `classNames` value: \[42]/], |
| 97 | + ]; |
| 98 | + |
| 99 | + for (let [input, expected] of TESTS) { |
| 100 | + test(input || 'empty', () => { |
| 101 | + let props = j(`export default {${input}};`) |
| 102 | + .find(j.ExportDefaultDeclaration) |
| 103 | + .get('declaration', 'properties'); |
| 104 | + |
| 105 | + if (expected instanceof RegExp) { |
| 106 | + expect(() => findClassNames(props)).toThrow(expected); |
| 107 | + } else { |
| 108 | + expect(findClassNames(props)).toEqual(expected); |
| 109 | + } |
| 110 | + }); |
| 111 | + } |
| 112 | +}); |
| 113 | + |
| 114 | +describe('findClassNameBindings()', () => { |
| 115 | + const TESTS = [ |
| 116 | + ['', new Map()], |
| 117 | + ["classNameBindings: ['foo']", new Map([['foo', ['foo', null]]])], |
| 118 | + ["classNameBindings: ['fooBar']", new Map([['fooBar', ['foo-bar', null]]])], |
| 119 | + ["classNameBindings: ['FOO']", new Map([['FOO', ['foo', null]]])], |
| 120 | + ["classNameBindings: ['foo:bar']", new Map([['foo', ['bar', null]]])], |
| 121 | + ["classNameBindings: ['foo:bar:baz']", new Map([['foo', ['bar', 'baz']]])], |
| 122 | + ["classNameBindings: ['foo::baz']", new Map([['foo', [null, 'baz']]])], |
| 123 | + [ |
| 124 | + "classNameBindings: ['foo', 'bar']", |
| 125 | + new Map([['foo', ['foo', null]], ['bar', ['bar', null]]]), |
| 126 | + ], |
| 127 | + ["classNameBindings: ''", /Unexpected `classNameBindings` value: ''/], |
| 128 | + ['classNameBindings: 5', /Unexpected `classNameBindings` value: 5/], |
| 129 | + ['classNameBindings: foo', /Unexpected `classNameBindings` value: foo/], |
| 130 | + ['classNameBindings: [42]', /Unexpected `classNameBindings` value: \[42]/], |
| 131 | + ]; |
| 132 | + |
| 133 | + for (let [input, expected] of TESTS) { |
| 134 | + test(input || 'empty', () => { |
| 135 | + let props = j(`export default {${input}};`) |
| 136 | + .find(j.ExportDefaultDeclaration) |
| 137 | + .get('declaration', 'properties'); |
| 138 | + |
| 139 | + if (expected instanceof RegExp) { |
| 140 | + expect(() => findClassNameBindings(props)).toThrow(expected); |
| 141 | + } else { |
| 142 | + expect(findClassNameBindings(props)).toEqual(expected); |
| 143 | + } |
| 144 | + }); |
| 145 | + } |
| 146 | +}); |
0 commit comments