From de1f891e1b6617c423a3c676d0db6a1d37cc0196 Mon Sep 17 00:00:00 2001 From: hakimio Date: Mon, 14 Jan 2019 16:08:51 +0100 Subject: [PATCH] fix(ng-chartist): corrected method visibility in chartist component. --- .../src/lib/chartist.component.spec.ts | 30 +++++++++---------- .../ng-chartist/src/lib/chartist.component.ts | 30 ++++++++++--------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/projects/ng-chartist/src/lib/chartist.component.spec.ts b/projects/ng-chartist/src/lib/chartist.component.spec.ts index 4edd1f4d..1414e0e3 100644 --- a/projects/ng-chartist/src/lib/chartist.component.spec.ts +++ b/projects/ng-chartist/src/lib/chartist.component.spec.ts @@ -34,7 +34,7 @@ describe('chartist component', function(): void { instance.data = data[chartType]; instance.type = chartType; - await instance.renderChart(); + await instance['renderChart'](); expect(Chartist.Bar).toHaveBeenCalledTimes(1); }); @@ -45,7 +45,7 @@ describe('chartist component', function(): void { instance.data = data[chartType]; instance.type = chartType; - const chart = await instance.renderChart(); + const chart = await instance['renderChart'](); expect(chart instanceof Chartist.Bar).toBe(true); }); @@ -53,7 +53,7 @@ describe('chartist component', function(): void { it('should bind events if there are events', async function() { const chartType: ChartType = 'Bar'; - spyOn(instance, 'bindEvents').and.callThrough(); + spyOn(instance, 'bindEvents').and.callThrough(); instance.data = data[chartType]; instance.type = chartType; @@ -65,7 +65,7 @@ describe('chartist component', function(): void { await instance.ngOnInit(); - expect(instance.bindEvents).toHaveBeenCalled(); + expect(instance['bindEvents']).toHaveBeenCalled(); }); it('should re-render the chart if the chart type changes', function(): void { @@ -75,11 +75,11 @@ describe('chartist component', function(): void { instance.type = 'Line'; - spyOn(instance, 'renderChart').and.callThrough(); + spyOn(instance, 'renderChart').and.callThrough(); - instance.update(changes); + instance['update'](changes); - expect(instance.renderChart).toHaveBeenCalled(); + expect(instance['renderChart']).toHaveBeenCalled(); }); it('should update the chart if the data changes', async function() { @@ -95,19 +95,19 @@ describe('chartist component', function(): void { fixture.detectChanges(); - await instance.renderChart(); + await instance['renderChart'](); instance.data = data.Line; instance.type = 'Line'; spyOn(instance.chart, 'update').and.callThrough(); - spyOn(instance, 'renderChart').and.callThrough(); + spyOn(instance, 'renderChart').and.callThrough(); fixture.detectChanges(); - instance.update(changes); + instance['update'](changes); - expect(instance.renderChart).not.toHaveBeenCalled(); + expect(instance['renderChart']).not.toHaveBeenCalled(); expect(instance.chart.update).toHaveBeenCalled(); }); @@ -123,19 +123,19 @@ describe('chartist component', function(): void { fixture.detectChanges(); - await instance.renderChart(); + await instance['renderChart'](); instance.data = data.Bar; instance.type = 'Bar'; spyOn(instance.chart, 'update').and.callThrough(); - spyOn(instance, 'renderChart').and.callThrough(); + spyOn(instance, 'renderChart').and.callThrough(); fixture.detectChanges(); - instance.update(changes); + instance['update'](changes); - expect(instance.renderChart).not.toHaveBeenCalled(); + expect(instance['renderChart']).not.toHaveBeenCalled(); expect(instance.chart.update).toHaveBeenCalled(); }); diff --git a/projects/ng-chartist/src/lib/chartist.component.ts b/projects/ng-chartist/src/lib/chartist.component.ts index cbd2d04f..db0f142f 100644 --- a/projects/ng-chartist/src/lib/chartist.component.ts +++ b/projects/ng-chartist/src/lib/chartist.component.ts @@ -41,23 +41,25 @@ export interface ChartEvent { template: '' }) export class ChartistComponent implements OnInit, OnChanges, OnDestroy { - @Input() // @ts-ignore - public data: Promise | Chartist.IChartistData; + @Input() + data: Promise | Chartist.IChartistData; // @ts-ignore - @Input() public type: Promise | ChartType; - @Input() - // @ts-ignore - public options: Promise | Chartist.IChartOptions; + type: Promise | ChartType; + // @ts-ignore @Input() + options: Promise | Chartist.IChartOptions; + // @ts-ignore - public responsiveOptions: Promise | ResponsiveOptions; + @Input() + responsiveOptions: Promise | ResponsiveOptions; // @ts-ignore - @Input() public events: ChartEvent; + @Input() + events: ChartEvent; // @ts-ignore public chart: ChartInterfaces; @@ -68,7 +70,7 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy { this.element = element.nativeElement; } - public ngOnInit(): Promise { + ngOnInit(): Promise { if (!this.type || !this.data) { Promise.reject('Expected at least type and data.'); } @@ -82,17 +84,17 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy { }); } - public ngOnChanges(changes: SimpleChanges): void { + ngOnChanges(changes: SimpleChanges): void { this.update(changes); } - public ngOnDestroy(): void { + ngOnDestroy(): void { if (this.chart) { this.chart.detach(); } } - public renderChart(): Promise { + private renderChart(): Promise { const promises: any[] = [ this.type, this.element, @@ -114,7 +116,7 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy { }); } - public update(changes: SimpleChanges): void { + private update(changes: SimpleChanges): void { if (!this.chart || 'type' in changes) { this.renderChart(); } else { @@ -130,7 +132,7 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy { } } - public bindEvents(chart: any): void { + private bindEvents(chart: any): void { for (const event of Object.keys(this.events)) { chart.on(event, this.events[event]); }