Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: v2 qa for semantic date range version limitation #2561

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions .changeset/shiny-radios-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@sap-ux-private/preview-middleware-client": patch
'@sap-ux/preview-middleware': patch
---

fix: restrict the '"Semantic Date Range" in filter bar' quick-action for certain UI5 versions which are not supported for V2 application.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { QuickActionContext, SimpleQuickActionDefinition } from '../../../cpe/qu
import { pageHasControlId } from '../../../cpe/quick-actions/utils';
import { getControlById } from '../../../utils/core';
import { SimpleQuickActionDefinitionBase } from '../simple-quick-action-base';
import { getUi5Version, isEqualToUi5Version, isLowerThanMinimalUi5Version } from '../../../utils/version';

export const ENABLE_SEMANTIC_DATE_RANGE_FILTER_BAR = 'enable-semantic-daterange-filterbar';
const CONTROL_TYPE = 'sap.ui.comp.smartfilterbar.SmartFilterBar';
Expand All @@ -25,7 +26,19 @@ export class ToggleSemanticDateRangeFilterBar
readonly forceRefreshAfterExecution = true;
private isUseDateRangeTypeEnabled = false;

initialize(): void {
async initialize(): Promise<void> {
const version = await getUi5Version();
const isUI5VersionNotSupported =
isLowerThanMinimalUi5Version(version, { major: 1, minor: 128 }) &&
!(
isEqualToUi5Version(version, { major: 1, minor: 96 }) ||
isEqualToUi5Version(version, { major: 1, minor: 108 }) ||
isEqualToUi5Version(version, { major: 1, minor: 120 })
);

if (isUI5VersionNotSupported) {
return;
}
if (FeatureService.isFeatureEnabled('cpe.beta.quick-actions') === false) {
return;
}
Expand Down
20 changes: 20 additions & 0 deletions packages/preview-middleware-client/src/utils/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ export function isLowerThanMinimalUi5Version(
return false;
}

/**
* Checks if the given version is equal to the specified version.
* @param ui5VersionInfo to check
* @param targetUi5VersionInfo to check against (default is 1.71)
*
* @returns boolean
*/
export function isEqualToUi5Version(
ui5VersionInfo: Ui5VersionInfo,
targetUi5VersionInfo: Ui5VersionInfo = minVersionInfo
): boolean {
if (!isNaN(ui5VersionInfo.major) && !isNaN(ui5VersionInfo.minor)) {
return (
ui5VersionInfo.major === targetUi5VersionInfo.major &&
ui5VersionInfo.minor === targetUi5VersionInfo.minor
);
}
return false;
}

/**
* Get UI5 version validation message.
* @param ui5VersionInfo to be mentioned in the message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import RuntimeAuthoring, { RTAOptions } from 'sap/ui/rta/RuntimeAuthoring';
import RuntimeAuthoringMock from 'mock/sap/ui/rta/RuntimeAuthoring';

import { quickActionListChanged, executeQuickAction } from '@sap-ux-private/control-property-editor-common';
import * as VersionUtils from '../../../../src/utils/version';

jest.mock('../../../../src/adp/init-dialogs', () => {
return {
Expand Down Expand Up @@ -38,6 +39,7 @@ import {
import { DialogNames } from 'open/ux/preview/client/adp/init-dialogs';
import * as adpUtils from 'open/ux/preview/client/adp/utils';
import type { ChangeService } from '../../../../src/cpe/changes/service';
import { Ui5VersionInfo } from '../../../../src/utils/version';

describe('FE V2 quick actions', () => {
let sendActionMock: jest.Mock;
Expand Down Expand Up @@ -842,8 +844,17 @@ describe('FE V2 quick actions', () => {
});

describe('disable/enable "semantic date range" in filter bar', () => {
afterEach(() => {
jest.restoreAllMocks(); // Restores all mocked functions to their original implementations
});
test('not available by default', async () => {
jest.spyOn(FeatureService, 'isFeatureEnabled').mockReturnValue(false);
jest.spyOn(VersionUtils, 'getUi5Version').mockReturnValue(
Promise.resolve({
major: 1,
minor: 130
} as Ui5VersionInfo)
);
sapCoreMock.byId.mockImplementation((id) => {
if (id == 'SmartFilterBar') {
return {
Expand Down Expand Up @@ -888,6 +899,86 @@ describe('FE V2 quick actions', () => {
}
});

const rtaMock = new RuntimeAuthoringMock({} as RTAOptions) as unknown as RuntimeAuthoring;
const registry = new FEV2QuickActionRegistry();
const service = new QuickActionService(rtaMock, new OutlineService(rtaMock, mockChangeService), [
registry
]);
await service.init(sendActionMock, subscribeMock);

await service.reloadQuickActions({
'sap.ui.comp.smartfilterbar.SmartFilterBar': [
{
controlId: 'SmartFilterBar'
} as any
],
'sap.m.NavContainer': [
{
controlId: 'NavContainer'
} as any
]
});

expect(sendActionMock).toHaveBeenCalledWith(
quickActionListChanged([
{
title: 'LIST REPORT',
actions: []
}
])
);
});
test('not supported ui5 version', async () => {
jest.spyOn(FeatureService, 'isFeatureEnabled').mockReturnValue(true);
jest.spyOn(VersionUtils, 'getUi5Version').mockReturnValue(
Promise.resolve({
major: 1,
minor: 80
} as Ui5VersionInfo)
);
sapCoreMock.byId.mockImplementation((id) => {
if (id == 'SmartFilterBar') {
return {
getProperty: jest.fn().mockImplementation(() => false),
getDomRef: () => ({}),
getEntitySet: jest.fn().mockImplementation(() => 'testEntity')
};
}
if (id == 'NavContainer') {
const container = new NavContainer();
const component = new UIComponentMock();
const view = new XMLView();
const pageView = new XMLView();
pageView.getDomRef.mockImplementation(() => {
return {
contains: () => true
};
});
pageView.getViewName.mockImplementation(
() => 'sap.suite.ui.generic.template.ListReport.view.ListReport'
);
const componentContainer = new ComponentContainer();
const spy = jest.spyOn(componentContainer, 'getComponent');
spy.mockImplementation(() => {
return 'component-id';
});
jest.spyOn(Component, 'getComponentById').mockImplementation((id: string | undefined) => {
if (id === 'component-id') {
return component;
}
});
view.getContent.mockImplementation(() => {
return [componentContainer];
});
container.getCurrentPage.mockImplementation(() => {
return view;
});
component.getRootControl.mockImplementation(() => {
return pageView;
});
return container;
}
});

const rtaMock = new RuntimeAuthoringMock({} as RTAOptions) as unknown as RuntimeAuthoring;
const registry = new FEV2QuickActionRegistry();
Expand Down Expand Up @@ -919,6 +1010,12 @@ describe('FE V2 quick actions', () => {
);
});
test('initialize and execute action', async () => {
jest.spyOn(VersionUtils, 'getUi5Version').mockReturnValue(
Promise.resolve({
major: 1,
minor: 96
} as Ui5VersionInfo)
);
sapCoreMock.byId.mockImplementation((id) => {
if (id == 'SmartFilterBar') {
return {
Expand Down
Loading