Skip to content

Commit

Permalink
clean up and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoreras committed Nov 8, 2024
1 parent b8d6ff3 commit f3082f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
Spectator,
SpyObject
} from '@ngneat/spectator/jest';
import { patchState } from '@ngrx/signals';
import { of } from 'rxjs';

import { Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';

import { MessageService } from 'primeng/api';
import { TabPanel, TabView } from 'primeng/tabview';

import {
Expand All @@ -21,6 +23,7 @@ import {
DotWorkflowsActionsService,
DotWorkflowService
} from '@dotcms/data-access';
import { ComponentStatus } from '@dotcms/dotcms-models';
import { DotWorkflowActionsComponent } from '@dotcms/ui';
import { DotFormatDateServiceMock } from '@dotcms/utils-testing';

Expand All @@ -40,7 +43,7 @@ import { MockResizeObserver } from '../../utils/mocks';
describe('DotFormComponent', () => {
let spectator: Spectator<DotEditContentFormComponent>;
let component: DotEditContentFormComponent;
let store: SpyObject<InstanceType<typeof DotEditContentStore>>;
let store: InstanceType<typeof DotEditContentStore>;
let dotContentTypeService: SpyObject<DotContentTypeService>;
let workflowActionsService: SpyObject<DotWorkflowsActionsService>;
let workflowActionsFireService: SpyObject<DotWorkflowActionsFireService>;
Expand All @@ -62,6 +65,7 @@ describe('DotFormComponent', () => {
mockProvider(DotMessageService),
mockProvider(Router),
mockProvider(DotWorkflowService),
mockProvider(MessageService),
{
provide: ActivatedRoute,
useValue: {
Expand Down Expand Up @@ -125,6 +129,21 @@ describe('DotFormComponent', () => {
expect(component.form.get('modUserName')).toBeFalsy();
expect(component.form.get('publishDate')).toBeFalsy();
});

it('should disable the form when loading and enable it when not loading', () => {
spectator.detectChanges();

// // Initially, the form should be enabled
expect(component.form.enabled).toBe(true);

patchState(store, {
state: ComponentStatus.SAVING
});

spectator.flushEffects();

expect(component.form.enabled).toBe(false);
});
});

describe('New Content', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
DestroyRef,
effect,
inject,
Injector,
OnInit,
output
} from '@angular/core';
Expand Down Expand Up @@ -148,8 +147,6 @@ export class DotEditContentFormComponent implements OnInit {
}
}

injector = inject(Injector);

constructor() {
effect(() => {
const isLoading = this.$store.isLoading();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ import { CONTENT_TYPE_MOCK } from '../../../utils/mocks';

const messageServiceMock = new MockDotMessageService({
'edit.content.success.workflow.message': 'Your changes have being applied.',
success: 'Success',
error: 'Error'
success: 'Success'
});

describe('DotEditContentStore', () => {
Expand Down

0 comments on commit f3082f1

Please sign in to comment.