diff --git a/awx/ui_next/src/util/getDocsBaseUrl.js b/awx/ui_next/src/util/getDocsBaseUrl.js index 31fc671de9..69347e481c 100644 --- a/awx/ui_next/src/util/getDocsBaseUrl.js +++ b/awx/ui_next/src/util/getDocsBaseUrl.js @@ -1,6 +1,7 @@ export default function getDocsBaseUrl(config) { let version = 'latest'; - if (config?.license_info?.license_type !== 'open') { + const licenseType = config?.license_info?.license_type; + if (licenseType && licenseType !== 'open') { version = config?.version ? config.version.split('-')[0] : 'latest'; } return `https://docs.ansible.com/ansible-tower/${version}`; diff --git a/awx/ui_next/src/util/getDocsBaseUrl.test.js b/awx/ui_next/src/util/getDocsBaseUrl.test.js new file mode 100644 index 0000000000..f2e6a5e8aa --- /dev/null +++ b/awx/ui_next/src/util/getDocsBaseUrl.test.js @@ -0,0 +1,44 @@ +import getDocsBaseUrl from './getDocsBaseUrl'; + +describe('getDocsBaseUrl', () => { + it('should return latest version for open license', () => { + const result = getDocsBaseUrl({ + license_info: { + license_type: 'open', + }, + version: '18.0.0', + }); + + expect(result).toEqual('https://docs.ansible.com/ansible-tower/latest'); + }); + + it('should return current version for enterprise license', () => { + const result = getDocsBaseUrl({ + license_info: { + license_type: 'enterprise', + }, + version: '4.0.0', + }); + + expect(result).toEqual('https://docs.ansible.com/ansible-tower/4.0.0'); + }); + + it('should strip version info after hyphen', () => { + const result = getDocsBaseUrl({ + license_info: { + license_type: 'enterprise', + }, + version: '4.0.0-beta', + }); + + expect(result).toEqual('https://docs.ansible.com/ansible-tower/4.0.0'); + }); + + it('should return latest version if license info missing', () => { + const result = getDocsBaseUrl({ + version: '18.0.0', + }); + + expect(result).toEqual('https://docs.ansible.com/ansible-tower/latest'); + }); +});