-
Notifications
You must be signed in to change notification settings - Fork 160
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
Prevent valueChanges event when patchValue method is used with emitEvent=false #712
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5813c4b
Prevent option change event firing when changes occur in component
anna-zhernovkova 3a2ab2e
Update event lockers
anna-zhernovkova 4d6026a
Fix typo
anna-zhernovkova 85aad24
Add test for bound options
anna-zhernovkova 57a08c6
Simplify lockers
anna-zhernovkova ed8f2ed
Refactor test
anna-zhernovkova 5220137
Prevent option change event firing when nested option was changed
anna-zhernovkova 8747f65
Move event locker to writeValue method
anna-zhernovkova 8bca0b9
Rework test
anna-zhernovkova 9cae97f
Fix typo
anna-zhernovkova 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* tslint:disable:component-selector */ | ||
|
||
import { | ||
Component, | ||
ViewChildren, | ||
QueryList | ||
} from '@angular/core'; | ||
|
||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import DxAccordion from 'devextreme/ui/accordion'; | ||
|
||
import { | ||
DxAccordionModule, | ||
DxAccordionComponent | ||
} from '../../../dist'; | ||
|
||
@Component({ | ||
selector: 'test-container-component', | ||
template: '' | ||
}) | ||
class TestContainerComponent { | ||
items = [{ id: 1, name: 'name1' }, { id: 2, name: 'name2' }]; | ||
selectedItem = this.items[0]; | ||
selectedIndex = 0; | ||
|
||
@ViewChildren(DxAccordionComponent) innerWidgets: QueryList<DxAccordionComponent>; | ||
} | ||
|
||
describe('DxAccordion', () => { | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule( | ||
{ | ||
declarations: [TestContainerComponent], | ||
imports: [DxAccordionModule] | ||
}); | ||
}); | ||
|
||
function getWidget(fixture) { | ||
let widgetElement = fixture.nativeElement.querySelector('.dx-accordion') || fixture.nativeElement; | ||
return DxAccordion['getInstance'](widgetElement) as any; | ||
} | ||
|
||
it('should change bound options', () => { | ||
TestBed.overrideComponent(TestContainerComponent, { | ||
set: { | ||
template: ` | ||
<dx-accordion [items]="items" [(selectedIndex)]="selectedIndex" [(selectedItem)]="selectedItem"> | ||
</dx-accordion> | ||
` | ||
} | ||
}); | ||
|
||
let fixture = TestBed.createComponent(TestContainerComponent); | ||
fixture.detectChanges(); | ||
|
||
let accordion = fixture.componentInstance; | ||
let instance = getWidget(fixture); | ||
|
||
expect(instance.option('selectedIndex')).toBe(0); | ||
expect(instance.option('selectedItem')).toBe(accordion.items[0]); | ||
expect(accordion.selectedIndex).toBe(0); | ||
expect(accordion.selectedItem).toBe(accordion.items[0]); | ||
|
||
accordion.selectedIndex = 1; | ||
fixture.detectChanges(); | ||
|
||
expect(instance.option('selectedIndex')).toBe(1); | ||
expect(instance.option('selectedItem')).toBe(accordion.items[1]); | ||
expect(accordion.selectedIndex).toBe(1); | ||
expect(accordion.selectedItem).toBe(accordion.items[1]); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to have an array here? It seems that it's impossible to have several locked events simultaneously
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the case, where we have two events in the array, but it's checked in the correct order. So, we can get rid of array here.