|
1 | | -import { getPackageName, getTabBase, getDefaultTab, addDemosOrDeprecated } from '../packageUtils' |
| 1 | +import { getPackageName, getTabBase, getDefaultTab, getDefaultTabForApi, addDemosOrDeprecated } from '../packageUtils' |
2 | 2 |
|
3 | 3 | describe('getPackageName', () => { |
4 | 4 | it('returns empty string for empty input', () => { |
@@ -192,3 +192,70 @@ describe('getDefaultTab', () => { |
192 | 192 | expect(getDefaultTab(filePath)).toBe('') |
193 | 193 | }) |
194 | 194 | }) |
| 195 | + |
| 196 | +describe('getDefaultTabForApi', () => { |
| 197 | + it('returns base tab for regular patternfly package path', () => { |
| 198 | + const filePath = '/path/to/node_modules/@patternfly/patternfly/dist/index.js' |
| 199 | + expect(getDefaultTabForApi(filePath)).toBe('html') |
| 200 | + }) |
| 201 | + |
| 202 | + it('returns base tab for regular react-core package path', () => { |
| 203 | + const filePath = '/path/to/node_modules/@patternfly/react-core/dist/index.js' |
| 204 | + expect(getDefaultTabForApi(filePath)).toBe('react') |
| 205 | + }) |
| 206 | + |
| 207 | + it('returns demos tab for demos path with patternfly package', () => { |
| 208 | + const filePath = '/path/to/node_modules/@patternfly/patternfly/demos/Button.js' |
| 209 | + expect(getDefaultTabForApi(filePath)).toBe('html-demos') |
| 210 | + }) |
| 211 | + |
| 212 | + it('returns demos tab for demos path with react-core package', () => { |
| 213 | + const filePath = '/path/to/node_modules/@patternfly/react-core/demos/Button.js' |
| 214 | + expect(getDefaultTabForApi(filePath)).toBe('react-demos') |
| 215 | + }) |
| 216 | + |
| 217 | + it('returns deprecated tab for deprecated path with patternfly package', () => { |
| 218 | + const filePath = '/path/to/node_modules/@patternfly/patternfly/deprecated/OldButton.js' |
| 219 | + expect(getDefaultTabForApi(filePath)).toBe('html-deprecated') |
| 220 | + }) |
| 221 | + |
| 222 | + it('returns deprecated tab for deprecated path with react-core package', () => { |
| 223 | + const filePath = '/path/to/node_modules/@patternfly/react-core/deprecated/OldButton.js' |
| 224 | + expect(getDefaultTabForApi(filePath)).toBe('react-deprecated') |
| 225 | + }) |
| 226 | + |
| 227 | + it('adds both demos and deprecated when both are in path', () => { |
| 228 | + const filePath = '/path/to/node_modules/@patternfly/react-core/demos/deprecated/Button.js' |
| 229 | + expect(getDefaultTabForApi(filePath)).toBe('react-demos-deprecated') |
| 230 | + }) |
| 231 | + |
| 232 | + it('returns "text" fallback for unknown package', () => { |
| 233 | + const filePath = '/path/to/node_modules/unknown-package/dist/index.js' |
| 234 | + expect(getDefaultTabForApi(filePath)).toBe('text') |
| 235 | + }) |
| 236 | + |
| 237 | + it('returns "text" fallback for path without node_modules', () => { |
| 238 | + const filePath = '/path/to/some/file.js' |
| 239 | + expect(getDefaultTabForApi(filePath)).toBe('text') |
| 240 | + }) |
| 241 | + |
| 242 | + it('returns "text" fallback for empty input', () => { |
| 243 | + expect(getDefaultTabForApi('')).toBe('text') |
| 244 | + }) |
| 245 | + |
| 246 | + it('returns "text" fallback for null/undefined input', () => { |
| 247 | + expect(getDefaultTabForApi(null as any)).toBe('text') |
| 248 | + expect(getDefaultTabForApi(undefined)).toBe('text') |
| 249 | + expect(getDefaultTabForApi()).toBe('text') |
| 250 | + }) |
| 251 | + |
| 252 | + it('returns "text" fallback for unknown package with demos path', () => { |
| 253 | + const filePath = '/path/to/node_modules/unknown-package/demos/Button.js' |
| 254 | + expect(getDefaultTabForApi(filePath)).toBe('text') |
| 255 | + }) |
| 256 | + |
| 257 | + it('returns "text" fallback for unknown package with deprecated path', () => { |
| 258 | + const filePath = '/path/to/node_modules/unknown-package/deprecated/Button.js' |
| 259 | + expect(getDefaultTabForApi(filePath)).toBe('text') |
| 260 | + }) |
| 261 | +}) |
0 commit comments