|
1 | 1 | import React from 'react'; |
2 | 2 | import { render, screen, waitFor } from '@testing-library/react'; |
3 | 3 | import { IntlProvider } from 'react-intl'; |
4 | | -import APIPanel from './APIPanel'; |
| 4 | +import APIPanel, { |
| 5 | + convertToConsoleDocsUrl, |
| 6 | + getConsoleBaseUrl, |
| 7 | +} from './APIPanel'; |
5 | 8 | import { |
6 | 9 | fetchBundleInfo, |
7 | 10 | fetchBundles, |
@@ -245,3 +248,113 @@ describe('APIPanel', () => { |
245 | 248 | expect(screen.getByText('Cost-Management')).toBeInTheDocument(); |
246 | 249 | }); |
247 | 250 | }); |
| 251 | + |
| 252 | +describe('getConsoleBaseUrl', () => { |
| 253 | + it('returns production URL for prod environment', () => { |
| 254 | + expect(getConsoleBaseUrl('prod')).toBe('https://console.redhat.com'); |
| 255 | + }); |
| 256 | + |
| 257 | + it('returns stage URL for stage environment', () => { |
| 258 | + expect(getConsoleBaseUrl('stage')).toBe('https://console.stage.redhat.com'); |
| 259 | + }); |
| 260 | + |
| 261 | + it('returns stage URL for frhStage environment', () => { |
| 262 | + expect(getConsoleBaseUrl('frhStage')).toBe( |
| 263 | + 'https://console.stage.redhat.com' |
| 264 | + ); |
| 265 | + }); |
| 266 | + |
| 267 | + it('returns production URL for qa environment (default)', () => { |
| 268 | + expect(getConsoleBaseUrl('qa')).toBe('https://console.redhat.com'); |
| 269 | + }); |
| 270 | + |
| 271 | + it('returns production URL for ci environment (default)', () => { |
| 272 | + expect(getConsoleBaseUrl('ci')).toBe('https://console.redhat.com'); |
| 273 | + }); |
| 274 | +}); |
| 275 | + |
| 276 | +describe('convertToConsoleDocsUrl', () => { |
| 277 | + it('converts API name and version to console docs URL (production)', () => { |
| 278 | + const result = convertToConsoleDocsUrl( |
| 279 | + 'notifications', |
| 280 | + 'https://developers.redhat.com/api-catalog/api/notifications/v2.0', |
| 281 | + 'prod' |
| 282 | + ); |
| 283 | + |
| 284 | + expect(result).toBe('https://console.redhat.com/docs/api/notifications/v2'); |
| 285 | + }); |
| 286 | + |
| 287 | + it('converts API name and version to console docs URL (stage)', () => { |
| 288 | + const result = convertToConsoleDocsUrl( |
| 289 | + 'notifications', |
| 290 | + 'https://developers.redhat.com/api-catalog/api/notifications/v2.0', |
| 291 | + 'stage' |
| 292 | + ); |
| 293 | + |
| 294 | + expect(result).toBe( |
| 295 | + 'https://console.stage.redhat.com/docs/api/notifications/v2' |
| 296 | + ); |
| 297 | + }); |
| 298 | + |
| 299 | + it('strips API suffix from name', () => { |
| 300 | + const result = convertToConsoleDocsUrl( |
| 301 | + 'notifications api', |
| 302 | + 'https://developers.redhat.com/api-catalog/api/notifications/v1', |
| 303 | + 'prod' |
| 304 | + ); |
| 305 | + |
| 306 | + expect(result).toBe('https://console.redhat.com/docs/api/notifications/v1'); |
| 307 | + }); |
| 308 | + |
| 309 | + it('handles APIs without version numbers', () => { |
| 310 | + const result = convertToConsoleDocsUrl( |
| 311 | + 'advisor api', |
| 312 | + 'https://developers.redhat.com/api-catalog/api/advisor', |
| 313 | + 'prod' |
| 314 | + ); |
| 315 | + |
| 316 | + expect(result).toBe('https://console.redhat.com/docs/api/advisor'); |
| 317 | + }); |
| 318 | + |
| 319 | + it('extracts only major version from v1.0', () => { |
| 320 | + const result = convertToConsoleDocsUrl( |
| 321 | + 'notifications', |
| 322 | + 'https://developers.redhat.com/api-catalog/api/notifications/v1.0', |
| 323 | + 'prod' |
| 324 | + ); |
| 325 | + |
| 326 | + expect(result).toBe('https://console.redhat.com/docs/api/notifications/v1'); |
| 327 | + }); |
| 328 | + |
| 329 | + it('extracts major version from v3.1.0', () => { |
| 330 | + const result = convertToConsoleDocsUrl( |
| 331 | + 'sources', |
| 332 | + 'https://developers.redhat.com/api-catalog/api/sources/v3.1.0', |
| 333 | + 'prod' |
| 334 | + ); |
| 335 | + |
| 336 | + expect(result).toBe('https://console.redhat.com/docs/api/sources/v3'); |
| 337 | + }); |
| 338 | + |
| 339 | + it('lowercases API name', () => { |
| 340 | + const result = convertToConsoleDocsUrl( |
| 341 | + 'RBAC', |
| 342 | + 'https://developers.redhat.com/api-catalog/api/rbac/v1', |
| 343 | + 'prod' |
| 344 | + ); |
| 345 | + |
| 346 | + expect(result).toBe('https://console.redhat.com/docs/api/rbac/v1'); |
| 347 | + }); |
| 348 | + |
| 349 | + it('handles frhStage environment correctly', () => { |
| 350 | + const result = convertToConsoleDocsUrl( |
| 351 | + 'notifications', |
| 352 | + 'https://developers.redhat.com/api-catalog/api/notifications/v2.0', |
| 353 | + 'frhStage' |
| 354 | + ); |
| 355 | + |
| 356 | + expect(result).toBe( |
| 357 | + 'https://console.stage.redhat.com/docs/api/notifications/v2' |
| 358 | + ); |
| 359 | + }); |
| 360 | +}); |
0 commit comments