-
Notifications
You must be signed in to change notification settings - Fork 667
CardView: fix selection (throw error if needed) (oqSw9T3c) #29873
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
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa17d31
CardView: fix selection (throw error if needed) (oqSw9T3c)
haksur 67ffef8
CardView: fix selection (throw error if needed) (oqSw9T3c) (review co…
haksur 8f4cbc9
CardView: editing operations, add/edit/delete (throw error if needed)…
haksur 79b1ff7
CardView: fix selection (throw error if needed) (oqSw9T3c) (review co…
haksur 3f0e7c6
Update packages/devextreme/js/__internal/grids/new/grid_core/selectio…
haksur 8c432c7
Update packages/devextreme/js/__internal/grids/new/grid_core/selectio…
haksur 84fd185
Update packages/devextreme/js/__internal/grids/new/grid_core/selectio…
haksur 8288369
CardView: fix selection (throw error if needed) (oqSw9T3c) (review co…
haksur 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
23 changes: 23 additions & 0 deletions
23
packages/devextreme/js/__internal/grids/new/grid_core/options_validation/controller.ts
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,23 @@ | ||
| import { isDefined } from '@js/core/utils/type'; | ||
| import { DataController } from '@ts/grids/new/grid_core/data_controller/index'; | ||
|
|
||
| import { throwError } from './utils'; | ||
|
|
||
| export class OptionsValidationController { | ||
| public static dependencies = [ | ||
| DataController, | ||
| ] as const; | ||
|
|
||
| constructor( | ||
| private readonly dataController: DataController, | ||
| ) { | ||
| } | ||
|
|
||
| public validateKeyExpr(): void { | ||
| const keyExpr = this.dataController.dataSource.peek().key(); | ||
|
|
||
| if (!isDefined(keyExpr)) { | ||
| throwError('E1042', 'CardView'); | ||
| } | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/devextreme/js/__internal/grids/new/grid_core/options_validation/index.ts
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 @@ | ||
| export { OptionsValidationController } from './controller'; |
5 changes: 5 additions & 0 deletions
5
packages/devextreme/js/__internal/grids/new/grid_core/options_validation/utils.ts
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,5 @@ | ||
| import errors from '@js/ui/widget/ui.errors'; | ||
|
|
||
| export const throwError = (errorCode?: string, message?: string): void => { | ||
| throw errors.Error(errorCode, message); | ||
| }; |
174 changes: 174 additions & 0 deletions
174
...ges/devextreme/js/__internal/grids/new/grid_core/selection/controller.integration.test.ts
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,174 @@ | ||
| /* eslint-disable spellcheck/spell-checker, @stylistic/max-len */ | ||
| import { | ||
| afterEach, beforeEach, describe, expect, it, jest, | ||
| } from '@jest/globals'; | ||
| import $ from '@js/core/renderer'; | ||
| import CardView from '@ts/grids/new/card_view/widget'; | ||
| import type { Options as GridCoreOptions } from '@ts/grids/new/grid_core/options'; | ||
| import { throwError } from '@ts/grids/new/grid_core/options_validation/utils'; | ||
| import { rerender } from 'inferno'; | ||
|
|
||
| const SELECTORS = { | ||
| cardView: '.dx-cardview', | ||
| card: '.dx-cardview-card', | ||
| cardCheckbox: '.dx-checkbox-container', | ||
| selectAllButton: '[aria-label="Select all"]', | ||
| }; | ||
|
|
||
| const setup = (options: GridCoreOptions = {}): CardView => { | ||
| const container = document.createElement('div'); | ||
| const { body } = document; | ||
| body.append(container); | ||
|
|
||
| const cardView = new CardView(container, options); | ||
| rerender(); | ||
| return cardView; | ||
| }; | ||
|
|
||
| const getCardElements = (): NodeListOf<Element> => document.querySelectorAll(SELECTORS.card); | ||
|
|
||
| const getCardCheckboxes = (): NodeListOf<Element> => document.querySelectorAll(SELECTORS.cardCheckbox); | ||
|
|
||
| const getSelectAllButton = (): Element | null => document.querySelector(SELECTORS.selectAllButton); | ||
|
|
||
| const checkError = (): void => expect(throwError).toHaveBeenCalledWith('E1042', 'CardView'); | ||
|
|
||
| jest.mock('@ts/grids/new/grid_core/options_validation/utils', () => ({ | ||
| throwError: jest.fn().mockImplementation(() => ({})), | ||
| })); | ||
|
|
||
| describe('when keyExpr is missing', () => { | ||
| afterEach(() => { | ||
| const cardView = document.querySelector(SELECTORS.cardView); | ||
| // @ts-expect-error bad typed renderer | ||
| $(cardView ?? undefined as any)?.dxCardView('dispose'); | ||
| document.body.innerHTML = ''; | ||
| }); | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
| describe('selection mode single', () => { | ||
| it('shouldn\'t throw E1042 error if keyExpr is missing and selection', () => { | ||
haksur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setup({ | ||
| dataSource: [{ value: 'test1' }, { value: 'test2' }], | ||
| selection: { | ||
| mode: 'single', | ||
| }, | ||
| }); | ||
|
|
||
| const cardElements = getCardElements(); | ||
| expect(cardElements.length).toEqual(2); | ||
| }); | ||
|
|
||
| it('should throw E1042 error on card click selection', () => { | ||
| setup({ | ||
| dataSource: [{ value: 'test1' }, { value: 'test2' }], | ||
| selection: { | ||
| mode: 'single', | ||
| }, | ||
| }); | ||
|
|
||
| const cardElements = getCardElements(); | ||
| cardElements[0].dispatchEvent(new MouseEvent('click')); | ||
|
|
||
| checkError(); | ||
| }); | ||
|
|
||
| it('should throw E1042 error on initial selectedCardKeys', () => { | ||
| setup({ | ||
| dataSource: [{ value: 'test1' }, { value: 'test2' }], | ||
| selection: { | ||
| mode: 'single', | ||
| }, | ||
| selectedCardKeys: [0], | ||
| }); | ||
|
|
||
| checkError(); | ||
| }); | ||
|
|
||
| it('should throw E1042 error on runtime selectedCardKeys update', () => { | ||
| const cardView = setup({ | ||
| dataSource: [{ value: 'test1' }, { value: 'test2' }], | ||
| selection: { | ||
| mode: 'single', | ||
| }, | ||
| }); | ||
|
|
||
| cardView.instance().option('selectedCardKeys', [1]); | ||
|
|
||
| checkError(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('selection mode multiple', () => { | ||
| it('shouldn\'t throw E1042 error if keyExpr is missing and selection', () => { | ||
haksur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setup({ | ||
| dataSource: [{ value: 'test1' }, { value: 'test2' }], | ||
| selection: { | ||
| mode: 'multiple', | ||
| }, | ||
| }); | ||
|
|
||
| const cardElements = getCardElements(); | ||
| expect(cardElements.length).toEqual(2); | ||
| }); | ||
|
|
||
| it('should throw E1042 error on checkbox click selection', () => { | ||
| setup({ | ||
| dataSource: [{ value: 'test1' }, { value: 'test2' }], | ||
| selection: { | ||
| mode: 'multiple', | ||
| showCheckBoxesMode: 'always', | ||
| }, | ||
| }); | ||
|
|
||
| const cardCheckboxes = getCardCheckboxes(); | ||
| cardCheckboxes[0].dispatchEvent(new MouseEvent('click', { bubbles: true })); | ||
|
|
||
| checkError(); | ||
| }); | ||
|
|
||
| it('should throw E1042 error on selectAll toolbar button click', () => { | ||
| setup({ | ||
| dataSource: [{ value: 'test1' }, { value: 'test2' }], | ||
| selection: { | ||
| mode: 'multiple', | ||
| showCheckBoxesMode: 'always', | ||
| allowSelectAll: true, | ||
| }, | ||
| }); | ||
|
|
||
| const selectAllButton = getSelectAllButton(); | ||
| selectAllButton?.dispatchEvent(new MouseEvent('click')); | ||
|
|
||
| checkError(); | ||
| }); | ||
|
|
||
| it('should throw E1042 error on initial selectedCardKeys', () => { | ||
| setup({ | ||
| dataSource: [{ value: 'test1' }, { value: 'test2' }], | ||
| selection: { | ||
| mode: 'multiple', | ||
| showCheckBoxesMode: 'always', | ||
| }, | ||
| selectedCardKeys: [0, 1], | ||
| }); | ||
|
|
||
| checkError(); | ||
| }); | ||
|
|
||
| it('should throw E1042 error on runtime selectedCardKeys update', () => { | ||
| const cardView = setup({ | ||
| dataSource: [{ value: 'test1' }, { value: 'test2' }], | ||
| selection: { | ||
| mode: 'multiple', | ||
| showCheckBoxesMode: 'always', | ||
| }, | ||
| }); | ||
|
|
||
| cardView.instance().option('selectedCardKeys', [1]); | ||
|
|
||
| checkError(); | ||
| }); | ||
| }); | ||
| }); | ||
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
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.