-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor-content): add storybook and unit tests #29871
- Loading branch information
Showing
4 changed files
with
216 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 92 additions & 5 deletions
97
.../src/lib/fields/dot-edit-content-file-field/dot-edit-content-file-field.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,111 @@ | ||
import { Spectator, createComponentFactory, mockProvider } from '@ngneat/spectator/jest'; | ||
import { Spectator, byTestId, createComponentFactory, mockProvider } from '@ngneat/spectator/jest'; | ||
|
||
import { provideHttpClient } from '@angular/common/http'; | ||
import { ControlContainer } from '@angular/forms'; | ||
|
||
import { DotMessageService } from '@dotcms/data-access'; | ||
import { | ||
DotDropZoneComponent, | ||
} from '@dotcms/ui'; | ||
|
||
import { DotEditContentFileFieldComponent } from './dot-edit-content-file-field.component'; | ||
import { FileFieldStore } from './store/file-field.store'; | ||
|
||
import { BINARY_FIELD_MOCK, createFormGroupDirectiveMock, FILE_FIELD_MOCK, IMAGE_FIELD_MOCK } from '../../utils/mocks'; | ||
|
||
|
||
describe('DotEditContentFileFieldComponent', () => { | ||
let spectator: Spectator<DotEditContentFileFieldComponent>; | ||
const createComponent = createComponentFactory({ | ||
component: DotEditContentFileFieldComponent, | ||
detectChanges: false, | ||
componentProviders: [FileFieldStore], | ||
providers: [provideHttpClient(), mockProvider(DotMessageService)] | ||
providers: [provideHttpClient(), mockProvider(DotMessageService)], | ||
componentViewProviders: [ | ||
{ provide: ControlContainer, useValue: createFormGroupDirectiveMock() } | ||
], | ||
}); | ||
|
||
beforeEach(() => (spectator = createComponent())); | ||
describe('FileField', () => { | ||
beforeEach(() => (spectator = createComponent({ | ||
props: { | ||
field: FILE_FIELD_MOCK | ||
} as unknown | ||
}))); | ||
|
||
it('should be created', () => { | ||
expect(spectator.component).toBeTruthy(); | ||
}); | ||
|
||
it('should have a DotDropZoneComponent', () => { | ||
spectator.detectChanges(); | ||
|
||
expect(spectator.query(DotDropZoneComponent)).toBeTruthy(); | ||
}); | ||
|
||
it('should show the proper actions', () => { | ||
spectator.detectChanges(); | ||
|
||
it('should be created', () => { | ||
expect(spectator.component).toBeTruthy(); | ||
expect(spectator.query(byTestId('action-import-from-url'))).toBeTruthy(); | ||
expect(spectator.query(byTestId('action-existing-file'))).toBeTruthy(); | ||
expect(spectator.query(byTestId('action-new-file'))).toBeTruthy(); | ||
expect(spectator.query(byTestId('action-generate-with-ai'))).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('ImageField', () => { | ||
beforeEach(() => (spectator = createComponent({ | ||
props: { | ||
field: IMAGE_FIELD_MOCK | ||
} as unknown | ||
}))); | ||
|
||
it('should be created', () => { | ||
expect(spectator.component).toBeTruthy(); | ||
}); | ||
|
||
it('should have a DotDropZoneComponent', () => { | ||
spectator.detectChanges(); | ||
|
||
expect(spectator.query(DotDropZoneComponent)).toBeTruthy(); | ||
}); | ||
|
||
it('should show the proper actions', () => { | ||
spectator.detectChanges(); | ||
|
||
expect(spectator.query(byTestId('action-import-from-url'))).toBeTruthy(); | ||
expect(spectator.query(byTestId('action-existing-file'))).toBeTruthy(); | ||
expect(spectator.query(byTestId('action-new-file'))).toBeFalsy(); | ||
expect(spectator.query(byTestId('action-generate-with-ai'))).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('BinaryField', () => { | ||
beforeEach(() => (spectator = createComponent({ | ||
props: { | ||
field: BINARY_FIELD_MOCK | ||
} as unknown | ||
}))); | ||
|
||
it('should be created', () => { | ||
expect(spectator.component).toBeTruthy(); | ||
}); | ||
|
||
it('should have a DotDropZoneComponent', () => { | ||
spectator.detectChanges(); | ||
|
||
expect(spectator.query(DotDropZoneComponent)).toBeTruthy(); | ||
}); | ||
|
||
it('should show the proper actions', () => { | ||
spectator.detectChanges(); | ||
|
||
expect(spectator.query(byTestId('action-import-from-url'))).toBeTruthy(); | ||
expect(spectator.query(byTestId('action-existing-file'))).toBeFalsy(); | ||
expect(spectator.query(byTestId('action-new-file'))).toBeTruthy(); | ||
expect(spectator.query(byTestId('action-generate-with-ai'))).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
|
||
}); |
78 changes: 78 additions & 0 deletions
78
...c/lib/fields/dot-edit-content-file-field/dot-edit-content-file-field.component.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { moduleMetadata, StoryObj, Meta, applicationConfig, argsToTemplate } from '@storybook/angular'; | ||
|
||
import { provideHttpClient } from '@angular/common/http'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
|
||
|
||
import { DotMessageService } from '@dotcms/data-access'; | ||
import { DotCMSContentTypeField } from '@dotcms/dotcms-models'; | ||
|
||
import { DotEditContentFileFieldComponent } from './dot-edit-content-file-field.component'; | ||
import { FileFieldStore } from './store/file-field.store'; | ||
import { MessageServiceMock } from './utils/mocks'; | ||
|
||
import { | ||
FILE_FIELD_MOCK, IMAGE_FIELD_MOCK, BINARY_FIELD_MOCK | ||
} from '../../utils/mocks'; | ||
|
||
type Args = DotEditContentFileFieldComponent & { | ||
field: DotCMSContentTypeField; | ||
value: string; | ||
} | ||
|
||
const meta: Meta<Args> = { | ||
title: 'Library / Edit Content / File Field', | ||
component: DotEditContentFileFieldComponent, | ||
decorators: [ | ||
applicationConfig({ | ||
providers: [ | ||
provideHttpClient(), | ||
{ | ||
provide: DotMessageService, | ||
useValue : MessageServiceMock | ||
} | ||
] | ||
}), | ||
moduleMetadata({ | ||
imports: [ | ||
BrowserAnimationsModule, | ||
FormsModule, | ||
], | ||
providers: [ | ||
FileFieldStore | ||
] | ||
}) | ||
], | ||
render: (args) => ({ | ||
props: args, | ||
template: ` | ||
<dot-edit-content-file-field ${argsToTemplate(args)} [(ngModel)]="value" /> | ||
<p>Current value: {{ value }}</p> | ||
` | ||
}) | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<Args>; | ||
|
||
export const FileField: Story = { | ||
args: { | ||
value: '', | ||
field: {...FILE_FIELD_MOCK} | ||
} | ||
}; | ||
|
||
export const ImageField: Story = { | ||
args: { | ||
value: '', | ||
field: {...IMAGE_FIELD_MOCK} | ||
} | ||
}; | ||
|
||
export const BinaryField: Story = { | ||
args: { | ||
value: '', | ||
field: {...BINARY_FIELD_MOCK} | ||
} | ||
}; |
42 changes: 42 additions & 0 deletions
42
core-web/libs/edit-content/src/lib/fields/dot-edit-content-file-field/utils/mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { MockDotMessageService } from "@dotcms/utils-testing"; | ||
|
||
const MESSAGES_MOCK = { | ||
'dot.file.field.action.choose.file': 'Choose File', | ||
'dot.file.field.action.create.new.file': 'Create New File', | ||
'dot.file.field.action.create.new.file.label': 'File Name', | ||
'dot.file.field.action.import.from.url.error.message': | ||
'The URL you requested is not valid. Please try again.', | ||
'dot.file.field.action.import.from.url': 'Import from URL', | ||
'dot.file.field.action.remove': 'Remove', | ||
'dot.file.field.dialog.create.new.file.header': 'File Details', | ||
'dot.file.field.dialog.import.from.url.header': 'URL', | ||
'dot.file.field.drag.and.drop.error.could.not.load.message': | ||
'<strong>Couldn't load the file.</strong> Please try again or', | ||
'dot.file.field.drag.and.drop.error.file.maxsize.exceeded.message': | ||
'The file weight <strong>exceeds the limits of {0}</strong>, please reduce size before uploading.', | ||
'dot.file.field.drag.and.drop.error.file.not.supported.message': | ||
'This type of <strong>file is not supported</strong>, Please select a {0} file.', | ||
'dot.file.field.drag.and.drop.error.multiple.files.dropped.message': | ||
'You can only upload one file at a time.', | ||
'dot.file.field.drag.and.drop.error.server.error.message': | ||
'<strong>Something went wrong</strong>, please try again or contact our support team.', | ||
'dot.file.field.drag.and.drop.message': 'Drag and Drop or', | ||
'dot.file.field.error.type.file.not.extension': "Please add the file's extension", | ||
'dot.file.field.error.type.file.not.supported.message': | ||
'This type of file is not supported. Please use a {0} file.', | ||
'dot.file.field.file.bytes': 'Bytes', | ||
'dot.file.field.file.dimension': 'Dimension', | ||
'dot.file.field.file.size': 'File Size', | ||
'dot.file.field.import.from.url.error.file.not.supported.message': | ||
'This type of file is not supported, Please import a {0} file.', | ||
'dot.file.field.action.generate.with.dotai': 'Generate with dotAI', | ||
'dot.file.field.action.select.existing.file': 'Select Existing File', | ||
'dot.common.cancel': 'Cancel', | ||
'dot.common.edit': 'Edit', | ||
'dot.common.import': 'Import', | ||
'dot.common.remove': 'Remove', | ||
'dot.common.save': 'Save', | ||
'error.form.validator.required': 'This field is required', | ||
}; | ||
|
||
export const MessageServiceMock = new MockDotMessageService(MESSAGES_MOCK); |