|
| 1 | +/** |
| 2 | + * @jest-environment jsdom |
| 3 | + */ |
| 4 | +import { |
| 5 | + beforeEach, describe, expect, it, |
| 6 | +} from '@jest/globals'; |
| 7 | + |
| 8 | +import { renderTrialPanel } from './trial_panel.client'; |
| 9 | + |
| 10 | +describe('trial panel client', () => { |
| 11 | + beforeEach(() => { |
| 12 | + document.body.innerHTML = ''; |
| 13 | + }); |
| 14 | + |
| 15 | + it('should not display subscription text when subscriptions parameter is empty string', () => { |
| 16 | + renderTrialPanel( |
| 17 | + 'https://example.com/buy', |
| 18 | + 'https://example.com/docs', |
| 19 | + '25.2.0', |
| 20 | + '', |
| 21 | + ); |
| 22 | + |
| 23 | + const triggerElement = document.querySelector('dx-license-trigger'); |
| 24 | + expect(triggerElement).not.toBeNull(); |
| 25 | + |
| 26 | + const panelElement = document.querySelector('dx-license'); |
| 27 | + if (panelElement) { |
| 28 | + const text = panelElement.textContent ?? ''; |
| 29 | + expect(text).not.toContain('Included in Subscriptions:'); |
| 30 | + } |
| 31 | + }); |
| 32 | + |
| 33 | + it('should set subscriptions attribute when parameter is a valid string', () => { |
| 34 | + renderTrialPanel( |
| 35 | + 'https://example.com/buy', |
| 36 | + 'https://example.com/docs', |
| 37 | + '25.2.0', |
| 38 | + 'Universal, DXperience', |
| 39 | + ); |
| 40 | + |
| 41 | + const triggerElement = document.querySelector('dx-license-trigger'); |
| 42 | + expect(triggerElement).not.toBeNull(); |
| 43 | + |
| 44 | + const subscriptionsAttr = triggerElement?.getAttribute('subscriptions'); |
| 45 | + expect(subscriptionsAttr).toBe('Universal, DXperience'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should not display subscription text when subscriptions parameter is actual null', () => { |
| 49 | + renderTrialPanel( |
| 50 | + 'https://example.com/buy', |
| 51 | + 'https://example.com/docs', |
| 52 | + '25.2.0', |
| 53 | + null as any, // Actual null value |
| 54 | + ); |
| 55 | + |
| 56 | + const triggerElement = document.querySelector('dx-license-trigger'); |
| 57 | + expect(triggerElement).not.toBeNull(); |
| 58 | + |
| 59 | + // When null is passed, it gets converted to string "null" as HTML attribute |
| 60 | + const subscriptionsAttr = triggerElement?.getAttribute('subscriptions'); |
| 61 | + expect(subscriptionsAttr).toBe(''); |
| 62 | + |
| 63 | + // Ensure the panel element doesn't show "Included in Subscriptions: null" |
| 64 | + // This is the key test - our fix should prevent displaying "null" |
| 65 | + const panelElement = document.querySelector('dx-license'); |
| 66 | + if (panelElement) { |
| 67 | + const text = panelElement.textContent ?? ''; |
| 68 | + expect(text).not.toContain('Included in Subscriptions: null'); |
| 69 | + } |
| 70 | + }); |
| 71 | +}); |
0 commit comments