-
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.
chore(edit-content): apply format to relationships (#31048)
### Parent Issue #31040 ### Proposed Changes This pull request introduces a new enumeration `DotContentletDepths` to manage the depth of contentlets and updates various components to utilize this enumeration. The changes include updates to type definitions, imports, and method calls to incorporate the new `DotContentletDepths` enum. ### Introduction of `DotContentletDepths` Enumeration: * Added `DotContentletDepths` enum to define the depth levels of contentlets in `dot-contentlet.model.ts`. ### Updates to Import Statements: * Updated import statements to include `DotContentletDepths` in `dot-edit-content-form.component.spec.ts`, `edit-content.store.ts`, `content.feature.ts`, `dot-edit-content-relationship-field.component.ts`, `dot-edit-content.service.spec.ts`, and `dot-edit-content.service.ts`. [[1]](diffhunk://#diff-ba170b6ba64e637bbeea8b08f81a725fc7de75cfb94e910ab35148aa4c377ec5L29-R29) [[2]](diffhunk://#diff-ed3e9ecca632a2f217989f35608b4eedd1576950bda10c74f8598e83a4703016L6-R6) [[3]](diffhunk://#diff-45e4158706adbaf57599a885340534ed77401e3c69ea593dd9b377ffacc36958R32) [[4]](diffhunk://#diff-479af3558b758325f127c8f7abe07cf9da59524f145b758f7c298e82a8e9cbadR15) [[5]](diffhunk://#diff-ee2c6ce1c6a997f7b2b87106dbc020dba9d7f42fcdc29caebe547f6963e7caabL13-R13) ### Updates to Method Calls: * Modified `initializeExistingContent` method calls to include the `depth` parameter in `dot-edit-content-form.component.spec.ts` and `edit-content.store.ts`. [[1]](diffhunk://#diff-ba170b6ba64e637bbeea8b08f81a725fc7de75cfb94e910ab35148aa4c377ec5L125-R128) [[2]](diffhunk://#diff-ba170b6ba64e637bbeea8b08f81a725fc7de75cfb94e910ab35148aa4c377ec5L203-R209) [[3]](diffhunk://#diff-ba170b6ba64e637bbeea8b08f81a725fc7de75cfb94e910ab35148aa4c377ec5L296-R305) [[4]](diffhunk://#diff-ba170b6ba64e637bbeea8b08f81a725fc7de75cfb94e910ab35148aa4c377ec5L310-R322) [[5]](diffhunk://#diff-ba170b6ba64e637bbeea8b08f81a725fc7de75cfb94e910ab35148aa4c377ec5L323-R338) [[6]](diffhunk://#diff-ba170b6ba64e637bbeea8b08f81a725fc7de75cfb94e910ab35148aa4c377ec5L337-R355) [[7]](diffhunk://#diff-ed3e9ecca632a2f217989f35608b4eedd1576950bda10c74f8598e83a4703016L49-R49) ### Enhancements to Relationship Field Store: * Added a new test file `relationship-field.store.spec.ts` to validate the functionality of `RelationshipFieldStore`. * Enhanced `relationship-field.store.ts` by adding computed properties for pagination, disabling create new content button, and formatting relationships. Removed unnecessary hooks and methods. [[1]](diffhunk://#diff-a2c980da63c75c9dc2cd899475beab89cb79492b1dc0819574fc380e856e7ed1L5-L15) [[2]](diffhunk://#diff-a2c980da63c75c9dc2cd899475beab89cb79492b1dc0819574fc380e856e7ed1R50-R58) [[3]](diffhunk://#diff-a2c980da63c75c9dc2cd899475beab89cb79492b1dc0819574fc380e856e7ed1R68-R76) [[4]](diffhunk://#diff-a2c980da63c75c9dc2cd899475beab89cb79492b1dc0819574fc380e856e7ed1L118-L124) [[5]](diffhunk://#diff-a2c980da63c75c9dc2cd899475beab89cb79492b1dc0819574fc380e856e7ed1L151-L155) ### Service Method Updates: * Updated `dot-edit-content.service.spec.ts` to include a test for getting content by id and depth. ### Checklist - [x] Tests - [x] Translations - [x] Security Implications Contemplated (add notes if applicable)
- Loading branch information
Showing
12 changed files
with
280 additions
and
47 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
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
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
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
153 changes: 153 additions & 0 deletions
153
...src/lib/fields/dot-edit-content-relationship-field/store/relationship-field.store.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 |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { ComponentStatus } from '@dotcms/dotcms-models'; | ||
|
||
import { RelationshipFieldStore } from './relationship-field.store'; | ||
|
||
import { RelationshipFieldItem } from '../models/relationship.models'; | ||
|
||
describe('RelationshipFieldStore', () => { | ||
let store: InstanceType<typeof RelationshipFieldStore>; | ||
|
||
const mockData: RelationshipFieldItem[] = [ | ||
{ id: '1', title: 'Content 1', language: '1', modDate: new Date().toISOString() }, | ||
{ id: '2', title: 'Content 2', language: '1', modDate: new Date().toISOString() }, | ||
{ id: '3', title: 'Content 3', language: '1', modDate: new Date().toISOString() } | ||
]; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [RelationshipFieldStore] | ||
}); | ||
|
||
store = TestBed.inject(RelationshipFieldStore); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(store).toBeTruthy(); | ||
}); | ||
|
||
describe('Initial State', () => { | ||
it('should have correct initial state', () => { | ||
expect(store.data()).toEqual([]); | ||
expect(store.status()).toBe(ComponentStatus.INIT); | ||
expect(store.selectionMode()).toBeNull(); | ||
expect(store.pagination()).toEqual({ | ||
offset: 0, | ||
currentPage: 1, | ||
rowsPerPage: 6 | ||
}); | ||
}); | ||
}); | ||
|
||
describe('State Management', () => { | ||
describe('setData', () => { | ||
it('should set data correctly', () => { | ||
store.setData(mockData); | ||
expect(store.data()).toEqual(mockData); | ||
}); | ||
}); | ||
|
||
describe('setCardinality', () => { | ||
it('should set single selection mode for ONE_TO_ONE relationship', () => { | ||
store.setCardinality(2); // ONE_TO_ONE cardinality | ||
expect(store.selectionMode()).toBe('single'); | ||
}); | ||
|
||
it('should set multiple selection mode for other relationship types', () => { | ||
store.setCardinality(0); // ONE_TO_MANY cardinality | ||
expect(store.selectionMode()).toBe('multiple'); | ||
}); | ||
|
||
it('should throw error for invalid cardinality', () => { | ||
expect(() => store.setCardinality(999)).toThrow('Invalid relationship type'); | ||
}); | ||
}); | ||
|
||
describe('addData', () => { | ||
it('should add new unique data to existing data', () => { | ||
const initialData = [mockData[0]]; | ||
const newData = [mockData[1], mockData[2]]; | ||
|
||
store.setData(initialData); | ||
store.addData(newData); | ||
|
||
expect(store.data()).toEqual([...initialData, ...newData]); | ||
}); | ||
|
||
it('should not add duplicate data', () => { | ||
const initialData = [mockData[0]]; | ||
const newData = [mockData[0], mockData[1]]; | ||
|
||
store.setData(initialData); | ||
store.addData(newData); | ||
|
||
expect(store.data()).toEqual([mockData[0], mockData[1]]); | ||
}); | ||
}); | ||
|
||
describe('pagination', () => { | ||
it('should handle next page correctly', () => { | ||
store.nextPage(); | ||
expect(store.pagination()).toEqual({ | ||
offset: 6, | ||
currentPage: 2, | ||
rowsPerPage: 6 | ||
}); | ||
}); | ||
|
||
it('should handle previous page correctly', () => { | ||
store.nextPage(); | ||
store.previousPage(); | ||
expect(store.pagination()).toEqual({ | ||
offset: 0, | ||
currentPage: 1, | ||
rowsPerPage: 6 | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Computed Properties', () => { | ||
describe('totalPages', () => { | ||
it('should compute total pages correctly', () => { | ||
store.setData(mockData); | ||
expect(store.totalPages()).toBe(1); | ||
}); | ||
|
||
it('should handle empty data', () => { | ||
expect(store.totalPages()).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('isDisabledCreateNewContent', () => { | ||
it('should disable for single mode with one item', () => { | ||
store.setCardinality(2); // ONE_TO_ONE | ||
store.setData([mockData[0]]); | ||
expect(store.isDisabledCreateNewContent()).toBe(true); | ||
}); | ||
|
||
it('should not disable for single mode with no items', () => { | ||
store.setCardinality(2); // ONE_TO_ONE | ||
expect(store.isDisabledCreateNewContent()).toBe(false); | ||
}); | ||
|
||
it('should not disable for multiple mode regardless of items', () => { | ||
store.setCardinality(0); // ONE_TO_MANY | ||
store.setData(mockData); | ||
expect(store.isDisabledCreateNewContent()).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('formattedRelationship', () => { | ||
it('should format relationship IDs correctly', () => { | ||
store.setData(mockData); | ||
expect(store.formattedRelationship()).toBe('1,2,3'); | ||
}); | ||
|
||
it('should handle empty data', () => { | ||
expect(store.formattedRelationship()).toBe(''); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.