-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modal): handle Observable values for modal/sidepanel labels
- Loading branch information
1 parent
6b79bec
commit e13fbd7
Showing
12 changed files
with
266 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { Observable } from 'rxjs'; | ||
|
||
export interface ILuModalContent<T = unknown> { | ||
title: string; | ||
title: string | Observable<string>; | ||
submitAction?: () => T | Observable<T>; | ||
submitLabel?: string; | ||
submitLabel?: string | Observable<string>; | ||
submitPalette?: string; | ||
submitDisabled?: boolean; | ||
submitCounter?: number; | ||
cancelLabel?: string; | ||
cancelLabel?: string | Observable<string>; | ||
} |
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,70 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { Component, Type } from '@angular/core'; | ||
import { By } from '@angular/platform-browser'; | ||
import { LuModalModule } from 'dist/ng/modal'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { ILuModalContent } from './modal.model'; | ||
import { LuModal } from './modal.service'; | ||
|
||
@Component({ | ||
selector: 'lu-test-modal', | ||
standalone: true, | ||
template: `Content` | ||
}) | ||
export class ModalContentComponent implements ILuModalContent { | ||
title = new BehaviorSubject('OriginalTitle'); | ||
} | ||
|
||
@Component({ | ||
selector: 'lu-test-opener', | ||
template: `Content` | ||
}) | ||
export class ModalOpenerComponent { | ||
constructor( | ||
public modal: LuModal, | ||
) { } | ||
} | ||
|
||
describe('LuModal', () => { | ||
let opener: ModalOpenerComponent; | ||
let fixture: ComponentFixture<ModalOpenerComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ModalOpenerComponent], | ||
imports: [LuModalModule], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ModalOpenerComponent); | ||
opener = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
function openModal<T>(type: Type<T>): T { | ||
opener.modal.open(type); | ||
return fixture.debugElement.parent.query(By.directive(type)).componentInstance; | ||
} | ||
|
||
function getModalTitle(): string { | ||
return fixture.debugElement.parent.query(By.css('.lu-modal-header-title')).nativeElement.innerHTML; | ||
} | ||
|
||
it('should update modal title when ILuModalContent\'s title emits a new value', () => { | ||
// Arrange | ||
const contentComponent = openModal(ModalContentComponent); | ||
fixture.detectChanges(); | ||
|
||
// Act | ||
const beforeTitle = getModalTitle(); | ||
|
||
contentComponent.title.next('UpdatedTitle'); | ||
fixture.detectChanges(); | ||
|
||
const afterTitle = getModalTitle(); | ||
|
||
// Assert | ||
expect(beforeTitle).toBe('OriginalTitle') | ||
expect(afterTitle).toBe('UpdatedTitle') | ||
}); | ||
}); |
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
Oops, something went wrong.