|
| 1 | +import { |
| 2 | + flagsmithColors, |
| 3 | + FLAGSMITH_DASHBOARD_URL, |
| 4 | + buildFlagUrl, |
| 5 | + buildProjectUrl, |
| 6 | +} from './flagsmithTheme'; |
| 7 | + |
| 8 | +describe('flagsmithTheme', () => { |
| 9 | + describe('flagsmithColors', () => { |
| 10 | + it('exports primary color', () => { |
| 11 | + expect(flagsmithColors.primary).toBe('#0AC2A3'); |
| 12 | + }); |
| 13 | + |
| 14 | + it('exports secondary color', () => { |
| 15 | + expect(flagsmithColors.secondary).toBe('#7B51FB'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('exports status colors', () => { |
| 19 | + expect(flagsmithColors.enabled).toBe('#4CAF50'); |
| 20 | + expect(flagsmithColors.disabled).toBe('#9E9E9E'); |
| 21 | + expect(flagsmithColors.warning).toBe('#FF9800'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('exports background colors', () => { |
| 25 | + expect(flagsmithColors.background.enabled).toBeDefined(); |
| 26 | + expect(flagsmithColors.background.disabled).toBeDefined(); |
| 27 | + expect(flagsmithColors.background.warning).toBeDefined(); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('FLAGSMITH_DASHBOARD_URL', () => { |
| 32 | + it('is set to the Flagsmith app URL', () => { |
| 33 | + expect(FLAGSMITH_DASHBOARD_URL).toBe('https://app.flagsmith.com'); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('buildFlagUrl', () => { |
| 38 | + it('builds URL with all parameters', () => { |
| 39 | + const url = buildFlagUrl('123', '456', '789'); |
| 40 | + |
| 41 | + expect(url).toBe( |
| 42 | + 'https://app.flagsmith.com/project/123/environment/456/features?feature=789', |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + it('builds URL without feature ID', () => { |
| 47 | + const url = buildFlagUrl('123', '456'); |
| 48 | + |
| 49 | + expect(url).toBe( |
| 50 | + 'https://app.flagsmith.com/project/123/environment/456/features', |
| 51 | + ); |
| 52 | + }); |
| 53 | + |
| 54 | + it('handles numeric parameters', () => { |
| 55 | + const url = buildFlagUrl(123, 456, 789); |
| 56 | + |
| 57 | + expect(url).toBe( |
| 58 | + 'https://app.flagsmith.com/project/123/environment/456/features?feature=789', |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | + it('handles mixed string and number parameters', () => { |
| 63 | + const url = buildFlagUrl('123', 456, '789'); |
| 64 | + |
| 65 | + expect(url).toBe( |
| 66 | + 'https://app.flagsmith.com/project/123/environment/456/features?feature=789', |
| 67 | + ); |
| 68 | + }); |
| 69 | + |
| 70 | + it('handles undefined feature ID', () => { |
| 71 | + const url = buildFlagUrl('123', '456', undefined); |
| 72 | + |
| 73 | + expect(url).toBe( |
| 74 | + 'https://app.flagsmith.com/project/123/environment/456/features', |
| 75 | + ); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + describe('buildProjectUrl', () => { |
| 80 | + it('builds URL with project and environment ID', () => { |
| 81 | + const url = buildProjectUrl('123', '456'); |
| 82 | + |
| 83 | + expect(url).toBe( |
| 84 | + 'https://app.flagsmith.com/project/123/environment/456/features', |
| 85 | + ); |
| 86 | + }); |
| 87 | + |
| 88 | + it('builds URL with only project ID', () => { |
| 89 | + const url = buildProjectUrl('123'); |
| 90 | + |
| 91 | + expect(url).toBe('https://app.flagsmith.com/project/123'); |
| 92 | + }); |
| 93 | + |
| 94 | + it('handles numeric project ID', () => { |
| 95 | + const url = buildProjectUrl(123, 456); |
| 96 | + |
| 97 | + expect(url).toBe( |
| 98 | + 'https://app.flagsmith.com/project/123/environment/456/features', |
| 99 | + ); |
| 100 | + }); |
| 101 | + |
| 102 | + it('handles undefined environment ID', () => { |
| 103 | + const url = buildProjectUrl('123', undefined); |
| 104 | + |
| 105 | + expect(url).toBe('https://app.flagsmith.com/project/123'); |
| 106 | + }); |
| 107 | + |
| 108 | + it('handles empty string environment ID as falsy', () => { |
| 109 | + // Empty string is falsy, so should return project-only URL |
| 110 | + const url = buildProjectUrl('123', ''); |
| 111 | + |
| 112 | + expect(url).toBe('https://app.flagsmith.com/project/123'); |
| 113 | + }); |
| 114 | + |
| 115 | + it('handles 0 as valid environment ID', () => { |
| 116 | + // 0 is falsy but could be a valid ID |
| 117 | + const url = buildProjectUrl('123', 0); |
| 118 | + |
| 119 | + // Current implementation treats 0 as falsy |
| 120 | + expect(url).toBe('https://app.flagsmith.com/project/123'); |
| 121 | + }); |
| 122 | + }); |
| 123 | +}); |
0 commit comments