-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1545 from musicEnfanthen/feature/refactor_sheet_v…
…iewer_nav refactor(edition): move sheet viewer nav into separate component
- Loading branch information
Showing
9 changed files
with
275 additions
and
103 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...svg-sheet-viewer/edition-svg-sheet-viewer-nav/edition-svg-sheet-viewer-nav.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,8 @@ | ||
<div class="awg-edition-svg-sheet-viewer-nav"> | ||
<div class="prev" (click)="browseSvgSheet(-1)"> | ||
<span>❮</span> | ||
</div> | ||
<div class="next" (click)="browseSvgSheet(1)"> | ||
<span>❯</span> | ||
</div> | ||
</div> |
36 changes: 36 additions & 0 deletions
36
...svg-sheet-viewer/edition-svg-sheet-viewer-nav/edition-svg-sheet-viewer-nav.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,36 @@ | ||
@import '/src/assets/themes/scss/shared'; | ||
|
||
.awg-edition-svg-sheet-viewer-nav { | ||
> .prev, | ||
.next { | ||
cursor: pointer; | ||
position: absolute; | ||
height: 100%; | ||
top: 0; | ||
width: auto; | ||
padding: 8px; | ||
user-select: none; | ||
|
||
&:hover { | ||
background-color: #dddddd; | ||
} | ||
|
||
span { | ||
position: relative; | ||
top: 45%; | ||
font-weight: bold; | ||
font-size: 18px; | ||
transition: 0.6s ease; | ||
color: $link-color; | ||
} | ||
} | ||
|
||
> .prev { | ||
border-right: 1px solid #dddddd; | ||
} | ||
|
||
> .next { | ||
right: 0; | ||
border-left: 1px solid #dddddd; | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
...-sheet-viewer/edition-svg-sheet-viewer-nav/edition-svg-sheet-viewer-nav.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,155 @@ | ||
import { DOCUMENT } from '@angular/common'; | ||
import { DebugElement } from '@angular/core'; | ||
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing'; | ||
|
||
import Spy = jasmine.Spy; | ||
|
||
import { cleanStylesFromDOM } from '@testing/clean-up-helper'; | ||
import { clickAndAwaitChanges } from '@testing/click-helper'; | ||
import { expectSpyCall, expectToBe, getAndExpectDebugElementByCss } from '@testing/expect-helper'; | ||
|
||
import { EditionSvgSheetViewerNavComponent } from './edition-svg-sheet-viewer-nav.component'; | ||
|
||
describe('EditionSvgSheetViewerNavComponent', () => { | ||
let component: EditionSvgSheetViewerNavComponent; | ||
let fixture: ComponentFixture<EditionSvgSheetViewerNavComponent>; | ||
let compDe: DebugElement; | ||
|
||
let mockDocument: Document; | ||
|
||
let browseSvgSheetSpy: Spy; | ||
let browseSvgSheetRequestEmitSpy: Spy; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [EditionSvgSheetViewerNavComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(EditionSvgSheetViewerNavComponent); | ||
component = fixture.componentInstance; | ||
compDe = fixture.debugElement; | ||
|
||
mockDocument = TestBed.inject(DOCUMENT); | ||
|
||
// Spies on component functions | ||
// `.and.callThrough` will track the spy down the nested describes, see | ||
// https://jasmine.github.io/2.0/introduction.html#section-Spies:_%3Ccode%3Eand.callThrough%3C/code%3E | ||
browseSvgSheetSpy = spyOn(component, 'browseSvgSheet').and.callThrough(); | ||
browseSvgSheetRequestEmitSpy = spyOn(component.browseSvgSheetRequest, 'emit').and.callThrough(); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanStylesFromDOM(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
describe('BEFORE initial data binding', () => { | ||
describe('VIEW', () => { | ||
it('... should contain one div.awg-edition-svg-sheet-viewer-nav', () => { | ||
getAndExpectDebugElementByCss(compDe, 'div.awg-edition-svg-sheet-viewer-nav', 1, 1); | ||
}); | ||
|
||
it('... should contain 1 div.prev and 1 div.next in div.awg-edition-svg-sheet-viewer-nav', () => { | ||
getAndExpectDebugElementByCss(compDe, 'div.awg-edition-svg-sheet-viewer-nav > div', 2, 2); | ||
|
||
const sheetViewerNavDe = getAndExpectDebugElementByCss( | ||
compDe, | ||
'div.awg-edition-svg-sheet-viewer-nav', | ||
1, | ||
1 | ||
); | ||
|
||
getAndExpectDebugElementByCss(sheetViewerNavDe[0], 'div.prev', 1, 1); | ||
getAndExpectDebugElementByCss(sheetViewerNavDe[0], 'div.next', 1, 1); | ||
}); | ||
|
||
it('... should display left arrow in div.prev', () => { | ||
const divPrevDe = getAndExpectDebugElementByCss(compDe, 'div.prev', 1, 1); | ||
|
||
const spanDe = getAndExpectDebugElementByCss(divPrevDe[0], 'span', 1, 1); | ||
const spanEl = spanDe[0].nativeElement; | ||
|
||
// Process HTML expression of expected text content | ||
const expectedHtmlTextContent = mockDocument.createElement('span'); | ||
expectedHtmlTextContent.innerHTML = '❮'; | ||
|
||
expectToBe(spanEl.textContent, expectedHtmlTextContent.textContent); | ||
}); | ||
|
||
it('... should display right arrow in div.next', () => { | ||
const divNextDe = getAndExpectDebugElementByCss(compDe, 'div.next', 1, 1); | ||
|
||
const spanDe = getAndExpectDebugElementByCss(divNextDe[0], 'span', 1, 1); | ||
const spanEl = spanDe[0].nativeElement; | ||
|
||
// Process HTML expression of expected text content | ||
const expectedHtmlTextContent = mockDocument.createElement('span'); | ||
expectedHtmlTextContent.innerHTML = '❯'; | ||
|
||
expectToBe(spanEl.textContent, expectedHtmlTextContent.textContent); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('AFTER initial data binding', () => { | ||
beforeEach(() => { | ||
// Trigger initial data binding | ||
fixture.detectChanges(); | ||
}); | ||
|
||
describe('#browseSvgSheet()', () => { | ||
it('... should have a method `browseSvgSheet` ', () => { | ||
expect(component.browseSvgSheet).toBeDefined(); | ||
}); | ||
|
||
it('... should trigger on click on div.prev', fakeAsync(() => { | ||
const divPrevDe = getAndExpectDebugElementByCss(compDe, 'div.prev', 1, 1); | ||
const expectedDirection = -1; | ||
|
||
// Trigger click with click helper & wait for changes | ||
clickAndAwaitChanges(divPrevDe[0], fixture); | ||
|
||
expectSpyCall(browseSvgSheetRequestEmitSpy, 1, expectedDirection); | ||
})); | ||
|
||
it('... should trigger on click on div.next', fakeAsync(() => { | ||
const divNextDe = getAndExpectDebugElementByCss(compDe, 'div.next', 1, 1); | ||
const expectedDirection = 1; | ||
|
||
// Trigger click with click helper & wait for changes | ||
clickAndAwaitChanges(divNextDe[0], fixture); | ||
|
||
expectSpyCall(browseSvgSheetRequestEmitSpy, 1, expectedDirection); | ||
})); | ||
|
||
it('... should not emit anything if no direction is provided', () => { | ||
const expectedDirection = undefined; | ||
component.browseSvgSheet(expectedDirection); | ||
|
||
expectSpyCall(browseSvgSheetRequestEmitSpy, 0, expectedDirection); | ||
}); | ||
|
||
it('... should emit a given direction', () => { | ||
const expectedDirection = 1; | ||
component.browseSvgSheet(expectedDirection); | ||
|
||
expectSpyCall(browseSvgSheetRequestEmitSpy, 1, expectedDirection); | ||
}); | ||
|
||
it('... should emit the correct direction', () => { | ||
let expectedDirection = 1; | ||
component.browseSvgSheet(expectedDirection); | ||
|
||
expectSpyCall(browseSvgSheetRequestEmitSpy, 1, expectedDirection); | ||
|
||
expectedDirection = -1; | ||
component.browseSvgSheet(expectedDirection); | ||
|
||
expectSpyCall(browseSvgSheetRequestEmitSpy, 2, expectedDirection); | ||
}); | ||
}); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
...n-svg-sheet-viewer/edition-svg-sheet-viewer-nav/edition-svg-sheet-viewer-nav.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,39 @@ | ||
import { ChangeDetectionStrategy, Component, EventEmitter, Output } from '@angular/core'; | ||
|
||
/** | ||
* The EditionSvgSheetViewerNav component. | ||
* | ||
* It contains the navigation panel for the edition svg sheet viewer. | ||
*/ | ||
@Component({ | ||
selector: 'awg-edition-svg-sheet-viewer-nav', | ||
templateUrl: './edition-svg-sheet-viewer-nav.component.html', | ||
styleUrl: './edition-svg-sheet-viewer-nav.component.scss', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class EditionSvgSheetViewerNavComponent { | ||
/** | ||
* Output variable: browseSvgSheetRequest. | ||
* | ||
* It keeps an event emitter for the next or pevious index of an svg sheet. | ||
*/ | ||
@Output() | ||
browseSvgSheetRequest: EventEmitter<number> = new EventEmitter(); | ||
|
||
/** | ||
* Public method: browseSvgSheet. | ||
* | ||
* It emits a given direction to the {@link browseSvgSheetRequest} | ||
* to browse to the previous or next sheet of the selected svg sheet. | ||
* | ||
* @param {number} direction A number indicating the direction of navigation. -1 for previous and 1 for next. | ||
* | ||
* @returns {void} Emits the direction. | ||
*/ | ||
browseSvgSheet(direction: number): void { | ||
if (!direction) { | ||
return; | ||
} | ||
this.browseSvgSheetRequest.emit(direction); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...on-sheets/edition-accolade/edition-svg-sheet-viewer/edition-svg-sheet-viewer-nav/index.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 @@ | ||
export * from './edition-svg-sheet-viewer-nav.component'; |
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.