|
| 1 | +import { API, FileInfo, Options } from 'jscodeshift'; |
| 2 | +const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest; |
| 3 | + |
| 4 | +import { addIsRemovableFlag } from '../motions/add-isRemovable-flag'; |
| 5 | + |
| 6 | +function transformer( |
| 7 | + fileInfo: FileInfo, |
| 8 | + { jscodeshift: j }: API, |
| 9 | + options: Options, |
| 10 | +) { |
| 11 | + const source = j(fileInfo.source); |
| 12 | + |
| 13 | + addIsRemovableFlag(j, source); |
| 14 | + |
| 15 | + return source.toSource(options.printOptions); |
| 16 | +} |
| 17 | + |
| 18 | +describe('Update isRemovable prop', () => { |
| 19 | + defineInlineTest( |
| 20 | + { default: transformer, parser: 'tsx' }, |
| 21 | + {}, |
| 22 | + ` |
| 23 | + import React from "react"; |
| 24 | + import Tag from "@atlaskit/tag"; |
| 25 | +
|
| 26 | + export default () => <Tag text="Removable button"/>; |
| 27 | + `, |
| 28 | + ` |
| 29 | + import React from "react"; |
| 30 | + import Tag from "@atlaskit/tag"; |
| 31 | +
|
| 32 | + export default () => <Tag text="Removable button"/>; |
| 33 | + `, |
| 34 | + 'should not add isRemovable flag when no removeButtonText defined', |
| 35 | + ); |
| 36 | + |
| 37 | + defineInlineTest( |
| 38 | + { default: transformer, parser: 'tsx' }, |
| 39 | + {}, |
| 40 | + ` |
| 41 | + import React from "react"; |
| 42 | + import Tag from "@atlaskit/tag"; |
| 43 | +
|
| 44 | + export default () => <Tag text="Removable button" removeButtonText=""/>; |
| 45 | + `, |
| 46 | + ` |
| 47 | + import React from "react"; |
| 48 | + import Tag from "@atlaskit/tag"; |
| 49 | +
|
| 50 | + export default () => <Tag text="Removable button" removeButtonText=""/>; |
| 51 | + `, |
| 52 | + 'should not adding isRemovable flag when removeButtonText has empty text', |
| 53 | + ); |
| 54 | + |
| 55 | + defineInlineTest( |
| 56 | + { default: transformer, parser: 'tsx' }, |
| 57 | + {}, |
| 58 | + ` |
| 59 | + import React from "react"; |
| 60 | + import Tag from "@atlaskit/tag"; |
| 61 | +
|
| 62 | + export default () => <Tag text="Removable button" removeButtonText="Remove" />; |
| 63 | + `, |
| 64 | + ` |
| 65 | + import React from "react"; |
| 66 | + import Tag from "@atlaskit/tag"; |
| 67 | +
|
| 68 | + export default () => <Tag text="Removable button" isRemovable removeButtonText="Remove" />; |
| 69 | + `, |
| 70 | + 'should add isRemovable flag when there is a removeButtonText defined', |
| 71 | + ); |
| 72 | + |
| 73 | + defineInlineTest( |
| 74 | + { default: transformer, parser: 'tsx' }, |
| 75 | + {}, |
| 76 | + ` |
| 77 | + import React from "react"; |
| 78 | + import RemovableTag from "@atlaskit/tag"; |
| 79 | +
|
| 80 | + export default () => <RemovableTag text="Removable button" removeButtonText="Remove" />; |
| 81 | + `, |
| 82 | + ` |
| 83 | + import React from "react"; |
| 84 | + import RemovableTag from "@atlaskit/tag"; |
| 85 | +
|
| 86 | + export default () => <RemovableTag text="Removable button" isRemovable removeButtonText="Remove" />; |
| 87 | + `, |
| 88 | + 'should add isRemovable flag when there is a removeButtonText defined for importing tag with alias', |
| 89 | + ); |
| 90 | + |
| 91 | + defineInlineTest( |
| 92 | + { default: transformer, parser: 'tsx' }, |
| 93 | + {}, |
| 94 | + ` |
| 95 | + import React from "react"; |
| 96 | + import RemovableTag from "@atlaskit/tag"; |
| 97 | +
|
| 98 | + const removeButtonLabel = "remove button"; |
| 99 | +
|
| 100 | + export default () => <RemovableTag text="Removable button" removeButtonText={removeButtonLabel} />; |
| 101 | + `, |
| 102 | + ` |
| 103 | + import React from "react"; |
| 104 | + import RemovableTag from "@atlaskit/tag"; |
| 105 | +
|
| 106 | + const removeButtonLabel = "remove button"; |
| 107 | +
|
| 108 | + export default () => <RemovableTag text="Removable button" isRemovable removeButtonText={removeButtonLabel} />; |
| 109 | + `, |
| 110 | + 'should add isRemovable flag when there is a removeButtonText defined as a variable', |
| 111 | + ); |
| 112 | + |
| 113 | + defineInlineTest( |
| 114 | + { default: transformer, parser: 'tsx' }, |
| 115 | + {}, |
| 116 | + ` |
| 117 | + import React from "react"; |
| 118 | + import Tag from "@atlaskit/tag"; |
| 119 | +
|
| 120 | + const removeButtonLabel = "remove button"; |
| 121 | +
|
| 122 | + export default () => ( |
| 123 | + <div> |
| 124 | + <Tag text="Removable button" removeButtonText="Remove" /> |
| 125 | + <Tag text="Removable button" removeButtonText={removeButtonLabel} /> |
| 126 | + <Tag text="Removable button" /> |
| 127 | + </div>); |
| 128 | + `, |
| 129 | + ` |
| 130 | + import React from "react"; |
| 131 | + import Tag from "@atlaskit/tag"; |
| 132 | +
|
| 133 | + const removeButtonLabel = "remove button"; |
| 134 | +
|
| 135 | + export default () => ( |
| 136 | + <div> |
| 137 | + <Tag text="Removable button" isRemovable removeButtonText="Remove" /> |
| 138 | + <Tag text="Removable button" isRemovable removeButtonText={removeButtonLabel} /> |
| 139 | + <Tag text="Removable button" /> |
| 140 | + </div>); |
| 141 | + `, |
| 142 | + 'should add isRemovable flag for different cases', |
| 143 | + ); |
| 144 | + |
| 145 | + defineInlineTest( |
| 146 | + { default: transformer, parser: 'tsx' }, |
| 147 | + {}, |
| 148 | + ` |
| 149 | + import React from "react"; |
| 150 | + import { SimpleTag as Tag } from "@atlaskit/tag"; |
| 151 | +
|
| 152 | + export default () => <Tag text="Removable button" removeButtonText="Remove" />; |
| 153 | + `, |
| 154 | + ` |
| 155 | + import React from "react"; |
| 156 | + import { SimpleTag as Tag } from "@atlaskit/tag"; |
| 157 | +
|
| 158 | + export default () => <Tag text="Removable button" removeButtonText="Remove" />; |
| 159 | + `, |
| 160 | + 'should not add isRemovable flag when it is SimpleTag', |
| 161 | + ); |
| 162 | + |
| 163 | + defineInlineTest( |
| 164 | + { default: transformer, parser: 'tsx' }, |
| 165 | + {}, |
| 166 | + ` |
| 167 | + import React from "react"; |
| 168 | + import Tag from "@facebook/tag"; |
| 169 | +
|
| 170 | + export default () => <Tag text="Removable button" removeButtonText="Remove" />; |
| 171 | + `, |
| 172 | + ` |
| 173 | + import React from "react"; |
| 174 | + import Tag from "@facebook/tag"; |
| 175 | +
|
| 176 | + export default () => <Tag text="Removable button" removeButtonText="Remove" />; |
| 177 | + `, |
| 178 | + 'should not add isRemovable flag when it is from other tag lib', |
| 179 | + ); |
| 180 | +}); |
0 commit comments