Skip to content

Commit

Permalink
Unit tests / code tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjmaclean committed Aug 30, 2021
1 parent 5b1d679 commit 0bb4fd9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
8 changes: 4 additions & 4 deletions cypress/integration/ct-zero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ context('statistics-dashboard', () => {
cy.get(selFilterLabel).should('have.length', 0);
cy.get(selFilterOpener).contains('Content Tier').should('have.length', 1);

cy.get(selFilterOpener).contains('Content Tier').click();
cy.get(selFilterOpener).contains('Content Tier').click({force: true});
cy.get(selFilterLabel).contains('Tier 0').should('have.length', 0);

cy.get(selCtrlCTZero).click();
cy.get(selCtrlCTZero).click({force: true});

cy.get(selFilterOpener).contains('Content Tier').click();
cy.get(selFilterOpener).contains('Content Tier').click({force: true});
cy.get(selFilterLabel).contains('Tier 0').should('have.length', 1);
});

Expand All @@ -45,7 +45,7 @@ context('statistics-dashboard', () => {
cy.get(selTotalRecords).contains('1,000').should('have.length', 1);
cy.get(selTotalRecords).contains('819').should('have.length', 0);

cy.get(selCtrlCTZero).click();
cy.get(selCtrlCTZero).click({force: true});

cy.get(selTotalRecords).contains('1,000').should('have.length', 0);
cy.get(selTotalRecords).contains('819').should('have.length', 1);
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ context('statistics-dashboard', () => {
cy.get(selFilterRemoveNav).should('have.length', 1);
});

it('should search the filters and rememebr the term when re-opened', () => {
it('should search the filters and remember the term when re-opened', () => {
cy.visit(`/data/contentTier`);
cy.get(selFilterValueLabel).should('have.length', 0);
cy.get(selFilterOpener).first().click({force: true});
Expand All @@ -76,7 +76,7 @@ context('statistics-dashboard', () => {
cy.get(selFilterValueLabel).contains('Belgium').should('have.length', 0);
cy.get(selFilterValueLabel).contains('Germany').should('have.length', 1);

cy.get(selFiltersHeader).click();
cy.get(selFiltersHeader).click({force: true});
cy.get(selFilterOpener).first().click({force: true});
cy.get(selSearch).should('have.value', 'Ge');
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ context('statistics-dashboard', () => {
});

it('should show information links', () => {
cy.get(selLinkInfo).should('have.length', 3);
cy.get(selLinkInfo).should('have.length', 4);
});

it('should show a map', () => {
Expand Down
27 changes: 24 additions & 3 deletions src/app/export/export.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { ElementRef } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import {
async,
ComponentFixture,
fakeAsync,
TestBed,
tick
} from '@angular/core/testing';
import { ExportComponent } from '.';

import { MockExportCSVService } from '../_mocked';
Expand Down Expand Up @@ -43,14 +49,17 @@ describe('ExportComponent', () => {
expect(component).toBeTruthy();
});

it('should copy', () => {
it('should copy', fakeAsync(() => {
(component.contentRef.nativeElement as HTMLInputElement).value = 'some-url';
component.copy();
fixture.detectChanges();
expect(
component.contentRef.nativeElement.classList.contains('copied')
).toBeTruthy();
});
expect(component.copied).toBeTruthy();
tick(component.msMsgDisplay);
expect(component.copied).toBeFalsy();
}));

it('should export CSV', () => {
spyOn(exportCSV, 'download');
Expand All @@ -66,4 +75,16 @@ describe('ExportComponent', () => {
component.export(ExportType.PDF);
expect(component.getChartData).toHaveBeenCalled();
});

it('should export only known types', () => {
spyOn(component, 'getChartData').and.callThrough();
component.export('XXX' as unknown as ExportType);
expect(component.getChartData).not.toHaveBeenCalled();
});

it('should toggle the active status', () => {
expect(component.active).toBeFalsy();
component.toggleActive();
expect(component.active).toBeTruthy();
});
});
11 changes: 0 additions & 11 deletions src/app/overview/overview.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
FacetProcessed,
FilterState,
FmtTableData,
GeneralResults,
IHashArrayNameLabel,
IHashNumber,
NameLabel,
Expand Down Expand Up @@ -113,16 +112,6 @@ export class OverviewComponent extends DataPollingComponent implements OnInit {
this.initialiseFilterStates();
}

getGeneralResults(): void {
this.subs.push(
this.api
.getGeneralResults()
.subscribe((generalResults: GeneralResults) => {
this.dataServerData = generalResults as unknown as BreakdownResults;
})
);
}

getDataServerDataRequest(): BreakdownRequest {
const breakdownRequest: BreakdownRequest = { filters: {} };

Expand Down

0 comments on commit 0bb4fd9

Please sign in to comment.