|
| 1 | +import variables, { computeYearsExperience } from './variables' |
| 2 | + |
| 3 | +describe('variables', () => { |
| 4 | + describe('static string values', () => { |
| 5 | + it('LINKEDIN_URL should be the correct LinkedIn profile URL', () => { |
| 6 | + expect(variables.LINKEDIN_URL).toBe('https://linkedin.com/in/jackdomleo7/') |
| 7 | + }) |
| 8 | + |
| 9 | + it('GITHUB_URL should be the correct GitHub profile URL', () => { |
| 10 | + expect(variables.GITHUB_URL).toBe('https://github.com/jackdomleo7') |
| 11 | + }) |
| 12 | + |
| 13 | + it('CODEPEN_URL should be the correct CodePen profile URL', () => { |
| 14 | + expect(variables.CODEPEN_URL).toBe('https://codepen.io/jackdomleo7') |
| 15 | + }) |
| 16 | + |
| 17 | + it('OCCUPATION should be Lead Frontend Engineer', () => { |
| 18 | + expect(variables.OCCUPATION).toBe('Lead Frontend Engineer') |
| 19 | + }) |
| 20 | + }) |
| 21 | + |
| 22 | + describe('CURRENT_YEAR', () => { |
| 23 | + it('should be a 4-digit calendar year', () => { |
| 24 | + expect(variables.CURRENT_YEAR).toBeGreaterThanOrEqual(2024) |
| 25 | + expect(variables.CURRENT_YEAR).toBeLessThanOrEqual(2100) |
| 26 | + }) |
| 27 | + |
| 28 | + it('should match the actual current year at runtime', () => { |
| 29 | + expect(variables.CURRENT_YEAR).toBe(new Date().getFullYear()) |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + describe('computeYearsExperience()', () => { |
| 34 | + // Career start date: 2018-09-03 |
| 35 | + // The function counts complete career quarters and maps remainders: |
| 36 | + // remainder 0 → exactly N years → "N" |
| 37 | + // remainder 1 → just past a year mark → "just over N" |
| 38 | + // remainder 2 → mid-year → "N and a half" |
| 39 | + // remainder 3 → approaching next year → "nearly N+1" |
| 40 | + |
| 41 | + it('returns exact years when on an anniversary (remainder 0)', () => { |
| 42 | + // 2025-09-03 = exactly 28 quarters (7 years) from 2018-09-03 |
| 43 | + expect(computeYearsExperience(new Date('2025-09-03'))).toBe('7') |
| 44 | + }) |
| 45 | + |
| 46 | + it('returns "just over N" when 1 quarter past an anniversary (remainder 1)', () => { |
| 47 | + // 2025-12-04 = 29 complete quarters from 2018-09-03, remainder 1 |
| 48 | + expect(computeYearsExperience(new Date('2025-12-04'))).toBe('just over 7') |
| 49 | + }) |
| 50 | + |
| 51 | + it('returns "N and a half" when 2 quarters past an anniversary (remainder 2)', () => { |
| 52 | + // 2026-03-04 = 30 complete quarters from 2018-09-03, remainder 2 |
| 53 | + expect(computeYearsExperience(new Date('2026-03-04'))).toBe('7 and a half') |
| 54 | + }) |
| 55 | + |
| 56 | + it('returns "nearly N+1" when 3 quarters past an anniversary (remainder 3)', () => { |
| 57 | + // 2026-06-04 = 31 complete quarters from 2018-09-03, remainder 3 |
| 58 | + expect(computeYearsExperience(new Date('2026-06-04'))).toBe('nearly 8') |
| 59 | + }) |
| 60 | + |
| 61 | + it('handles earlier career milestones correctly', () => { |
| 62 | + // 2020-09-03 = exactly 8 quarters (2 years) |
| 63 | + expect(computeYearsExperience(new Date('2020-09-03'))).toBe('2') |
| 64 | + }) |
| 65 | + }) |
| 66 | + |
| 67 | + describe('NO_OF_YEARS_EXPERIENCE', () => { |
| 68 | + it('should be a non-empty string', () => { |
| 69 | + expect(typeof variables.NO_OF_YEARS_EXPERIENCE).toBe('string') |
| 70 | + expect(variables.NO_OF_YEARS_EXPERIENCE.length).toBeGreaterThan(0) |
| 71 | + }) |
| 72 | + |
| 73 | + it('should match computeYearsExperience() called at the same moment', () => { |
| 74 | + // Both are evaluated at import time so they should be identical |
| 75 | + expect(variables.NO_OF_YEARS_EXPERIENCE).toBe(computeYearsExperience()) |
| 76 | + }) |
| 77 | + }) |
| 78 | +}) |
0 commit comments