From 9c0821ed3b9c001f27de9877592778b1afdbd01b Mon Sep 17 00:00:00 2001 From: Arcadio Quintero Date: Mon, 18 Nov 2024 21:16:02 -0500 Subject: [PATCH] feat(edit-content) clean up, add more test --- .../store/edit-content.store.spec.ts | 11 ++++++--- .../store/features/content.feature.spec.ts | 23 +++++++++++-------- .../store/features/content.feature.ts | 5 ++-- .../store/features/debug.feature.ts | 2 +- .../store/features/information.feature.ts | 2 +- .../store/features/sidebar.feature.ts | 3 ++- .../store/features/workflow.feature.ts | 5 ++-- .../src/lib/utils/functions.util.ts | 3 ++- 8 files changed, 33 insertions(+), 21 deletions(-) diff --git a/core-web/libs/edit-content/src/lib/feature/edit-content/store/edit-content.store.spec.ts b/core-web/libs/edit-content/src/lib/feature/edit-content/store/edit-content.store.spec.ts index 2dd47ffd99a9..f570a57da514 100644 --- a/core-web/libs/edit-content/src/lib/feature/edit-content/store/edit-content.store.spec.ts +++ b/core-web/libs/edit-content/src/lib/feature/edit-content/store/edit-content.store.spec.ts @@ -1,4 +1,9 @@ +import { createServiceFactory, mockProvider, SpectatorService } from '@ngneat/spectator/jest'; + import { ActivatedRoute } from '@angular/router'; + +import { MessageService } from 'primeng/api'; + import { DotContentTypeService, DotHttpErrorManagerService, @@ -8,11 +13,11 @@ import { DotWorkflowService } from '@dotcms/data-access'; import { ComponentStatus } from '@dotcms/dotcms-models'; -import { createServiceFactory, mockProvider, SpectatorService } from '@ngneat/spectator/jest'; -import { MessageService } from 'primeng/api'; -import { DotEditContentService } from '../../../services/dot-edit-content.service'; + import { DotEditContentStore } from './edit-content.store'; +import { DotEditContentService } from '../../../services/dot-edit-content.service'; + describe('DotEditContentStore', () => { let spectator: SpectatorService>; let store: InstanceType; diff --git a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/content.feature.spec.ts b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/content.feature.spec.ts index 1efcf8c0238f..bed43c6c3b1c 100644 --- a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/content.feature.spec.ts +++ b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/content.feature.spec.ts @@ -1,31 +1,35 @@ -import { Router } from '@angular/router'; +/* eslint-disable @typescript-eslint/no-explicit-any */ + import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { signalStore, withState } from '@ngrx/signals'; +import { of, throwError } from 'rxjs'; + +import { HttpErrorResponse } from '@angular/common/http'; +import { fakeAsync, tick } from '@angular/core/testing'; +import { Router } from '@angular/router'; import { DotContentTypeService, DotHttpErrorManagerService, DotWorkflowsActionsService } from '@dotcms/data-access'; - -import { of, throwError } from 'rxjs'; - -import { HttpErrorResponse } from '@angular/common/http'; -import { fakeAsync, tick } from '@angular/core/testing'; import { ComponentStatus, DotCMSContentlet, DotCMSWorkflowAction } from '@dotcms/dotcms-models'; import { MOCK_SINGLE_WORKFLOW_ACTIONS } from '@dotcms/utils-testing'; + +import { withContent } from './content.feature'; +import { workflowInitialState } from './workflow.feature'; + import { DotEditContentService } from '../../../../services/dot-edit-content.service'; import { parseWorkflows } from '../../../../utils/functions.util'; import { CONTENT_TYPE_MOCK } from '../../../../utils/mocks'; import { initialState } from '../edit-content.store'; -import { withContent } from './content.feature'; -import { workflowInitialState } from './workflow.feature'; describe('ContentFeature', () => { + // let spectator: SpectatorService>; let spectator: SpectatorService; + let store: any; let contentTypeService: SpyObject; - let dotHttpErrorManagerService: SpyObject; let dotEditContentService: SpyObject; let workflowActionService: SpyObject; let router: SpyObject; @@ -48,7 +52,6 @@ describe('ContentFeature', () => { spectator = createStore(); store = spectator.service; contentTypeService = spectator.inject(DotContentTypeService); - dotHttpErrorManagerService = spectator.inject(DotHttpErrorManagerService); dotEditContentService = spectator.inject(DotEditContentService); workflowActionService = spectator.inject(DotWorkflowsActionsService); router = spectator.inject(Router); diff --git a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/content.feature.ts b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/content.feature.ts index 599343cd5ea7..4c14a885bcd3 100644 --- a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/content.feature.ts +++ b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/content.feature.ts @@ -29,10 +29,11 @@ import { FeaturedFlags } from '@dotcms/dotcms-models'; +import { WorkflowState } from './workflow.feature'; + import { DotEditContentService } from '../../../../services/dot-edit-content.service'; import { parseWorkflows, transformFormDataFn } from '../../../../utils/functions.util'; import { EditContentRootState } from '../edit-content.store'; -import { WorkflowState } from './workflow.feature'; export interface ContentState { /** ContentType full data */ @@ -46,7 +47,7 @@ const initialState: ContentState = { contentlet: null }; -export function withContent() { +export function withContent() { return signalStoreFeature( { state: type() }, withState(initialState), diff --git a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/debug.feature.ts b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/debug.feature.ts index 26d42fe664f3..95f0f407d58a 100644 --- a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/debug.feature.ts +++ b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/debug.feature.ts @@ -9,7 +9,7 @@ export function withDebug() { withHooks({ onInit(store) { watchState(store, (state) => { - console.info('🔄 Store state:', state); + console.warn('🔄 Store state:', state); }); } }) diff --git a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/information.feature.ts b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/information.feature.ts index 4bcd67550f00..b30009c13200 100644 --- a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/information.feature.ts +++ b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/information.feature.ts @@ -39,7 +39,7 @@ const initialState: InformationState = { * Signal store feature that manages the information component state in the edit content sidebar * Handles loading states, error handling, and related content count for the current contentlet */ -export function withInformation() { +export function withInformation() { return signalStoreFeature( withState(initialState), withComputed(({ information }) => ({ diff --git a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/sidebar.feature.ts b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/sidebar.feature.ts index 8c9b83f3d31e..a04dce9a2679 100644 --- a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/sidebar.feature.ts +++ b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/sidebar.feature.ts @@ -10,9 +10,10 @@ import { import { computed } from '@angular/core'; -import { getPersistSidebarState, setPersistSidebarState } from '../../../../utils/functions.util'; import { ContentState } from './content.feature'; +import { getPersistSidebarState, setPersistSidebarState } from '../../../../utils/functions.util'; + export interface SidebarState { showSidebar: boolean; } diff --git a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/workflow.feature.ts b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/workflow.feature.ts index 48316d50b977..315f855593f7 100644 --- a/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/workflow.feature.ts +++ b/core-web/libs/edit-content/src/lib/feature/edit-content/store/features/workflow.feature.ts @@ -35,13 +35,14 @@ import { WorkflowTask } from '@dotcms/dotcms-models'; +import { ContentState } from './content.feature'; + import { getWorkflowActions, shouldShowWorkflowActions, shouldShowWorkflowWarning } from '../../../../utils/functions.util'; import { EditContentRootState } from '../edit-content.store'; -import { ContentState } from './content.feature'; export interface WorkflowState { /** Schemas available for the content type */ @@ -90,7 +91,7 @@ export const workflowInitialState: WorkflowState = { * * @returns */ -export function withWorkflow() { +export function withWorkflow() { return signalStoreFeature( { state: type() }, withState(workflowInitialState), diff --git a/core-web/libs/edit-content/src/lib/utils/functions.util.ts b/core-web/libs/edit-content/src/lib/utils/functions.util.ts index beeae7ffb8fa..a27136960e23 100644 --- a/core-web/libs/edit-content/src/lib/utils/functions.util.ts +++ b/core-web/libs/edit-content/src/lib/utils/functions.util.ts @@ -347,7 +347,7 @@ export const parseWorkflows = ( */ export function shouldShowWorkflowActions( schemes: WorkflowState['schemes'], - contentlet: any | null, + contentlet: ContentState['contentlet'], currentSchemeId: string | null ): boolean { const hasOneScheme = Object.keys(schemes).length === 1; @@ -428,6 +428,7 @@ export function getWorkflowActions( return Object.values(schemes[currentSchemeId].actions).sort((a, b) => { if (a.name === 'Save') return -1; if (b.name === 'Save') return 1; + return a.name.localeCompare(b.name); }); }