[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",
"order": 89,
"rules": {
"visible": "app.isSearchSupported"
"visible": "app.navigation.isNotSearchResults"
}
},
{
@@ -393,7 +393,7 @@
"click": "SEARCH"
},
"rules": {
"visible": "app.isSearchSupported"
"visible": "app.navigation.isNotSearchResults"
}
},
{
@@ -1252,7 +1252,7 @@
"click": "ASPECT_LIST"
},
"rules": {
"visible": "editAspects"
"visible": "canEditAspects"
}
},
{

View File

@@ -171,7 +171,6 @@ export class ContentServiceExtensionModule {
canToggleFavorite: rules.canToggleFavorite,
isLibraryManager: rules.isLibraryManager,
canEditAspects: rules.canEditAspects,
editAspects: rules.editAspects,
canShowExpand: rules.canShowExpand,
canInfoPreview: rules.canInfoPreview,
showInfoSelectionButton: rules.showInfoSelectionButton,
@@ -225,7 +224,6 @@ export class ContentServiceExtensionModule {
'app.isContentServiceEnabled': rules.isContentServiceEnabled,
'app.isUploadSupported': rules.isUploadSupported,
'app.canCreateLibrary': rules.canCreateLibrary,
'app.isSearchSupported': rules.isSearchSupported,
'app.areTagsEnabled': rules.areTagsEnabled,
'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';
};
/**
* 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
* JSON ref: `app.isUploadSupported`
@@ -122,7 +115,7 @@ export const canCopyNode = (context: RuleContext): boolean =>
* JSON ref: `app.selection.canAddFavorite`
*/
export function canAddFavorite(context: RuleContext): boolean {
if (!context.selection.isEmpty) {
if (hasSelection(context)) {
if (navigation.isFavorites(context) || navigation.isLibraries(context) || navigation.isTrashcan(context)) {
return false;
}
@@ -136,7 +129,7 @@ export function canAddFavorite(context: RuleContext): boolean {
* JSON ref: `app.selection.canRemoveFavorite`
*/
export function canRemoveFavorite(context: RuleContext): boolean {
if (!context.selection.isEmpty && !navigation.isTrashcan(context)) {
if (hasSelection(context) && !navigation.isTrashcan(context)) {
if (navigation.isFavorites(context)) {
return true;
}
@@ -177,7 +170,7 @@ export function isShared(context: RuleContext): boolean {
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'];
}
@@ -189,12 +182,7 @@ export function isShared(context: RuleContext): boolean {
* JSON ref: `app.selection.canDelete`
*/
export function canDeleteSelection(context: RuleContext): boolean {
if (
navigation.isNotTrashcan(context) &&
navigation.isNotLibraries(context) &&
navigation.isNotSearchResults(context) &&
!context.selection.isEmpty
) {
if (navigation.isNotTrashcan(context) && navigation.isNotLibraries(context) && navigation.isNotSearchResults(context) && hasSelection(context)) {
if (hasLockedFiles(context)) {
return false;
}
@@ -225,7 +213,7 @@ export function canDeleteSelection(context: RuleContext): boolean {
* JSON ref: `app.selection.canUnshare`
*/
export function canUnshareNodes(context: RuleContext): boolean {
if (!context.selection.isEmpty) {
if (hasSelection(context)) {
return context.permissions.check(context.selection.nodes, ['delete'], {
target: 'allowableOperationsOnTarget'
});
@@ -276,7 +264,7 @@ export function canUpload(context: AcaRuleContext): boolean {
* JSON ref: `app.selection.canDownload`
*/
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 false;
@@ -328,7 +316,7 @@ export const hasFileSelected = (context: RuleContext): boolean => !!context?.sel
* JSON ref: `app.selection.first.canUpdate`
*/
export function canUpdateSelectedNode(context: RuleContext): boolean {
if (context.selection && !context.selection.isEmpty) {
if (context.selection && hasSelection(context)) {
const node = context.selection.first;
if (node?.entry.isFile && hasLockedFiles(context)) {
@@ -342,7 +330,7 @@ export function canUpdateSelectedNode(context: RuleContext): boolean {
export function isMultiselection(context: RuleContext): boolean {
let isMultiNodeSelected = false;
if (context.selection && !context.selection.isEmpty) {
if (context.selection && hasSelection(context)) {
isMultiNodeSelected = context.selection.count > 1;
}
return isMultiNodeSelected;
@@ -498,14 +486,6 @@ export const canEditAspects = (context: RuleContext): boolean =>
repository.isMajorVersionAvailable(context, '7')
].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);
/**

View File

@@ -22,15 +22,19 @@
* 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 { AcaRuleContext } from './app.rules';
import { AppConfigService } from '@alfresco/adf-core';
export class TestRuleContext implements RuleContext {
export class TestRuleContext implements AcaRuleContext {
auth: any;
navigation: NavigationState = {};
permissions: NodePermissions;
profile: ProfileState;
repository: RepositoryInfo;
withCredentials: boolean;
appConfig: AppConfigService;
selection: SelectionState = {
count: 0,