Skip to content

Commit

Permalink
feat(edit-content) test working
Browse files Browse the repository at this point in the history
  • Loading branch information
oidacra committed Nov 18, 2024
1 parent 87bd535 commit 872cc0f
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('DotFormComponent', () => {
beforeEach(() => {
dotContentTypeService.getContentType.mockReturnValue(of(MOCK_CONTENTTYPE_1_TAB));
workflowActionsService.getDefaultActions.mockReturnValue(
of(MOCK_WORKFLOW_ACTIONS_NEW_ITEMNTTYPE_1_TAB)
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
workflowActionsService.getWorkFlowActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
Expand Down Expand Up @@ -235,29 +235,6 @@ describe('DotFormComponent', () => {
expect(toggleSidebarSpy).toHaveBeenCalled();
});

it('should call fireWorkflowAction when Save action is clicked', () => {
const fireWorkflowActionSpy = jest.spyOn(component.$store, 'fireWorkflowAction');
const workflowActions = spectator.query(DotWorkflowActionsComponent);
expect(workflowActions).toBeTruthy();

const saveButton = spectator.query('.p-splitbutton-defaultbutton');
expect(saveButton).toBeTruthy();
expect(saveButton.textContent.trim()).toBe('Save');

spectator.click(saveButton);

expect(fireWorkflowActionSpy).toHaveBeenCalledWith({
actionId: MOCK_WORKFLOW_ACTIONS_NEW_ITEMNTTYPE_1_TAB[0].id,
inode: MOCK_CONTENTLET_1_OR_2_TABS.inode,
data: {
contentlet: {
...component.form.value,
contentType: MOCK_CONTENTTYPE_1_TAB.variable
}
}
});
});

it('should call toggleSidebar when sidebar toggle button is clicked', () => {
const toggleSidebarSpy = jest.spyOn(store, 'toggleSidebar');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('DotEditContentSidebarWorkflowComponent', () => {
spectator.detectChanges();

expect(spectator.query(byTestId('workflow-name')).textContent.trim()).toBe('Blogs');
expect(spectator.query(byTestId('workflow-step')).textContent.trim()).toBe('QA');
expect(spectator.query(byTestId('workflow-step')).textContent.trim()).toBe('New');
expect(spectator.query(byTestId('workflow-assigned')).textContent.trim()).toBe(
'Admin User'
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!--Todo: handle Loading and Saving state-->
@if ($store.isLoaded() || $store.isSaving()) {
@let contentType = $store.contentType();
@let variable = contentType.variable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import {
} from '@dotcms/data-access';
import {
MOCK_MULTIPLE_WORKFLOW_ACTIONS,
MOCK_SINGLE_WORKFLOW_ACTIONS,
mockWorkflowsActions
MOCK_SINGLE_WORKFLOW_ACTIONS
} from '@dotcms/utils-testing';

import { EditContentLayoutComponent } from './edit-content.layout.component';
Expand Down Expand Up @@ -115,7 +114,9 @@ describe('EditContentLayoutComponent', () => {
describe('New Content Editor', () => {
it('should initialize new content, show layout components and dialogs when new content editor is enabled', fakeAsync(() => {
dotContentTypeService.getContentType.mockReturnValue(of(CONTENT_TYPE_MOCK));
workflowActionsService.getDefaultActions.mockReturnValue(of(mockWorkflowsActions));
workflowActionsService.getDefaultActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
workflowActionsService.getWorkFlowActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
Expand Down Expand Up @@ -144,7 +145,9 @@ describe('EditContentLayoutComponent', () => {
};

dotContentTypeService.getContentType.mockReturnValue(of(CONTENT_TYPE_MOCK_NO_METADATA));
workflowActionsService.getDefaultActions.mockReturnValue(of(mockWorkflowsActions));
workflowActionsService.getDefaultActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
workflowActionsService.getWorkFlowActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
Expand All @@ -159,13 +162,15 @@ describe('EditContentLayoutComponent', () => {
describe('Warning Messages', () => {
beforeEach(() => {
dotContentTypeService.getContentType.mockReturnValue(of(CONTENT_TYPE_MOCK));
workflowActionsService.getDefaultActions.mockReturnValue(of(mockWorkflowsActions));
workflowActionsService.getDefaultActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
dotEditContentService.getContentById.mockReturnValue(of(MOCK_CONTENTLET_1_TAB));
});

it('should show workflow warning message when multiple schemes are available for new content', fakeAsync(() => {
// Set up multiple workflow schemes
workflowActionsService.getWorkFlowActions.mockReturnValue(
// Multiple schemes trigger the warning message
workflowActionsService.getDefaultActions.mockReturnValue(
of(MOCK_MULTIPLE_WORKFLOW_ACTIONS)
);

Expand All @@ -176,6 +181,7 @@ describe('EditContentLayoutComponent', () => {
const warningMessage = spectator.query(
byTestId('edit-content-layout__select-workflow-warning')
);
expect(store.showSelectWorkflowWarning()).toBe(true);
expect(warningMessage).toBeTruthy();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ import {
DotCMSContentType,
DotCMSWorkflowAction
} from '@dotcms/dotcms-models';
import {
MOCK_SINGLE_WORKFLOW_ACTIONS,
MockDotMessageService,
mockWorkflowsActions
} from '@dotcms/utils-testing';
import { MOCK_SINGLE_WORKFLOW_ACTIONS, MockDotMessageService } from '@dotcms/utils-testing';

import { DotEditContentStore } from './edit-content.store';

Expand Down Expand Up @@ -120,7 +116,9 @@ describe('DotEditContentStore', () => {
const testContentType = 'testContentType';

contentTypeService.getContentType.mockReturnValue(of(CONTENT_TYPE_MOCK));
workflowActionsService.getDefaultActions.mockReturnValue(of(mockWorkflowsActions));
workflowActionsService.getDefaultActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
workflowActionsService.getWorkFlowActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);
Expand All @@ -130,10 +128,9 @@ describe('DotEditContentStore', () => {
// use the proper contentType for get the data
expect(contentTypeService.getContentType).toHaveBeenCalledWith(testContentType);
expect(workflowActionsService.getDefaultActions).toHaveBeenCalledWith(testContentType);
expect(workflowActionsService.getWorkFlowActions).toHaveBeenCalledWith(testContentType);

expect(store.contentType()).toEqual(CONTENT_TYPE_MOCK);
expect(store.actions()).toEqual(mockWorkflowsActions);

expect(store.state()).toBe(ComponentStatus.LOADED);
expect(store.error()).toBeNull();
});
Expand All @@ -142,7 +139,9 @@ describe('DotEditContentStore', () => {
const mockError = new HttpErrorResponse({ status: 404, statusText: 'Not Found' });

contentTypeService.getContentType.mockReturnValue(throwError(() => mockError));
workflowActionsService.getDefaultActions.mockReturnValue(of(mockWorkflowsActions));
workflowActionsService.getDefaultActions.mockReturnValue(
of(MOCK_SINGLE_WORKFLOW_ACTIONS)
);

store.initializeNewContent('testContentType');

Expand Down Expand Up @@ -187,7 +186,7 @@ describe('DotEditContentStore', () => {

expect(store.contentlet()).toEqual(mockContentlet);
expect(store.contentType()).toEqual(mockContentType);
expect(store.actions()).toEqual(mockActions);

expect(store.state()).toBe(ComponentStatus.LOADED);
expect(store.error()).toBe(null);
});
Expand Down Expand Up @@ -226,7 +225,7 @@ describe('DotEditContentStore', () => {

expect(store.state()).toBe(ComponentStatus.LOADED);
expect(store.contentlet()).toEqual(mockContentlet);
expect(store.actions()).toEqual(mockActions);

expect(store.error()).toBeNull();

expect(workflowActionsFireService.fireTo).toHaveBeenCalledWith(mockOptions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,11 @@
import { tapResponse } from '@ngrx/operators';
import {
patchState,
signalStore,
withComputed,
withHooks,
withMethods,
withState
} from '@ngrx/signals';
import { rxMethod } from '@ngrx/signals/rxjs-interop';
import { forkJoin, of, pipe } from 'rxjs';

import { HttpErrorResponse } from '@angular/common/http';
import { computed, inject } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { signalStore, withHooks, withState } from '@ngrx/signals';

import { inject } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { ComponentStatus } from '@dotcms/dotcms-models';

import {
DotContentTypeService,
DotFireActionOptions,
DotHttpErrorManagerService,
DotMessageService,
DotRenderMode,
DotWorkflowActionsFireService,
DotWorkflowsActionsService
} from '@dotcms/data-access';
import {
ComponentStatus,
DotCMSContentlet,
DotCMSContentType,
DotCMSWorkflow,
DotCMSWorkflowAction,
FeaturedFlags,
WorkflowStep,
WorkflowTask
} from '@dotcms/dotcms-models';

import { withContent } from './features/content.feature';
import { withInformation } from './features/information.feature';
import { withSidebar } from './features/sidebar.feature';
import { withWorkflow } from './features/workflow.feature';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { tapResponse } from '@ngrx/component-store';
import {
patchState,
signalStoreFeature,
Expand Down Expand Up @@ -31,6 +30,7 @@ import {

import { WorkflowState } from './workflow.feature';

import { tapResponse } from '@ngrx/operators';
import { DotEditContentService } from '../../../../services/dot-edit-content.service';
import { parseWorkflows, transformFormDataFn } from '../../../../utils/functions.util';
import { EditContentState } from '../edit-content.store';
Expand Down
22 changes: 22 additions & 0 deletions core-web/libs/edit-content/src/lib/utils/edit-content.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,17 @@ export const MOCK_WORKFLOW_DATA = [
schemeId: 'd61a59e1-a49c-46f2-a929-db2b4bfa88b2',
showOn: ['EDITING', 'UNPUBLISHED', 'NEW', 'LOCKED', 'PUBLISHED']
},
firstStep: {
creationDate: 1731595862064,
enableEscalation: false,
escalationAction: null,
escalationTime: 0,
id: '6cb7e3bd-1710-4eed-8838-d3db60f78f19',
myOrder: 0,
name: 'New',
resolved: false,
schemeId: 'd61a59e1-a49c-46f2-a929-db2b4bfa88b2'
},
scheme: {
archived: false,
creationDate: new Date(1731432900580),
Expand Down Expand Up @@ -1177,6 +1188,17 @@ export const MOCK_WORKFLOW_DATA = [
schemeId: '2a4e1d2e-5342-4b46-be3d-80d3a2d9c0dd',
showOn: ['EDITING', 'UNPUBLISHED', 'NEW', 'LOCKED', 'LISTING', 'PUBLISHED']
},
firstStep: {
creationDate: 1731595862064,
enableEscalation: false,
escalationAction: null,
escalationTime: 0,
id: '6cb7e3bd-1710-4eed-8838-d3db60f78f19',
myOrder: 0,
name: 'Edit',
resolved: false,
schemeId: '2a4e1d2e-5342-4b46-be3d-80d3a2d9c0dd'
},
scheme: {
archived: false,
creationDate: new Date(1731432900580),
Expand Down
10 changes: 4 additions & 6 deletions core-web/libs/edit-content/src/lib/utils/functions.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,15 +675,13 @@ describe('Utils Functions', () => {
it('should parse real workflow data correctly', () => {
const expected = {
[MOCK_WORKFLOW_DATA[0].scheme.id]: {
actions: {
[MOCK_WORKFLOW_DATA[0].action.id]: { ...MOCK_WORKFLOW_DATA[0].action }
},
actions: [{ ...MOCK_WORKFLOW_DATA[0].action }],
firstStep: { ...MOCK_WORKFLOW_DATA[0].firstStep },
scheme: { ...MOCK_WORKFLOW_DATA[0].scheme }
},
[MOCK_WORKFLOW_DATA[1].scheme.id]: {
actions: {
[MOCK_WORKFLOW_DATA[1].action.id]: { ...MOCK_WORKFLOW_DATA[1].action }
},
actions: [{ ...MOCK_WORKFLOW_DATA[1].action }],
firstStep: { ...MOCK_WORKFLOW_DATA[1].firstStep },
scheme: { ...MOCK_WORKFLOW_DATA[1].scheme }
}
};
Expand Down
24 changes: 23 additions & 1 deletion core-web/libs/edit-content/src/lib/utils/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,17 @@ export const EXISTING_WORKFLOW_MOCK: DotCMSWorkflowStatus = {
status: 'd95caaa6-1ece-42b2-8663-fb01e804a149',
title: '5 Snow Sports to Try This Winter',
webasset: '0edfee78-2a75-4f3d-bf20-813aae15d4e9'
},
firstStep: {
creationDate: 1731595862064,
enableEscalation: false,
escalationAction: null,
escalationTime: 0,
id: '6cb7e3bd-1710-4eed-8838-d3db60f78f19',
myOrder: 0,
name: 'New',
resolved: false,
schemeId: 'd61a59e1-a49c-46f2-a929-db2b4bfa88b2'
}
};

Expand All @@ -1623,5 +1634,16 @@ export const NEW_WORKFLOW_MOCK: DotCMSWorkflowStatus = {
variableName: 'Blogs'
},
step: null,
task: null
task: null,
firstStep: {
creationDate: 1731595862064,
enableEscalation: false,
escalationAction: null,
escalationTime: 0,
id: '6cb7e3bd-1710-4eed-8838-d3db60f78f19',
myOrder: 0,
name: 'New',
resolved: false,
schemeId: 'd61a59e1-a49c-46f2-a929-db2b4bfa88b2'
}
};

0 comments on commit 872cc0f

Please sign in to comment.