Skip to content

Commit d7992c5

Browse files
Licensing: Fix the trial panel text when null string is passed (πŸ’ #31551 ) (#31617)
Co-authored-by: Vasily Strelyaev <[email protected]>
1 parent 32664aa commit d7992c5

File tree

3 files changed

+79
-7
lines changed

3 files changed

+79
-7
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
});

β€Žpackages/devextreme/js/__internal/core/license/trial_panel.client.tsβ€Ž

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,11 @@ class DxLicenseTrigger extends SafeHTMLElement {
304304
const license = document.createElement(componentNames.panel);
305305

306306
Object.values(attributeNames).forEach((attrName) => {
307-
license.setAttribute(
308-
attrName,
309-
this.getAttribute(attrName) as string,
310-
);
307+
const attrValue = this.getAttribute(attrName);
308+
309+
if (attrValue) {
310+
license.setAttribute(attrName, attrValue);
311+
}
311312
});
312313

313314
license.setAttribute(DATA_PERMANENT_ATTRIBUTE, '');
@@ -338,7 +339,7 @@ export function renderTrialPanel(
338339
buyNowUrl: string,
339340
licensingDocUrl: string,
340341
version: string,
341-
subscriptions = '',
342+
subscriptions: string | undefined | null,
342343
customStyles?: CustomTrialPanelStyles,
343344
): void {
344345
registerCustomComponents(customStyles);
@@ -348,7 +349,7 @@ export function renderTrialPanel(
348349
trialPanelTrigger.setAttribute(attributeNames.buyNow, buyNowUrl);
349350
trialPanelTrigger.setAttribute(attributeNames.licensingDoc, licensingDocUrl);
350351
trialPanelTrigger.setAttribute(attributeNames.version, version);
351-
trialPanelTrigger.setAttribute(attributeNames.subscriptions, subscriptions);
352+
trialPanelTrigger.setAttribute(attributeNames.subscriptions, subscriptions ?? '');
352353

353354
document.body.appendChild(trialPanelTrigger);
354355
}

β€Žpackages/devextreme/js/__internal/core/license/trial_panel.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function showTrialPanel(
99
buyNowUrl: string,
1010
licensingDocUrl: string,
1111
version: string,
12-
subscriptions?: string,
12+
subscriptions?: string | null,
1313
customStyles?: CustomTrialPanelStyles,
1414
): void {
1515
if (isClient()) {

0 commit comments

Comments
Β (0)