[ACS-6366] Add missing unit tests for app rules (#3831)

* [ACS-6366] Aca-shared rules cleanup

* [ACS-6366] Add missing unit tests for app rules

* [ACS-6366] Move context creation to beforeEach
This commit is contained in:
MichalKinas
2024-05-08 08:53:30 +02:00
committed by GitHub
parent 12742b3b90
commit 0f3f580e24
5 changed files with 1044 additions and 606 deletions

View File

@@ -377,7 +377,7 @@
"type": "separator", "type": "separator",
"order": 89, "order": 89,
"rules": { "rules": {
"visible": "app.isSearchSupported" "visible": "app.navigation.isNotSearchResults"
} }
}, },
{ {
@@ -393,7 +393,7 @@
"click": "SEARCH" "click": "SEARCH"
}, },
"rules": { "rules": {
"visible": "app.isSearchSupported" "visible": "app.navigation.isNotSearchResults"
} }
}, },
{ {
@@ -1252,7 +1252,7 @@
"click": "ASPECT_LIST" "click": "ASPECT_LIST"
}, },
"rules": { "rules": {
"visible": "editAspects" "visible": "canEditAspects"
} }
}, },
{ {

View File

@@ -171,7 +171,6 @@ export class ContentServiceExtensionModule {
canToggleFavorite: rules.canToggleFavorite, canToggleFavorite: rules.canToggleFavorite,
isLibraryManager: rules.isLibraryManager, isLibraryManager: rules.isLibraryManager,
canEditAspects: rules.canEditAspects, canEditAspects: rules.canEditAspects,
editAspects: rules.editAspects,
canShowExpand: rules.canShowExpand, canShowExpand: rules.canShowExpand,
canInfoPreview: rules.canInfoPreview, canInfoPreview: rules.canInfoPreview,
showInfoSelectionButton: rules.showInfoSelectionButton, showInfoSelectionButton: rules.showInfoSelectionButton,
@@ -225,7 +224,6 @@ export class ContentServiceExtensionModule {
'app.isContentServiceEnabled': rules.isContentServiceEnabled, 'app.isContentServiceEnabled': rules.isContentServiceEnabled,
'app.isUploadSupported': rules.isUploadSupported, 'app.isUploadSupported': rules.isUploadSupported,
'app.canCreateLibrary': rules.canCreateLibrary, 'app.canCreateLibrary': rules.canCreateLibrary,
'app.isSearchSupported': rules.isSearchSupported,
'app.areTagsEnabled': rules.areTagsEnabled, 'app.areTagsEnabled': rules.areTagsEnabled,
'app.areCategoriesEnabled': rules.areCategoriesEnabled 'app.areCategoriesEnabled': rules.areCategoriesEnabled
}); });

File diff suppressed because it is too large Load Diff

View File

@@ -93,13 +93,6 @@ export const isContentServiceEnabled = (context: AcaRuleContext): boolean => {
return flag === true || flag === 'true'; return flag === true || flag === 'true';
}; };
/**
* Checks if Search is supported for active view
* JSON ref: `app.isSearchSupported`
*/
export const isSearchSupported = (context: RuleContext): boolean =>
[navigation.isNotSearchResults(context) /* , !hasSelection(context)*/].every(Boolean);
/** /**
* Checks if upload action is supported for the given context * Checks if upload action is supported for the given context
* JSON ref: `app.isUploadSupported` * JSON ref: `app.isUploadSupported`
@@ -122,7 +115,7 @@ export const canCopyNode = (context: RuleContext): boolean =>
* JSON ref: `app.selection.canAddFavorite` * JSON ref: `app.selection.canAddFavorite`
*/ */
export function canAddFavorite(context: RuleContext): boolean { export function canAddFavorite(context: RuleContext): boolean {
if (!context.selection.isEmpty) { if (hasSelection(context)) {
if (navigation.isFavorites(context) || navigation.isLibraries(context) || navigation.isTrashcan(context)) { if (navigation.isFavorites(context) || navigation.isLibraries(context) || navigation.isTrashcan(context)) {
return false; return false;
} }
@@ -136,7 +129,7 @@ export function canAddFavorite(context: RuleContext): boolean {
* JSON ref: `app.selection.canRemoveFavorite` * JSON ref: `app.selection.canRemoveFavorite`
*/ */
export function canRemoveFavorite(context: RuleContext): boolean { export function canRemoveFavorite(context: RuleContext): boolean {
if (!context.selection.isEmpty && !navigation.isTrashcan(context)) { if (hasSelection(context) && !navigation.isTrashcan(context)) {
if (navigation.isFavorites(context)) { if (navigation.isFavorites(context)) {
return true; return true;
} }
@@ -177,7 +170,7 @@ export function isShared(context: RuleContext): boolean {
return true; return true;
} }
if (navigation.isNotTrashcan(context) && !context.selection.isEmpty && context.selection.file) { if (navigation.isNotTrashcan(context) && hasSelection(context) && context.selection.file) {
return !!context.selection.file.entry?.properties?.['qshare:sharedId']; return !!context.selection.file.entry?.properties?.['qshare:sharedId'];
} }
@@ -189,12 +182,7 @@ export function isShared(context: RuleContext): boolean {
* JSON ref: `app.selection.canDelete` * JSON ref: `app.selection.canDelete`
*/ */
export function canDeleteSelection(context: RuleContext): boolean { export function canDeleteSelection(context: RuleContext): boolean {
if ( if (navigation.isNotTrashcan(context) && navigation.isNotLibraries(context) && navigation.isNotSearchResults(context) && hasSelection(context)) {
navigation.isNotTrashcan(context) &&
navigation.isNotLibraries(context) &&
navigation.isNotSearchResults(context) &&
!context.selection.isEmpty
) {
if (hasLockedFiles(context)) { if (hasLockedFiles(context)) {
return false; return false;
} }
@@ -225,7 +213,7 @@ export function canDeleteSelection(context: RuleContext): boolean {
* JSON ref: `app.selection.canUnshare` * JSON ref: `app.selection.canUnshare`
*/ */
export function canUnshareNodes(context: RuleContext): boolean { export function canUnshareNodes(context: RuleContext): boolean {
if (!context.selection.isEmpty) { if (hasSelection(context)) {
return context.permissions.check(context.selection.nodes, ['delete'], { return context.permissions.check(context.selection.nodes, ['delete'], {
target: 'allowableOperationsOnTarget' target: 'allowableOperationsOnTarget'
}); });
@@ -276,7 +264,7 @@ export function canUpload(context: AcaRuleContext): boolean {
* JSON ref: `app.selection.canDownload` * JSON ref: `app.selection.canDownload`
*/ */
export function canDownloadSelection(context: RuleContext): boolean { export function canDownloadSelection(context: RuleContext): boolean {
if (!context.selection.isEmpty && navigation.isNotTrashcan(context)) { if (hasSelection(context) && navigation.isNotTrashcan(context)) {
return context.selection.nodes.every((node: any) => node.entry && (node.entry.isFile || node.entry.isFolder || !!node.entry.nodeId)); return context.selection.nodes.every((node: any) => node.entry && (node.entry.isFile || node.entry.isFolder || !!node.entry.nodeId));
} }
return false; return false;
@@ -328,7 +316,7 @@ export const hasFileSelected = (context: RuleContext): boolean => !!context?.sel
* JSON ref: `app.selection.first.canUpdate` * JSON ref: `app.selection.first.canUpdate`
*/ */
export function canUpdateSelectedNode(context: RuleContext): boolean { export function canUpdateSelectedNode(context: RuleContext): boolean {
if (context.selection && !context.selection.isEmpty) { if (context.selection && hasSelection(context)) {
const node = context.selection.first; const node = context.selection.first;
if (node?.entry.isFile && hasLockedFiles(context)) { if (node?.entry.isFile && hasLockedFiles(context)) {
@@ -342,7 +330,7 @@ export function canUpdateSelectedNode(context: RuleContext): boolean {
export function isMultiselection(context: RuleContext): boolean { export function isMultiselection(context: RuleContext): boolean {
let isMultiNodeSelected = false; let isMultiNodeSelected = false;
if (context.selection && !context.selection.isEmpty) { if (context.selection && hasSelection(context)) {
isMultiNodeSelected = context.selection.count > 1; isMultiNodeSelected = context.selection.count > 1;
} }
return isMultiNodeSelected; return isMultiNodeSelected;
@@ -498,14 +486,6 @@ export const canEditAspects = (context: RuleContext): boolean =>
repository.isMajorVersionAvailable(context, '7') repository.isMajorVersionAvailable(context, '7')
].every(Boolean); ].every(Boolean);
export const editAspects = (context: RuleContext): boolean =>
[
canUpdateSelectedNode(context),
!isWriteLocked(context),
navigation.isNotTrashcan(context),
repository.isMajorVersionAvailable(context, '7')
].every(Boolean);
export const canShowExpand = (context: RuleContext): boolean => [!navigation.isLibraries(context), !navigation.isDetails(context)].every(Boolean); export const canShowExpand = (context: RuleContext): boolean => [!navigation.isLibraries(context), !navigation.isDetails(context)].every(Boolean);
/** /**

View File

@@ -22,15 +22,19 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>. * from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { NavigationState, NodePermissions, ProfileState, RuleContext, RuleEvaluator, SelectionState } from '@alfresco/adf-extensions'; import { NavigationState, NodePermissions, ProfileState, RuleEvaluator, SelectionState } from '@alfresco/adf-extensions';
import { RepositoryInfo } from '@alfresco/js-api'; import { RepositoryInfo } from '@alfresco/js-api';
import { AcaRuleContext } from './app.rules';
import { AppConfigService } from '@alfresco/adf-core';
export class TestRuleContext implements RuleContext { export class TestRuleContext implements AcaRuleContext {
auth: any; auth: any;
navigation: NavigationState = {}; navigation: NavigationState = {};
permissions: NodePermissions; permissions: NodePermissions;
profile: ProfileState; profile: ProfileState;
repository: RepositoryInfo; repository: RepositoryInfo;
withCredentials: boolean;
appConfig: AppConfigService;
selection: SelectionState = { selection: SelectionState = {
count: 0, count: 0,