Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jantoun-scottlogic committed Jun 19, 2024
1 parent 8abe6a2 commit 0b8b9b9
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions src/app/carbon-estimation/carbon-estimation.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,38 +65,53 @@ describe('CarbonEstimationComponent', () => {
expect(component.chartOptions.chart.height).toBe(600 - estimatorBaseHeight - 200 - 100);
});

it('should recalculate chart height on window resize, for laptop screen', () => {
spyOn(component.chart as ChartComponent, 'updateOptions');
spyOnProperty(component.detailsPanel.nativeElement, 'clientHeight').and.returnValue(200);
[0.5, 1, 2, 5].forEach(browserZoomFactor => {
it(`should recalculate chart height on window resize, for laptop screen (zoom factor: ${browserZoomFactor})`, () => {
spyOn(component.chart as ChartComponent, 'updateOptions');
spyOnProperty(component.detailsPanel.nativeElement, 'clientHeight').and.returnValue(200);

component.onResize(2000, 1000, 2000, 1);
component.onResize(1500, 1000, 2000, browserZoomFactor);

expect(component.chart?.updateOptions).toHaveBeenCalledOnceWith({
chart: { height: 1500 }, // Height will be capped at a percentage of the screen height
expect(component.chart?.updateOptions).toHaveBeenCalledOnceWith({
chart: { height: (1500 - estimatorBaseHeight - 200) * browserZoomFactor },
});
});
});

[0.5, 1, 2, 5].forEach(browserZoomFactor => {
it(`should recalculate chart height on window resize, for mobile screen (zoom factor: ${browserZoomFactor})`, () => {
spyOn(component.chart as ChartComponent, 'updateOptions');
spyOnProperty(component.detailsPanel.nativeElement, 'clientHeight').and.returnValue(200);

component.onResize(1000, 500, 1000, browserZoomFactor);

expect(component.chart?.updateOptions).toHaveBeenCalledOnceWith({
chart: { height: (1000 - estimatorBaseHeight - 200 + estimatorHeights.title) * browserZoomFactor },
});
});
});

it('should recalculate chart height on window resize, for mobile screen', () => {
it('should cap chart height as a percentage of screen height for laptop screen', () => {
spyOn(component.chart as ChartComponent, 'updateOptions');
spyOnProperty(component.detailsPanel.nativeElement, 'clientHeight').and.returnValue(200);

component.onResize(1000, 500, 1000, 1);
const screenHeight = 2000;
component.onResize(2000, 1000, screenHeight, 1);

expect(component.chart?.updateOptions).toHaveBeenCalledOnceWith({
chart: { height: 1000 - estimatorBaseHeight - 200 + estimatorHeights.title },
chart: { height: screenHeight * 0.75 },
});
});

[0.5, 1, 2, 5].forEach(browserZoomFactor => {
it(`should scale chart height appropriately if the browser zoom factor is ${browserZoomFactor}`, () => {
spyOn(component.chart as ChartComponent, 'updateOptions');
spyOnProperty(component.detailsPanel.nativeElement, 'clientHeight').and.returnValue(200);
it('should cap chart height as a percentage of screen height for mobile screen', () => {
spyOn(component.chart as ChartComponent, 'updateOptions');
spyOnProperty(component.detailsPanel.nativeElement, 'clientHeight').and.returnValue(200);

component.onResize(1500, 1000, 2000, browserZoomFactor);
const screenHeight = 1000;
component.onResize(1100, 500, screenHeight, 1);

expect(component.chart?.updateOptions).toHaveBeenCalledOnceWith({
chart: { height: (1500 - estimatorBaseHeight - 200) * browserZoomFactor },
});
expect(component.chart?.updateOptions).toHaveBeenCalledOnceWith({
chart: { height: screenHeight * 0.75 },
});
});

Expand Down

0 comments on commit 0b8b9b9

Please sign in to comment.