Skip to content

Commit 928a274

Browse files
author
Salma Alam-Naylor
committed
Move similarModes functionality to a pipe to make the component rerender automatically with home-index
1 parent 5aa16d5 commit 928a274

File tree

10 files changed

+202
-71
lines changed

10 files changed

+202
-71
lines changed

apps/fretonator-web/src/app/common/fret-map/fret-map.service.spec.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
cIonianChordMap,
1313
cIonianFretMappings,
1414
cIonianMode,
15+
cIonianSimilarModes,
1516
cMajorPentatonicChordMap,
1617
cMinorPentatonicChordMap,
1718
cPhrygianMode,
@@ -1363,43 +1364,6 @@ describe('FretMapService:getSimilarModes', () => {
13631364
it('returns correctly for an input of c natural ionian', () => {
13641365
const result = service.getSimilarModes(cIonianMode, Mode.ionian);
13651366

1366-
expect(result).toBe([
1367-
{
1368-
noteDisplayName: 'D',
1369-
note: 'd',
1370-
mode: 'dorian',
1371-
noteExtender: 'natural'
1372-
},
1373-
{
1374-
noteDisplayName: 'E',
1375-
note: 'e',
1376-
mode: 'phrygian',
1377-
noteExtender: 'natural'
1378-
},
1379-
{
1380-
noteDisplayName: 'F',
1381-
note: 'f',
1382-
mode: 'lydian',
1383-
noteExtender: 'natural'
1384-
},
1385-
{
1386-
noteDisplayName: 'G',
1387-
note: 'g',
1388-
mode: 'mixolydian',
1389-
noteExtender: 'natural'
1390-
},
1391-
{
1392-
noteDisplayName: 'A',
1393-
note: 'a',
1394-
mode: 'aolian',
1395-
noteExtender: 'natural'
1396-
},
1397-
{
1398-
noteDisplayName: 'B',
1399-
note: 'b',
1400-
mode: 'locrian',
1401-
noteExtender: 'natural'
1402-
}
1403-
]);
1367+
expect(result).toEqual(cIonianSimilarModes);
14041368
});
14051369
});

apps/fretonator-web/src/app/common/fret-map/fret-map.service.testConstants.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,3 +1209,42 @@ export const cIonianChordMap = [
12091209
type: ChordType.diminished,
12101210
},
12111211
]
1212+
1213+
export const cIonianSimilarModes = [
1214+
{
1215+
noteDisplayName: 'D',
1216+
note: 'd',
1217+
mode: 'dorian',
1218+
noteExtender: 'natural'
1219+
},
1220+
{
1221+
noteDisplayName: 'E',
1222+
note: 'e',
1223+
mode: 'phrygian',
1224+
noteExtender: 'natural'
1225+
},
1226+
{
1227+
noteDisplayName: 'F',
1228+
note: 'f',
1229+
mode: 'lydian',
1230+
noteExtender: 'natural'
1231+
},
1232+
{
1233+
noteDisplayName: 'G',
1234+
note: 'g',
1235+
mode: 'mixolydian',
1236+
noteExtender: 'natural'
1237+
},
1238+
{
1239+
noteDisplayName: 'A',
1240+
note: 'a',
1241+
mode: 'aolian',
1242+
noteExtender: 'natural'
1243+
},
1244+
{
1245+
noteDisplayName: 'B',
1246+
note: 'b',
1247+
mode: 'locrian',
1248+
noteExtender: 'natural'
1249+
}
1250+
]

apps/fretonator-web/src/app/common/fretonator/fretonator.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ <h4 class="fretonator__playCta">
8787
<app-chord-map [chordMap]="chordMap"></app-chord-map>
8888

8989
<app-similar-modes [modeDisplayString]="modeDisplayString"
90-
[modeMap]="modeMap"
91-
[mode]="mode"></app-similar-modes>
90+
[similarModes]="modeMap | getSimilarModes : mode">
91+
92+
</app-similar-modes>
9293

9394
</div>

apps/fretonator-web/src/app/common/fretonator/fretonator.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import { ScaleMapModule } from './scale-map/scale-map.module';
88
import { IsTheoreticalScalePipe } from './is-theoretical-scale.pipe';
99
import { SpeakerModule } from '../svgs/speaker/speaker.module';
1010
import { SimilarModesModule } from './similar-modes/similar-modes.module';
11+
import { GetSimilarModesPipe } from './get-similar-modes.pipe';
1112

1213
@NgModule({
1314
declarations: [
1415
FretonatorComponent,
1516
GetFretFromFretMapPipe,
1617
IsTheoreticalScalePipe,
18+
GetSimilarModesPipe,
1719
],
1820
imports: [
1921
CommonModule,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { GetSimilarModesPipe } from './get-similar-modes.pipe';
2+
import { TestBed } from '@angular/core/testing';
3+
import { FretMapService } from '../fret-map/fret-map.service';
4+
import { Mode } from '../../util/types';
5+
import { cIonianMode } from '../fret-map/fret-map.service.testConstants';
6+
7+
describe('GetSimilarModesPipe', () => {
8+
9+
let pipe: GetSimilarModesPipe;
10+
11+
beforeEach(() => {
12+
const service = TestBed.inject(FretMapService);
13+
pipe = new GetSimilarModesPipe(service);
14+
});
15+
16+
it('create an instance', () => {
17+
expect(pipe).toBeTruthy();
18+
});
19+
20+
21+
it('calls GenerateFretMapService.getSimilarModes', () => {
22+
const spy = spyOn(pipe.generateFretMapService, 'getSimilarModes');
23+
24+
pipe.transform(cIonianMode, 'ionian' as Mode);
25+
expect(spy).toHaveBeenCalledWith(cIonianMode, 'ionian');
26+
});
27+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
import { FretMapService } from '../fret-map/fret-map.service';
3+
import { Mode, ModeMap, SimilarModes } from '../../util/types';
4+
5+
@Pipe({
6+
name: 'getSimilarModes'
7+
})
8+
export class GetSimilarModesPipe implements PipeTransform {
9+
10+
constructor(public generateFretMapService: FretMapService) {}
11+
12+
transform(modeMap: ModeMap, mode: Mode): SimilarModes {
13+
return this.generateFretMapService.getSimilarModes(modeMap, mode);
14+
}
15+
16+
}

apps/fretonator-web/src/app/common/fretonator/similar-modes/similar-modes.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ <h4 class="similarModes__title">Did you know?</h4>
88
[note]="mode.note"
99
[noteExtender]="mode.noteExtender"
1010
[mode]="mode.mode"
11-
selectedColor="default">{{mode.displayName}} {{mode.mode | titlecase}}</app-chip>
11+
selectedColor="default">{{mode.noteDisplayName}} {{mode.mode | titlecase}}</app-chip>
1212
</app-chips>
1313
</div>

apps/fretonator-web/src/app/common/fretonator/similar-modes/similar-modes.component.spec.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { SimilarModesComponent } from './similar-modes.component';
4+
import { Component } from '@angular/core';
5+
import { SimilarModesModule } from './similar-modes.module';
46

57
describe('SimilarModesComponent', () => {
6-
let component: SimilarModesComponent;
7-
let fixture: ComponentFixture<SimilarModesComponent>;
8+
9+
@Component({
10+
selector: 'app-similar-modes-spec',
11+
template: `
12+
<app-similar-modes>
13+
</app-similar-modes>
14+
`
15+
})
16+
class SimilarModesComponentSpec {
17+
}
18+
19+
let component: SimilarModesComponentSpec;
20+
let fixture: ComponentFixture<SimilarModesComponentSpec>;
821

922
beforeEach(async(() => {
1023
TestBed.configureTestingModule({
11-
declarations: [ SimilarModesComponent ]
24+
declarations: [SimilarModesComponentSpec],
25+
imports: [ SimilarModesModule ]
1226
})
13-
.compileComponents();
27+
.compileComponents();
1428
}));
1529

1630
beforeEach(() => {
17-
fixture = TestBed.createComponent(SimilarModesComponent);
31+
fixture = TestBed.createComponent(SimilarModesComponentSpec);
1832
component = fixture.componentInstance;
1933
fixture.detectChanges();
2034
});
Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
1-
import { Component, Input, OnInit } from '@angular/core';
2-
import { Mode, ModeMap, SimilarModes } from '../../../util/types';
3-
import { FretMapService } from '../../fret-map/fret-map.service';
4-
import { ActivatedRoute } from '@angular/router';
1+
import { Component, Input } from '@angular/core';
2+
import { SimilarModes } from '../../../util/types';
53

64
@Component({
75
selector: 'app-similar-modes',
86
templateUrl: './similar-modes.component.html',
97
styleUrls: ['./similar-modes.component.scss']
108
})
11-
export class SimilarModesComponent implements OnInit {
12-
@Input() modeMap: ModeMap;
13-
@Input() mode: Mode;
9+
export class SimilarModesComponent {
10+
@Input() similarModes: SimilarModes;
1411
@Input() modeDisplayString: string;
15-
similarModes: SimilarModes = [];
16-
17-
constructor(private activatedRoute: ActivatedRoute,
18-
public fretMapService: FretMapService) {
19-
}
20-
21-
ngOnInit(): void {
22-
this.activatedRoute.params.subscribe(() => this.onRouteChange());
23-
this.getSimilarModes();
24-
}
25-
26-
onRouteChange() {
27-
this.getSimilarModes();
28-
}
29-
30-
getSimilarModes() {
31-
this.similarModes = this.fretMapService.getSimilarModes(this.modeMap, this.mode);
32-
}
3312
}

apps/fretonator-web/src/app/pages/home/home-index/__snapshots__/home-index.component.spec.ts.snap

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,95 @@ exports[`HomeIndexComponent should create 1`] = `
13941394
</div>
13951395
</div>
13961396
</app-chord-map>
1397+
<app-similar-modes>
1398+
<div
1399+
class="similarModes"
1400+
>
1401+
<h4
1402+
class="similarModes__title"
1403+
>
1404+
Did you know?
1405+
</h4>
1406+
<p
1407+
class="similarModes__copy"
1408+
>
1409+
If you know the patterns of C Ionian (Major), you'll know the modes below. Just shift your fingers along the fret board.
1410+
</p>
1411+
<app-chips>
1412+
<div
1413+
class="chips"
1414+
>
1415+
1416+
<app-chip
1417+
selectedcolor="default"
1418+
>
1419+
<a
1420+
aria-label="D Dorian"
1421+
class="chip"
1422+
href="/d/natural/dorian"
1423+
>
1424+
D Dorian
1425+
</a>
1426+
</app-chip>
1427+
<app-chip
1428+
selectedcolor="default"
1429+
>
1430+
<a
1431+
aria-label="E Phrygian"
1432+
class="chip"
1433+
href="/e/natural/phrygian"
1434+
>
1435+
E Phrygian
1436+
</a>
1437+
</app-chip>
1438+
<app-chip
1439+
selectedcolor="default"
1440+
>
1441+
<a
1442+
aria-label="F Lydian"
1443+
class="chip"
1444+
href="/f/natural/lydian"
1445+
>
1446+
F Lydian
1447+
</a>
1448+
</app-chip>
1449+
<app-chip
1450+
selectedcolor="default"
1451+
>
1452+
<a
1453+
aria-label="G Mixolydian"
1454+
class="chip"
1455+
href="/g/natural/mixolydian"
1456+
>
1457+
G Mixolydian
1458+
</a>
1459+
</app-chip>
1460+
<app-chip
1461+
selectedcolor="default"
1462+
>
1463+
<a
1464+
aria-label="A Aolian (Minor)"
1465+
class="chip"
1466+
href="/a/natural/aolian"
1467+
>
1468+
A Aolian
1469+
</a>
1470+
</app-chip>
1471+
<app-chip
1472+
selectedcolor="default"
1473+
>
1474+
<a
1475+
aria-label="B Locrian"
1476+
class="chip"
1477+
href="/b/natural/locrian"
1478+
>
1479+
B Locrian
1480+
</a>
1481+
</app-chip>
1482+
</div>
1483+
</app-chips>
1484+
</div>
1485+
</app-similar-modes>
13971486
</div>
13981487
</app-fretonator>
13991488

0 commit comments

Comments
 (0)