-
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(edit-content): implement relationship field data table with mock…
… data (#30825) ### Parent Issue #30523 ### Proposed Changes This pull request includes several changes to the `core-web` library, focusing on improvements to the `dot-select-existing-content` component and its associated files. The changes involve updates to the SCSS file, HTML templates, TypeScript components, and the addition of new tests. Here are the most important changes: ### SCSS Changes: * Updated the primary tint color in `_colors.scss` from `$color-palette-primary-200` to `$color-palette-primary-100`. ### HTML Template Changes: * Added a condition to display the hint only if the field type is not `RELATIONSHIP` in `dot-edit-content-field.component.html`. * Removed the pagination HTML structure from `pagination.component.html` and added a new structure with conditional layout based on `$currentPageReportLayout`. ### TypeScript Component Changes: * Added `output` import and defined `onSelectItems` signal to emit selected items in `dot-select-existing-content.component.ts`. [[1]](diffhunk://#diff-14d3d666b0a074fe26436013ebf4abe96e518e28e9799b85b393d14b82ac528bL2-R2) [[2]](diffhunk://#diff-14d3d666b0a074fe26436013ebf4abe96e518e28e9799b85b393d14b82ac528bR93-R114) * Replaced `Content` type with `RelationshipFieldItem` and updated the store to use `tapResponse` for handling content loading in `existing-content.store.ts`. [[1]](diffhunk://#diff-1c1758cf3c19df1a6e75e613761290b504a1d26e8521af1492593e1825969b63R10-R22) [[2]](diffhunk://#diff-1c1758cf3c19df1a6e75e613761290b504a1d26e8521af1492593e1825969b63L53-R76) ### Test Additions: * Added a new test suite for `DotSelectExistingContentComponent` to validate dialog visibility, selected items state, and apply button label in `dot-select-existing-content.component.spec.ts`. These changes enhance the functionality and maintainability of the `dot-select-existing-content` component and its related parts. ### Checklist - [ ] Tests - [ ] Translations - [ ] Security Implications Contemplated (add notes if applicable)
- Loading branch information
Showing
18 changed files
with
593 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,3 +179,5 @@ dotCMS/dependencies.gradle | |
!/examples/nextjs/.npmrc | ||
|
||
.nx/ | ||
.cursorrules | ||
.cursorignore |
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
26 changes: 0 additions & 26 deletions
26
...ld/components/dot-select-existing-content/components/pagination/pagination.component.html
This file was deleted.
Oops, something went wrong.
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
88 changes: 88 additions & 0 deletions
88
...ield/components/dot-select-existing-content/dot-select-existing-content.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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Spectator, createComponentFactory } from '@ngneat/spectator/jest'; | ||
|
||
import { DotMessageService } from '@dotcms/data-access'; | ||
import { RelationshipFieldItem } from '@dotcms/edit-content/fields/dot-edit-content-relationship-field/models/relationship.models'; | ||
import { MockDotMessageService } from '@dotcms/utils-testing'; | ||
|
||
import { DotSelectExistingContentComponent } from './dot-select-existing-content.component'; | ||
import { ExistingContentStore } from './store/existing-content.store'; | ||
|
||
describe('DotSelectExistingContentComponent', () => { | ||
let spectator: Spectator<DotSelectExistingContentComponent>; | ||
let store: InstanceType<typeof ExistingContentStore>; | ||
|
||
const mockRelationshipItem = (id: string): RelationshipFieldItem => ({ | ||
id, | ||
title: `Test Content ${id}`, | ||
language: '1', | ||
state: { | ||
label: 'Published', | ||
styleClass: 'small-chip' | ||
}, | ||
description: 'Test description', | ||
step: 'Step 1', | ||
lastUpdate: new Date().toISOString() | ||
}); | ||
|
||
const messageServiceMock = new MockDotMessageService({ | ||
'dot.file.relationship.dialog.apply.one.entry': 'Apply 1 entry', | ||
'dot.file.relationship.dialog.apply.entries': 'Apply {0} entries' | ||
}); | ||
|
||
const createComponent = createComponentFactory({ | ||
component: DotSelectExistingContentComponent, | ||
componentProviders: [ExistingContentStore], | ||
providers: [{ provide: DotMessageService, useValue: messageServiceMock }], | ||
detectChanges: false | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent(); | ||
store = spectator.inject(ExistingContentStore, true); | ||
spectator.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(spectator.component).toBeTruthy(); | ||
expect(store).toBeTruthy(); | ||
}); | ||
|
||
describe('Dialog Visibility', () => { | ||
it('should set visibility to false when closeDialog is called', () => { | ||
spectator.component.$visible.set(true); | ||
spectator.component.closeDialog(); | ||
expect(spectator.component.$visible()).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('Selected Items State', () => { | ||
it('should disable apply button when no items are selected', () => { | ||
spectator.component.$selectedItems.set([]); | ||
expect(spectator.component.$isApplyDisabled()).toBeTruthy(); | ||
}); | ||
|
||
it('should enable apply button when items are selected', () => { | ||
const mockContent = [mockRelationshipItem('1')]; | ||
spectator.component.$selectedItems.set(mockContent); | ||
expect(spectator.component.$isApplyDisabled()).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('Apply Button Label', () => { | ||
it('should show singular label when one item is selected', () => { | ||
const mockContent = [mockRelationshipItem('1')]; | ||
spectator.component.$selectedItems.set(mockContent); | ||
|
||
const label = spectator.component.$applyLabel(); | ||
expect(label).toBe('Apply 1 entry'); | ||
}); | ||
|
||
it('should show plural label when multiple items are selected', () => { | ||
const mockContent = [mockRelationshipItem('1'), mockRelationshipItem('2')]; | ||
spectator.component.$selectedItems.set(mockContent); | ||
|
||
const label = spectator.component.$applyLabel(); | ||
expect(label).toBe('Apply 2 entries'); | ||
}); | ||
}); | ||
}); |
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.