-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: save connection info, logout button (#285)
- Loading branch information
1 parent
2844db2
commit d6aa1cc
Showing
21 changed files
with
462 additions
and
5 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
15 changes: 15 additions & 0 deletions
15
src/app/components/editors/shared/modal-confirm/modal-confirm.component.html
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,15 @@ | ||
<div class="alert-box"> | ||
<div class="modal-header"> | ||
<h4 class="modal-title">{{ title }}</h4> | ||
<button type="button" class="close" aria-label="Close" (click)="onCancel()"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
{{ content }} | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-primary" (click)="onConfirm()" id="yes">Yes</button> | ||
<button type="button" class="btn btn-secondary" (click)="onCancel()" id="no">No</button> | ||
</div> | ||
</div> |
60 changes: 60 additions & 0 deletions
60
src/app/components/editors/shared/modal-confirm/modal-confirm.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,60 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { BsModalRef } from 'ngx-bootstrap'; | ||
import Spy = jasmine.Spy; | ||
import { ModalConfirmComponent } from './modal-confirm.component'; | ||
import { ModalConfirmModule } from './modal-confirm.module'; | ||
import { PageObject } from '../../../../test-utils/page-object'; | ||
|
||
class ModalConfirmComponentPage extends PageObject<ModalConfirmComponent> { | ||
get yesBtn() { return this.query<HTMLButtonElement>('#yes'); } | ||
get noBtn() { return this.query<HTMLButtonElement>('#no'); } | ||
} | ||
|
||
describe('ModalConfirmComponent', () => { | ||
let component: ModalConfirmComponent; | ||
let fixture: ComponentFixture<ModalConfirmComponent>; | ||
let hideSpy: Spy; | ||
let page: ModalConfirmComponentPage; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
ModalConfirmModule, | ||
], | ||
providers: [ | ||
BsModalRef, | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ModalConfirmComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
page = new ModalConfirmComponentPage(fixture); | ||
|
||
hideSpy = spyOn(TestBed.get(BsModalRef), 'hide'); | ||
}); | ||
|
||
it('onConfirm() should correctly hide the modal', () => { | ||
const nextSpy = spyOn(component.onClose, 'next'); | ||
|
||
page.yesBtn.click(); | ||
|
||
expect(nextSpy).toHaveBeenCalledWith(true); | ||
expect(nextSpy).toHaveBeenCalledTimes(1); | ||
expect(hideSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('onCancel() should correctly hide the modal', () => { | ||
const nextSpy = spyOn(component.onClose, 'next'); | ||
|
||
page.noBtn.click(); | ||
|
||
expect(nextSpy).toHaveBeenCalledWith(false); | ||
expect(nextSpy).toHaveBeenCalledTimes(1); | ||
expect(hideSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
}); |
30 changes: 30 additions & 0 deletions
30
src/app/components/editors/shared/modal-confirm/modal-confirm.component.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,30 @@ | ||
import { BsModalRef } from 'ngx-bootstrap/modal'; | ||
import { OnInit, Component } from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'app-modal-confirm', | ||
templateUrl: './modal-confirm.component.html', | ||
}) | ||
export class ModalConfirmComponent implements OnInit { | ||
|
||
public onClose: Subject <boolean>; | ||
title: string; | ||
content: string; | ||
|
||
constructor(private _bsModalRef: BsModalRef) {} | ||
|
||
public ngOnInit(): void { | ||
this.onClose = new Subject(); | ||
} | ||
|
||
public onConfirm(): void { | ||
this.onClose.next(true); | ||
this._bsModalRef.hide(); | ||
} | ||
|
||
public onCancel(): void { | ||
this.onClose.next(false); | ||
this._bsModalRef.hide(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/app/components/editors/shared/modal-confirm/modal-confirm.module.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,10 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { ModalModule } from 'ngx-bootstrap'; | ||
import { ModalConfirmComponent } from './modal-confirm.component'; | ||
|
||
@NgModule({ | ||
declarations: [ ModalConfirmComponent ], | ||
imports: [ ModalModule.forRoot() ], | ||
exports: [ ModalConfirmComponent ], | ||
}) | ||
export class ModalConfirmModule {} |
4 changes: 4 additions & 0 deletions
4
src/app/components/main-window/sidebar/logout-btn/logout-btn.component.html
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,4 @@ | ||
<button class="btn btn-sm btn-secondary" (click)="openModalConfirm()"> | ||
Logout | ||
<i class="fas fa-power-off"></i> | ||
</button> |
4 changes: 4 additions & 0 deletions
4
src/app/components/main-window/sidebar/logout-btn/logout-btn.component.scss
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,4 @@ | ||
button.btn-sm { | ||
font-size: 0.7rem; | ||
margin-top: 6px; | ||
} |
55 changes: 55 additions & 0 deletions
55
src/app/components/main-window/sidebar/logout-btn/logout-btn.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,55 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import Spy = jasmine.Spy; | ||
|
||
import { LogoutBtnComponent } from './logout-btn.component'; | ||
import { LocationService } from '../../../../services/location.service'; | ||
import { ModalModule, BsModalService } from 'ngx-bootstrap'; | ||
import { NgModule } from '@angular/core'; | ||
import { ModalConfirmComponent } from '../../../editors/shared/modal-confirm/modal-confirm.component'; | ||
|
||
@NgModule({ | ||
declarations: [ ModalConfirmComponent ], | ||
entryComponents: [ ModalConfirmComponent ], | ||
imports: [ ], | ||
}) | ||
class TestModule {} | ||
|
||
describe('LogoutBtnComponent', () => { | ||
let component: LogoutBtnComponent; | ||
let fixture: ComponentFixture<LogoutBtnComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ LogoutBtnComponent ], | ||
imports: [ | ||
ModalModule.forRoot(), | ||
TestModule, | ||
], | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(LogoutBtnComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('openModalConfirm() should correctly work', () => { | ||
const showSpy = spyOn(TestBed.get(BsModalService), 'show').and.callThrough(); | ||
const logoutSpy = spyOn(component, 'logout'); | ||
|
||
component.openModalConfirm(); | ||
expect(showSpy).toHaveBeenCalledTimes(1); | ||
|
||
component['modalRef'].content.onCancel(); | ||
expect(logoutSpy).toHaveBeenCalledTimes(0); | ||
|
||
component['modalRef'].content.onConfirm(); | ||
expect(logoutSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('logout() should correctly work', () => { | ||
const locationServiceSpy: Spy = spyOn(TestBed.get(LocationService), 'reload'); | ||
component.logout(); | ||
expect(locationServiceSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
src/app/components/main-window/sidebar/logout-btn/logout-btn.component.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,44 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
import { ModalConfirmComponent } from '../../../editors/shared/modal-confirm/modal-confirm.component'; | ||
import { BsModalService, BsModalRef } from 'ngx-bootstrap'; | ||
import { LocationService } from '../../../../services/location.service'; | ||
import { SubscriptionHandler } from '../../../../utils/subscription-handler/subscription-handler'; | ||
|
||
@Component({ | ||
selector: 'app-logout-btn', | ||
templateUrl: './logout-btn.component.html', | ||
styleUrls: ['./logout-btn.component.scss'], | ||
}) | ||
export class LogoutBtnComponent extends SubscriptionHandler { | ||
|
||
public modalRef: BsModalRef; | ||
constructor( | ||
private modalService: BsModalService, | ||
private locationService: LocationService | ||
) { | ||
super(); | ||
} | ||
|
||
openModalConfirm() { | ||
const initialState = { | ||
title: 'Logout', | ||
content: 'Are you sure you want to logout?' | ||
}; | ||
|
||
this.modalRef = this.modalService.show(ModalConfirmComponent, { initialState }); | ||
|
||
this.subscriptions.push( | ||
this.modalRef.content.onClose.subscribe(result => { | ||
if (result) { | ||
this.logout(); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
logout() { | ||
this.locationService.reload(); | ||
} | ||
|
||
} |
Oops, something went wrong.