Skip to content

Commit

Permalink
feat(edit-content) remove test #28831
Browse files Browse the repository at this point in the history
  • Loading branch information
oidacra committed Jun 26, 2024
1 parent e2b1531 commit 175615d
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,33 @@

@switch (field.fieldType) {
@case (fieldTypes.SELECT) {
<dot-edit-content-select-field
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
<dot-edit-content-select-field [field]="field" [attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.RADIO) {
<dot-edit-content-radio-field
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
<dot-edit-content-radio-field [field]="field" [attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.TEXT) {
<dot-edit-content-text-field
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
<dot-edit-content-text-field [field]="field" [attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.TEXTAREA) {
<dot-edit-content-text-area
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
<dot-edit-content-text-area [field]="field" [attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.CHECKBOX) {
<dot-edit-content-checkbox-field
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
<dot-edit-content-checkbox-field [field]="field" [attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.MULTI_SELECT) {
<dot-edit-content-multi-select-field
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
}
@case (calendarTypes.includes(field.fieldType) ? field.fieldType : '') {
<dot-edit-content-calendar-field
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
<dot-edit-content-calendar-field [field]="field" [attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.TAG) {
<dot-edit-content-tag-field
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
<dot-edit-content-tag-field [field]="field" [attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.JSON) {
<dot-edit-content-json-field
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
<dot-edit-content-json-field [field]="field" [attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.BINARY) {
<dot-edit-content-binary-field
Expand Down Expand Up @@ -78,9 +62,7 @@
[attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.WYSIWYG) {
<dot-edit-content-wysiwyg-field
[field]="field"
[attr.data-testId]="'field-' + field.variable" />
<dot-edit-content-wysiwyg-field [field]="field" [attr.data-testId]="'field-' + field.variable" />
}
@case (fieldTypes.HOST_FOLDER) {
<dot-edit-content-host-folder-field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@
[ngClass]="{ 'no-overflow-x-yet': emptyColumns().length }"
class="flex-1 category-list__category-list">
@for (column of categories(); let index = $index; track index) {
<!--dynamic columns-->
<div #categoryColumn class="category-list__category-column" data-testId="category-column">
@for (item of column; track item.inode) {
<div
data-testId="category-item"
class="flex align-content-center align-items-center category-list__item"
[ngClass]="{ 'category-list__item--selected': item.checked }"
(click)="itemClicked.emit({ index, item })">
<p-checkbox [(ngModel)]="itemsSelected" [value]="item.key" />
<!--dynamic columns-->
<div #categoryColumn class="category-list__category-column" data-testId="category-column">
@for (item of column; track item.inode) {
<div
data-testId="category-item"
class="flex align-content-center align-items-center category-list__item"
[ngClass]="{ 'category-list__item--selected': item.checked }"
(click)="itemClicked.emit({ index, item })">
<p-checkbox [(ngModel)]="itemsSelected" [value]="item.key" />

<label
data-testId="category-item-label"
class="flex flex-grow-1 category-list__item-label"
[ngClass]="{ 'cursor-pointer': item.childrenCount > 0 }"
[for]="item.key"
>{{ item.categoryName }}</label
>
<label
data-testId="category-item-label"
class="flex flex-grow-1 category-list__item-label"
[ngClass]="{ 'cursor-pointer': item.childrenCount > 0 }"
[for]="item.key"
>{{ item.categoryName }}</label
>

@if (item.childrenCount > 0) {
<i
data-testId="category-item-with-child"
class="pi pi-chevron-right category-list__item-icon"></i>
}
</div>
@if (item.childrenCount > 0) {
<i
data-testId="category-item-with-child"
class="pi pi-chevron-right category-list__item-icon"></i>
}
</div>
}
</div>
}

<!--Fake empty columns-->
@for (_ of emptyColumns(); track _) {
<div
class="flex-grow-1 category-list__category-column"
data-testId="category-column-empty"></div>
<div
class="flex-grow-1 category-list__category-column"
data-testId="category-column-empty"></div>
}
</div>
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@if (store.selectedCategories().length) {
<div class="dot-category-field__categories" data-testId="category-chip-list">
@for (category of store.categoriesValue(); track category.key) {
<p-chip
[pTooltip]="category.value"
[removable]="true"
[label]="category.value"
tooltipPosition="top"
styleClass="p-chip-sm" />
}
</div>
<div class="dot-category-field__categories" data-testId="category-chip-list">
@for (category of store.categoriesValue(); track category.key) {
<p-chip
[pTooltip]="category.value"
[removable]="true"
[label]="category.value"
tooltipPosition="top"
styleClass="p-chip-sm" />
}
</div>
}

<div class="dot-category-field__select">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
@if (contentletArea.payload.container) {
<p-button
(click)="setPositionFlag('before'); menu.toggle($event)"
[ngStyle]="styles.topButton"
data-testId="add-top-button"
icon="pi pi-plus"></p-button>
<p-button
*ngIf="!isContainerEmpty"
(click)="setPositionFlag('after'); menu.toggle($event)"
[ngStyle]="styles.bottomButton"
data-testId="add-bottom-button"
icon="pi pi-plus"></p-button>
<p-menu [model]="items()" [popup]="true" #menu appendTo="body" data-testId="menu-add"></p-menu>
<p-button
(click)="setPositionFlag('before'); menu.toggle($event)"
[ngStyle]="styles.topButton"
data-testId="add-top-button"
icon="pi pi-plus"></p-button>
<p-button
*ngIf="!isContainerEmpty"
(click)="setPositionFlag('after'); menu.toggle($event)"
[ngStyle]="styles.bottomButton"
data-testId="add-bottom-button"
icon="pi pi-plus"></p-button>
<p-menu [model]="items()" [popup]="true" #menu appendTo="body" data-testId="menu-add"></p-menu>
}

<div *ngIf="!isContainerEmpty" [ngStyle]="styles.actions" class="actions" data-testId="actions">
@if (contentletArea.payload.vtlFiles?.length) {
<p-menu [model]="vtlFiles" [popup]="true" #menuVTL appendTo="body" data-testId="menu-vtl" />
<p-button
(click)="menuVTL.toggle($event)"
data-testId="edit-vtl-button"
styleClass="p-button-rounded p-button-raised"
icon="pi pi-code" />
}
@if (contentletArea.payload.container) {
<p-button
(dragstart)="dragStart($event)"
[attr.data-item]="
{
container: contentletArea.payload.container,
contentlet: contentletArea.payload.contentlet,
move: true
} | json
"
data-type="contentlet"
draggable="true"
data-testId="drag-button"
styleClass="p-button-rounded p-button-raised"
icon="pi pi-arrows-alt" />
<p-button
(click)="delete.emit(contentletArea.payload)"
data-testId="delete-button"
styleClass="p-button-rounded p-button-raised delete"
icon="pi pi-times" />
<p-menu [model]="vtlFiles" [popup]="true" #menuVTL appendTo="body" data-testId="menu-vtl" />
<p-button
(click)="menuVTL.toggle($event)"
data-testId="edit-vtl-button"
styleClass="p-button-rounded p-button-raised"
icon="pi pi-code" />
} @if (contentletArea.payload.container) {
<p-button
(dragstart)="dragStart($event)"
[attr.data-item]="
{
container: contentletArea.payload.container,
contentlet: contentletArea.payload.contentlet,
move: true
} | json
"
data-type="contentlet"
draggable="true"
data-testId="drag-button"
styleClass="p-button-rounded p-button-raised"
icon="pi pi-arrows-alt" />
<p-button
(click)="delete.emit(contentletArea.payload)"
data-testId="delete-button"
styleClass="p-button-rounded p-button-raised delete"
icon="pi pi-times" />
}

<p-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,20 @@
[variantId]="es.editorData.variantId"
data-testId="palette" />

@if (
es.editorData.canEditVariant &&
(es.editorData.mode === editorMode.EDIT || es.editorData.mode === editorMode.EDIT_VARIANT)
) {
<dot-edit-ema-dialog
(action)="onCustomEvent($event)"
(reloadFromDialog)="reloadFromDialog()"
#dialog
data-testId="ema-dialog"></dot-edit-ema-dialog>
<p-confirmDialog
[style]="{
width: '400px'
}"
rejectIcon="hidden"
acceptIcon="hidden"
rejectButtonStyleClass="p-button-outlined"
data-testId="confirm-dialog"></p-confirmDialog>
@if ( es.editorData.canEditVariant && (es.editorData.mode === editorMode.EDIT ||
es.editorData.mode === editorMode.EDIT_VARIANT) ) {
<dot-edit-ema-dialog
(action)="onCustomEvent($event)"
(reloadFromDialog)="reloadFromDialog()"
#dialog
data-testId="ema-dialog"></dot-edit-ema-dialog>
<p-confirmDialog
[style]="{
width: '400px'
}"
rejectIcon="hidden"
acceptIcon="hidden"
rejectButtonStyleClass="p-button-outlined"
data-testId="confirm-dialog"></p-confirmDialog>
}
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { ButtonModule } from 'primeng/button';

import { DotMessageService } from '@dotcms/data-access';
import { DotAIImageOrientation, DotGeneratedAIImage, PromptType } from '@dotcms/dotcms-models';
import { DotClipboardUtil, DotCopyButtonComponent, DotMessagePipe } from '@dotcms/ui';

import { DotCopyButtonComponent } from './../../../../components/dot-copy-button/dot-copy-button.component';
import { DotMessagePipe } from './../../../../dot-message/dot-message.pipe';
import { AiImagePromptFormComponent } from './ai-image-prompt-form.component';

describe('DotAiImagePromptFormComponent', () => {
Expand All @@ -22,8 +21,13 @@ describe('DotAiImagePromptFormComponent', () => {
};
const createComponent = createComponentFactory({
component: AiImagePromptFormComponent,
imports: [HttpClientTestingModule, ButtonModule, ReactiveFormsModule],
providers: [DotMessageService],
imports: [
HttpClientTestingModule,
ButtonModule,
ReactiveFormsModule,
DotCopyButtonComponent
],
providers: [DotMessageService, DotClipboardUtil],
mocks: [DotMessagePipe]
});

Expand Down Expand Up @@ -54,21 +58,6 @@ describe('DotAiImagePromptFormComponent', () => {
expect(spectator.component.form.get('text').validator).toBeNull();
});

it('should update form when changes come', () => {
const newGeneratedValue = {
request: formValue,
response: { revised_prompt: 'New Prompt' }
} as DotGeneratedAIImage;

spectator.setInput('value', newGeneratedValue);
spectator.setInput('isLoading', false);

expect(spectator.component.form.value).toEqual(newGeneratedValue.request);
expect(spectator.component.aiProcessedPrompt).toBe(
newGeneratedValue.response.revised_prompt
);
});

it('should disable form controls when isLoading is true', () => {
spectator.setInput('isLoading', true);
expect(spectator.query('form').getAttribute('disabled')).toBeDefined();
Expand Down Expand Up @@ -122,22 +111,4 @@ describe('DotAiImagePromptFormComponent', () => {

expect(spectator.query(byTestId('prompt-label')).classList).not.toContain(REQUIRED_CLASS);
});

it('should copy to clipboard the ai rewritten text', () => {
const newGeneratedValue = {
request: formValue,
response: { revised_prompt: 'New Prompt' }
} as DotGeneratedAIImage;

spectator.setInput('value', newGeneratedValue);
spectator.setInput('isLoading', false);

const icon = spectator.query(byTestId('copy-to-clipboard'));

const btnCopy = spectator.query(DotCopyButtonComponent);
const spyCopy = spyOn(btnCopy, 'copyUrlToClipboard');
spectator.click(icon);

expect(spyCopy).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import { ToolbarModule } from 'primeng/toolbar';

import { DotMessageService } from '@dotcms/data-access';
import { DotCMSWorkflowAction } from '@dotcms/dotcms-models';
import { DotClipboardUtil, DotMessagePipe, DotWorkflowActionsComponent } from '@dotcms/ui';
import { MockDotMessageService, mockWorkflowsActions } from '@dotcms/utils-testing';

import { DotWorkflowActionsComponent } from './dot-workflow-actions.component';

import { DotMessagePipe } from '../../dot-message/dot-message.pipe';

const WORKFLOW_ACTIONS_SEPARATOR_MOCK: DotCMSWorkflowAction = {
assignable: true,
commentable: true,
Expand Down Expand Up @@ -75,7 +72,8 @@ describe('DotWorkflowActionsComponent', () => {
{
provide: DotMessageService,
useValue: messageServiceMock
}
},
DotClipboardUtil
],
detectChanges: false
});
Expand All @@ -89,7 +87,7 @@ describe('DotWorkflowActionsComponent', () => {
size: 'normal'
}
});
spectator.detectComponentChanges();
spectator.detectChanges();
});

describe('without actions', () => {
Expand Down Expand Up @@ -125,6 +123,7 @@ describe('DotWorkflowActionsComponent', () => {
describe('group action', () => {
it('should render an extra split button for each `SEPARATOR` Action', () => {
const splitButtons = spectator.queryAll(SplitButton);
spectator.detectComponentChanges();
expect(splitButtons.length).toBe(2);
});

Expand Down

0 comments on commit 175615d

Please sign in to comment.