Skip to content

Commit

Permalink
Remove unused behaviour from assumptions component
Browse files Browse the repository at this point in the history
  • Loading branch information
mgriffin-scottlogic committed Aug 9, 2024
1 parent 3aa5538 commit 03ea38d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<div #assumptionsLimitation class="tce-flex tce-flex-col tce-gap-4" tabindex="0">
<div class="tce-flex tce-justify-between">
<h2 class="tce-text-2xl">Assumptions and Limitations</h2>
<button
type="button"
class="material-icons-outlined tce-text hover:tce-bg-slate-200 hover:tce-rounded"
(click)="onClose()"
aria-label="Close assumptions and limitations">
close
</button>
</div>
<p class="tce-text-sm">
The Technology Carbon Estimator tool is designed to give a high-level overview of the possible areas of carbon
Expand Down Expand Up @@ -117,7 +110,13 @@ <h4 class="tce-text-lg">Carbon Intensity</h4>
<h4 class="tce-text-lg">Upstream Emissions</h4>
<p class="tce-text-sm">
Each class of device is given an average amount of embodied carbon and a lifespan, based on averages taken from
manufacturer provided Product Carbon Footprint documentation<a id="networkNoteRef" role="doc-noteref" href="#networkNote" aria-label="see footnote">*</a>. At present these are:
manufacturer provided Product Carbon Footprint documentation<a
id="networkNoteRef"
role="doc-noteref"
href="#networkNote"
aria-label="see footnote"
>*</a
>. At present these are:
</p>
<table class="tce-w-fit">
<thead>
Expand All @@ -144,8 +143,8 @@ <h4 class="tce-text-lg">Upstream Emissions</h4>
</tbody>
</table>
<aside id="networkNote" class="tce-text-sm tce-italic" role="doc-footnote">
<a role="doc-backlink" href="#networkNoteRef" aria-label="return to reference">*</a> The network device figure is reverse engineered from typical yearly energy and embodied carbon ratios as published
values are difficult to find.
<a role="doc-backlink" href="#networkNoteRef" aria-label="return to reference">*</a> The network device figure is
reverse engineered from typical yearly energy and embodied carbon ratios as published values are difficult to find.
</aside>
<p class="tce-text-sm">
We use the total Embodied Carbon and the lifespan to give an
Expand Down Expand Up @@ -322,10 +321,4 @@ <h5 class="tce-text-base">Managed Services</h5>
<p class="tce-text-sm">
We currently do not make a distinction between on-premises data centers and those run by a third party.
</p>
<button
class="tce-button-close tce-px-3 tce-py-2 tce-self-end"
(click)="onClose()"
aria-label="Close assumptions and limitations">
Close
</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,11 @@ describe('AssumptionsAndLimitationComponent', () => {
fixture.detectChanges();
});

it('should emit close event when click close button', () => {
spyOn(component.closeEvent, 'emit');

fixture.nativeElement.querySelector('button').click();

expect(component.closeEvent.emit).toHaveBeenCalledTimes(1);
});

it('should emit close event when press esc key', () => {
spyOn(component.closeEvent, 'emit');

document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));

expect(component.closeEvent.emit).toHaveBeenCalledTimes(1);
});

it('should have focus afterContentInit', () => {
component.ngAfterContentInit();
fixture.detectChanges();

const hasFocus = component.assumptionsLimitation.nativeElement.contains(document.activeElement);
expect(hasFocus).toBeTrue();
});

it('should emit close event with true value when press esc key with focus within component', () => {
spyOn(component.closeEvent, 'emit');

component.ngAfterContentInit();
fixture.detectChanges();

document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));

expect(component.closeEvent.emit).toHaveBeenCalledWith(true);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterContentInit, Component, ElementRef, EventEmitter, HostListener, Output, ViewChild } from '@angular/core';
import { AfterContentInit, Component, ElementRef, ViewChild } from '@angular/core';
import { CLOUD_AVERAGE_PUE, ON_PREMISE_AVERAGE_PUE } from '../estimation/constants';
import { siteTypeInfo } from '../estimation/estimate-downstream-emissions';
import { PurposeOfSite, WorldLocation, locationArray, purposeOfSiteArray } from '../types/carbon-estimator';
Expand Down Expand Up @@ -33,7 +33,6 @@ const locationDescriptions: Record<WorldLocation, string> = {
imports: [DecimalPipe, ExternalLinkDirective],
})
export class AssumptionsAndLimitationComponent implements AfterContentInit {
@Output() public closeEvent = new EventEmitter<boolean>();
readonly ON_PREMISE_AVERAGE_PUE = ON_PREMISE_AVERAGE_PUE;
readonly CLOUD_AVERAGE_PUE = CLOUD_AVERAGE_PUE;
readonly siteTypeInfo = purposeOfSiteArray.map(purpose => ({
Expand Down Expand Up @@ -85,14 +84,4 @@ export class AssumptionsAndLimitationComponent implements AfterContentInit {
public ngAfterContentInit(): void {
this.assumptionsLimitation.nativeElement.focus({ preventScroll: true });
}

public onClose(hasFocus = true): void {
this.closeEvent.emit(hasFocus);
}

@HostListener('document:keydown.escape', ['$event'])
public onEscKeydown(): void {
const hasFocus = this.assumptionsLimitation.nativeElement.contains(document.activeElement);
this.onClose(hasFocus);
}
}

0 comments on commit 03ea38d

Please sign in to comment.