|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { checkVersionForNotification } from './releaseNotesNotification'; |
| 7 | + |
| 8 | +describe('releaseNotesNotification', () => { |
| 9 | + describe('checkVersionForNotification', () => { |
| 10 | + describe('version comparison logic', () => { |
| 11 | + it('should show notification when upgrading from 0.6.0 to 0.7.0', () => { |
| 12 | + const result = checkVersionForNotification('0.7.0', '0.6.0', false); |
| 13 | + |
| 14 | + expect(result.shouldShowNotification).toBe(true); |
| 15 | + expect(result.currentMajorMinor).toBe('0.7.0'); |
| 16 | + expect(result.storedMajorMinor).toBe('0.6.0'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should show notification when upgrading from 0.7.0 to 0.8.0', () => { |
| 20 | + const result = checkVersionForNotification('0.8.0', '0.7.0', false); |
| 21 | + |
| 22 | + expect(result.shouldShowNotification).toBe(true); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should show notification when upgrading from 0.7.0 to 1.0.0 (major version change)', () => { |
| 26 | + const result = checkVersionForNotification('1.0.0', '0.7.0', false); |
| 27 | + |
| 28 | + expect(result.shouldShowNotification).toBe(true); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should NOT show notification for patch update (0.7.0 to 0.7.1)', () => { |
| 32 | + const result = checkVersionForNotification('0.7.1', '0.7.0', false); |
| 33 | + |
| 34 | + expect(result.shouldShowNotification).toBe(false); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should NOT show notification for same version', () => { |
| 38 | + const result = checkVersionForNotification('0.7.0', '0.7.0', false); |
| 39 | + |
| 40 | + expect(result.shouldShowNotification).toBe(false); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should NOT show notification when stored version is newer (downgrade scenario)', () => { |
| 44 | + const result = checkVersionForNotification('0.7.0', '0.8.0', false); |
| 45 | + |
| 46 | + expect(result.shouldShowNotification).toBe(false); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + describe('prerelease version handling', () => { |
| 51 | + it('should show notification when upgrading from 0.6.0 to 0.7.1-alpha', () => { |
| 52 | + const result = checkVersionForNotification('0.7.1-alpha', '0.6.0', false); |
| 53 | + |
| 54 | + expect(result.shouldShowNotification).toBe(true); |
| 55 | + expect(result.currentMajorMinor).toBe('0.7.0'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should NOT show notification for patch with prerelease (0.7.0 to 0.7.1-alpha)', () => { |
| 59 | + const result = checkVersionForNotification('0.7.1-alpha', '0.7.0', false); |
| 60 | + |
| 61 | + expect(result.shouldShowNotification).toBe(false); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should show notification when upgrading to minor with prerelease (0.7.0 to 0.8.0-beta)', () => { |
| 65 | + const result = checkVersionForNotification('0.8.0-beta', '0.7.0', false); |
| 66 | + |
| 67 | + expect(result.shouldShowNotification).toBe(true); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should NOT show notification between prerelease versions of same minor (0.7.1-alpha to 0.7.2-beta)', () => { |
| 71 | + const result = checkVersionForNotification('0.7.2-beta', '0.7.1-alpha', false); |
| 72 | + |
| 73 | + expect(result.shouldShowNotification).toBe(false); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should handle stored prerelease version correctly (0.7.0-rc.1 to 0.8.0)', () => { |
| 77 | + const result = checkVersionForNotification('0.8.0', '0.7.0-rc.1', false); |
| 78 | + |
| 79 | + expect(result.shouldShowNotification).toBe(true); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should NOT show notification for same minor with different prereleases (0.7.0-alpha to 0.7.0-beta)', () => { |
| 83 | + const result = checkVersionForNotification('0.7.0-beta', '0.7.0-alpha', false); |
| 84 | + |
| 85 | + expect(result.shouldShowNotification).toBe(false); |
| 86 | + }); |
| 87 | + |
| 88 | + it('should show notification when upgrading from prerelease to release of next minor (0.7.1-alpha to 0.8.0)', () => { |
| 89 | + const result = checkVersionForNotification('0.8.0', '0.7.1-alpha', false); |
| 90 | + |
| 91 | + expect(result.shouldShowNotification).toBe(true); |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + describe('first-time install handling', () => { |
| 96 | + it('should NOT show notification on first install (no stored version, no welcome flag)', () => { |
| 97 | + const result = checkVersionForNotification('0.7.0', undefined, false); |
| 98 | + |
| 99 | + expect(result.shouldShowNotification).toBe(false); |
| 100 | + expect(result.isFirstInstall).toBe(true); |
| 101 | + expect(result.currentMajorMinor).toBe('0.7.0'); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should normalize version on first install with prerelease', () => { |
| 105 | + const result = checkVersionForNotification('0.7.1-alpha', undefined, false); |
| 106 | + |
| 107 | + expect(result.shouldShowNotification).toBe(false); |
| 108 | + expect(result.isFirstInstall).toBe(true); |
| 109 | + expect(result.currentMajorMinor).toBe('0.7.0'); |
| 110 | + expect(result.storedMajorMinor).toBe('0.7.0'); |
| 111 | + }); |
| 112 | + }); |
| 113 | + |
| 114 | + describe('transitional code for 0.7.0 upgrade', () => { |
| 115 | + it('should show notification when upgrading from pre-0.7.0 (welcome flag present, no release notes key)', () => { |
| 116 | + const result = checkVersionForNotification('0.7.0', undefined, true); |
| 117 | + |
| 118 | + expect(result.shouldShowNotification).toBe(true); |
| 119 | + expect(result.isUpgradeFromPre070).toBe(true); |
| 120 | + expect(result.storedMajorMinor).toBe('0.0.0'); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should show notification for pre-0.7.0 upgrade even with prerelease version', () => { |
| 124 | + const result = checkVersionForNotification('0.7.1-alpha', undefined, true); |
| 125 | + |
| 126 | + expect(result.shouldShowNotification).toBe(true); |
| 127 | + expect(result.isUpgradeFromPre070).toBe(true); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + describe('version normalization', () => { |
| 132 | + it('should normalize current version to major.minor.0', () => { |
| 133 | + const result = checkVersionForNotification('0.7.5', '0.6.0', false); |
| 134 | + |
| 135 | + expect(result.currentMajorMinor).toBe('0.7.0'); |
| 136 | + }); |
| 137 | + |
| 138 | + it('should normalize stored version to major.minor.0', () => { |
| 139 | + const result = checkVersionForNotification('0.8.0', '0.7.5', false); |
| 140 | + |
| 141 | + expect(result.storedMajorMinor).toBe('0.7.0'); |
| 142 | + }); |
| 143 | + }); |
| 144 | + |
| 145 | + describe('error handling', () => { |
| 146 | + it('should return parseError for invalid current version', () => { |
| 147 | + const result = checkVersionForNotification('invalid', '0.7.0', false); |
| 148 | + |
| 149 | + expect(result.parseError).toBe(true); |
| 150 | + expect(result.shouldShowNotification).toBe(false); |
| 151 | + }); |
| 152 | + |
| 153 | + it('should handle invalid stored version gracefully (treats as first install)', () => { |
| 154 | + const result = checkVersionForNotification('0.7.0', 'invalid', false); |
| 155 | + |
| 156 | + // Invalid stored version is treated as null (first install scenario) |
| 157 | + expect(result.shouldShowNotification).toBe(false); |
| 158 | + expect(result.isFirstInstall).toBe(true); |
| 159 | + }); |
| 160 | + }); |
| 161 | + }); |
| 162 | +}); |
0 commit comments