Skip to content

Commit

Permalink
feat(edit-content) clean up, add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
oidacra committed Nov 19, 2024
1 parent fd6dac3 commit 9c0821e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<InstanceType<typeof DotEditContentStore>>;
let store: InstanceType<typeof DotEditContentStore>;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ReturnType<EditContentRootState & WorkflowState>>;
let spectator: SpectatorService<any>;

let store: any;
let contentTypeService: SpyObject<DotContentTypeService>;
let dotHttpErrorManagerService: SpyObject<DotHttpErrorManagerService>;
let dotEditContentService: SpyObject<DotEditContentService>;
let workflowActionService: SpyObject<DotWorkflowsActionsService>;
let router: SpyObject<Router>;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -46,7 +47,7 @@ const initialState: ContentState = {
contentlet: null
};

export function withContent<ContentState>() {
export function withContent() {
return signalStoreFeature(
{ state: type<EditContentRootState & WorkflowState>() },
withState(initialState),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function withDebug() {
withHooks({
onInit(store) {
watchState(store, (state) => {
console.info('🔄 Store state:', state);
console.warn('🔄 Store state:', state);
});
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InformationState>() {
export function withInformation() {
return signalStoreFeature(
withState(initialState),
withComputed(({ information }) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -90,7 +91,7 @@ export const workflowInitialState: WorkflowState = {
*
* @returns
*/
export function withWorkflow<WorkflowState>() {
export function withWorkflow() {
return signalStoreFeature(
{ state: type<EditContentRootState & ContentState>() },
withState(workflowInitialState),
Expand Down
3 changes: 2 additions & 1 deletion core-web/libs/edit-content/src/lib/utils/functions.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}

0 comments on commit 9c0821e

Please sign in to comment.