-
Notifications
You must be signed in to change notification settings - Fork 667
CardView - implement ContentView #28791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pomahtri
merged 3 commits into
grids/cardview/main
from
grids/cardview/content_view/impl
Feb 18, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
...__internal/grids/new/card_view/content_view/content/card/__snapshots__/card.test.tsx.snap
This file contains hidden or 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 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Rendering should be rendered correctly 1`] = ` | ||
| <div> | ||
| <div | ||
| class="dx-cardview-card" | ||
| style="min-width: undefinedpx; max-width: undefinedpx;" | ||
| tabindex="0" | ||
| > | ||
| <div | ||
| class="dx-cardview-card-header" | ||
| > | ||
| <div | ||
| class="dx-toolbar dx-widget dx-visibility-change-handler dx-collection" | ||
| role="toolbar" | ||
| > | ||
| <div | ||
| class="dx-toolbar-items-container" | ||
| > | ||
| <div | ||
| class="dx-toolbar-before" | ||
| role="presentation" | ||
| > | ||
| <div | ||
| class="dx-item dx-toolbar-item dx-toolbar-button" | ||
| > | ||
| <div | ||
| class="dx-item-content dx-toolbar-item-content" | ||
| > | ||
| <div | ||
| aria-checked="false" | ||
| aria-invalid="false" | ||
| aria-readonly="false" | ||
| class="dx-widget dx-checkbox" | ||
| role="checkbox" | ||
| tabindex="0" | ||
| > | ||
| <input | ||
| type="hidden" | ||
| value="false" | ||
| /> | ||
| <div | ||
| class="dx-checkbox-container" | ||
| > | ||
| <span | ||
| class="dx-checkbox-icon" | ||
| /> | ||
|
|
||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div | ||
| class="dx-item dx-toolbar-item dx-toolbar-label" | ||
| > | ||
| <div | ||
| class="dx-item-content dx-toolbar-item-content" | ||
| > | ||
| <div> | ||
| Card Header | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div | ||
| class="dx-toolbar-center" | ||
| role="presentation" | ||
| /> | ||
| <div | ||
| class="dx-toolbar-after" | ||
| role="presentation" | ||
| > | ||
| <div | ||
| class="dx-item dx-toolbar-item dx-toolbar-button" | ||
| > | ||
| <div | ||
| class="dx-item-content dx-toolbar-item-content" | ||
| > | ||
| <div | ||
| aria-label="edit" | ||
| class="dx-widget dx-button dx-button-mode-text dx-button-normal dx-button-has-icon" | ||
| role="button" | ||
| tabindex="0" | ||
| > | ||
| <div | ||
| class="dx-button-content" | ||
| > | ||
| <i | ||
| class="dx-icon dx-icon-edit" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div | ||
| class="dx-item dx-toolbar-item dx-toolbar-button" | ||
| > | ||
| <div | ||
| class="dx-item-content dx-toolbar-item-content" | ||
| > | ||
| <div | ||
| aria-label="trash" | ||
| class="dx-widget dx-button dx-button-mode-text dx-button-normal dx-button-has-icon" | ||
| role="button" | ||
| tabindex="0" | ||
| > | ||
| <div | ||
| class="dx-button-content" | ||
| > | ||
| <i | ||
| class="dx-icon dx-icon-trash" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div | ||
| class="dx-card-cover" | ||
| > | ||
| <img | ||
| alt="Card Cover" | ||
| class="dx-card-cover-image" | ||
| src="https://www.devexpress.com/support/demos/i/demo-thumbs/aspnetcore-grid.png" | ||
| style="width: 100%; height: auto;" | ||
| /> | ||
| </div> | ||
| <div | ||
| class="dx-cardview-card-content" | ||
| > | ||
| <div | ||
| class="dx-cardview-field" | ||
| tabindex="0" | ||
| > | ||
| <span | ||
| class="dx-cardview-field-name" | ||
| > | ||
| Field | ||
| : | ||
| </span> | ||
| <span | ||
| class="dx-cardview-field-value" | ||
| > | ||
| devextreme | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| `; | ||
172 changes: 172 additions & 0 deletions
172
...vextreme/js/__internal/grids/new/card_view/content_view/content/card/card.events.test.tsx
This file contains hidden or 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,172 @@ | ||
| /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ | ||
| /* eslint-disable no-return-assign */ | ||
| /* eslint-disable @typescript-eslint/init-declarations */ | ||
| /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
| import { describe, expect, it } from '@jest/globals'; | ||
| import { render } from 'inferno'; | ||
|
|
||
| import { Card } from './card'; | ||
|
|
||
| const mockOnDblClick = { | ||
| called: false, | ||
| call() { | ||
| this.called = true; | ||
| }, | ||
| }; | ||
|
|
||
| const mockOnClick = { | ||
| called: false, | ||
| call() { | ||
| this.called = true; | ||
| }, | ||
| }; | ||
|
|
||
| const props = { | ||
| row: { | ||
| cells: [ | ||
| { | ||
| column: { | ||
| dataField: 'Name', | ||
| name: 'Field', | ||
| }, | ||
| value: 'devextreme', | ||
| text: 'devextreme', | ||
| }, | ||
| ], | ||
| key: 0, | ||
| }, | ||
| toolbar: [ | ||
| { | ||
| location: 'before', | ||
| widget: 'dxCheckBox', | ||
| }, | ||
| { | ||
| location: 'before', | ||
| text: 'Card Header', | ||
| }, | ||
| { | ||
| location: 'after', | ||
| widget: 'dxButton', | ||
| options: { | ||
| icon: 'edit', | ||
| stylingMode: 'text', | ||
| }, | ||
| }, | ||
| { | ||
| location: 'after', | ||
| widget: 'dxButton', | ||
| options: { | ||
| icon: 'trash', | ||
| stylingMode: 'text', | ||
| }, | ||
| }, | ||
| ], | ||
| cover: { | ||
| src: 'https://www.devexpress.com/support/demos/i/demo-thumbs/aspnetcore-grid.png', | ||
| alt: 'Card Cover', | ||
| className: 'card-cover', | ||
| }, | ||
| hoverStateEnabled: true, | ||
| maxWidth: 300, | ||
| width: 300, | ||
| minWidth: 300, | ||
| onDblClick: mockOnDblClick.call(), | ||
| onClick: mockOnClick.call(), | ||
| }; | ||
|
|
||
| const CLASSES = { | ||
| card: 'dx-cardview-card', | ||
| }; | ||
|
|
||
| describe('Events', () => { | ||
| let container: HTMLDivElement; | ||
| // @ts-expect-error | ||
| beforeEach(() => { | ||
| container = document.createElement('div'); | ||
| // @ts-expect-error | ||
| render(<Card {...props} />, container); | ||
| }); | ||
|
|
||
| it('should trigger onClick event', () => { | ||
| // @ts-expect-error | ||
| render(<Card {...props} />, container); | ||
|
|
||
| const cardElement = container.querySelector(`.${CLASSES.card}`); | ||
| cardElement?.dispatchEvent(new MouseEvent('click')); | ||
|
|
||
| expect(mockOnClick.called).toBe(true); | ||
pomahtri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it('should trigger onDblClick event', () => { | ||
| // @ts-expect-error | ||
| render(<Card {...props} />, container); | ||
|
|
||
| const cardElement = container.querySelector(`.${CLASSES.card}`); | ||
| cardElement?.dispatchEvent(new MouseEvent('dblclick')); | ||
|
|
||
| expect(mockOnDblClick.called).toBe(true); | ||
| }); | ||
|
|
||
| it('should trigger onHoverChanged event on mouse enter', () => { | ||
| const mockHover: { called: boolean; fn: ({ isHovered }: { isHovered: boolean }) => void } = { | ||
| called: false, | ||
| fn: ({ isHovered }: { isHovered: boolean }) => { | ||
| mockHover.called = true; | ||
| expect(isHovered).toBe(true); | ||
| }, | ||
| }; | ||
|
|
||
| const newProps = { ...props, hoverStateEnabled: true, onHoverChanged: mockHover.fn }; | ||
| // @ts-expect-error | ||
| render(<Card {...newProps} />, container); | ||
|
|
||
| const cardElement = container.querySelector(`.${CLASSES.card}`); | ||
| cardElement?.dispatchEvent(new MouseEvent('mouseenter')); | ||
|
|
||
| expect(mockHover.called).toBe(true); | ||
| }); | ||
|
|
||
| it('should trigger onHoverChanged event on mouse leave', () => { | ||
| const mockHover: { called: boolean; fn: ({ isHovered }: { isHovered: boolean }) => void } = { | ||
| called: false, | ||
| fn: ({ isHovered }: { isHovered: boolean }) => { | ||
| mockHover.called = true; | ||
| expect(isHovered).toBe(false); | ||
| }, | ||
| }; | ||
|
|
||
| const newProps = { ...props, hoverStateEnabled: true, onHoverChanged: mockHover.fn }; | ||
| // @ts-expect-error | ||
| render(<Card {...newProps} />, container); | ||
|
|
||
| const cardElement = container.querySelector(`.${CLASSES.card}`); | ||
| cardElement?.dispatchEvent(new MouseEvent('mouseleave')); | ||
|
|
||
| expect(mockHover.called).toBe(true); | ||
| }); | ||
|
|
||
| it('should apply correct minWidth, maxWidth, and width styles', () => { | ||
| const cardElement = container.querySelector('.dx-cardview-card'); | ||
| const style = cardElement?.getAttribute('style'); | ||
|
|
||
| expect(style).toContain('min-width: 300px'); | ||
| expect(style).toContain('max-width: 300px'); | ||
| expect(style).toContain('width: 300px'); | ||
| }); | ||
|
|
||
| it('should handle hoverStateEnabled prop correctly', () => { | ||
| const cardElement = container.querySelector('.dx-cardview-card'); | ||
| cardElement?.dispatchEvent(new MouseEvent('mouseenter')); | ||
|
|
||
| const classList = cardElement?.getAttribute('class') || ''; | ||
| expect(classList).toContain('dx-cardview-card-hover'); | ||
| }); | ||
|
|
||
| it('should render field template correctly', () => { | ||
| const fieldName = container.querySelector('.dx-cardview-field-name'); | ||
| const fieldValue = container.querySelector('.dx-cardview-field-value'); | ||
|
|
||
| expect(fieldName?.textContent).toBe('Field:'); | ||
| expect(fieldValue?.textContent).toBe('devextreme'); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.