Skip to content

Commit

Permalink
Add stronger typing / object access map
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjmaclean committed Sep 8, 2021
1 parent bbc19c2 commit ea21c15
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 93 deletions.
4 changes: 3 additions & 1 deletion cypress/integration/ct-zero.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { DimensionName } from '../../src/app/_models';

context('statistics-dashboard', () => {

const ctZeroParam = 'content-tier-zero=true';
const ctZeroFilterParam = 'contentTier';
const ctZeroFilterParam = DimensionName.contentTier;
const selCtrlCTZero = '[for=ctZero]';
const selFilterLabel = '.filter-label';
const selFilterOpener = '.opener-name';
Expand Down
18 changes: 10 additions & 8 deletions src/app/_data/static-data.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export const facetNames = [
'contentTier',
'COUNTRY',
'DATA_PROVIDER',
'metadataTier',
'PROVIDER',
'RIGHTS',
'TYPE'
import { DimensionName } from '../_models';

export const facetNames: Array<DimensionName> = [
DimensionName.contentTier,
DimensionName.COUNTRY,
DimensionName.DATA_PROVIDER,
DimensionName.metadataTier,
DimensionName.PROVIDER,
DimensionName.RIGHTS,
DimensionName.TYPE
];

export const colours = ['#0a72cc', '#e11d53', '#ffae00', '#219d31'];
Expand Down
53 changes: 27 additions & 26 deletions src/app/_mocked/mock-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { delay } from 'rxjs/operators';
import {
BreakdownRequest,
BreakdownResults,
DimensionName,
GeneralResults,
IHashString,
RawFacet
Expand All @@ -11,7 +12,7 @@ import {
export const MockAPIData = {
facets: [
{
name: 'contentTier',
name: DimensionName.contentTier,
fields: [
{
label: '4',
Expand Down Expand Up @@ -63,7 +64,7 @@ export const MockAPIData = {
]
},
{
name: 'RIGHTS',
name: DimensionName.RIGHTS,
fields: [
{
label: 'http://creativecommons.org/licenses/by-nc-nd',
Expand Down Expand Up @@ -112,7 +113,7 @@ export const MockAPIData = {
export const MockGeneralResults = {
allBreakdowns: [
{
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 181,
Expand Down Expand Up @@ -303,7 +304,7 @@ export const MockGeneralResults = {
]
},
{
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 50,
Expand Down Expand Up @@ -500,14 +501,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Denmark',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand All @@ -525,14 +526,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Ireland',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand All @@ -550,14 +551,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Norway',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand All @@ -575,14 +576,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Finland',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand All @@ -600,14 +601,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Germany',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand All @@ -625,14 +626,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Portugal',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand All @@ -650,14 +651,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Poland',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand All @@ -675,14 +676,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Italy',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand All @@ -700,14 +701,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Holy See (Vatican City State)',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand All @@ -725,14 +726,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Croatia',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand All @@ -750,14 +751,14 @@ export const MockBreakdowns = {
percentage: 9.09,
value: 'Iceland',
breakdown: {
by: 'RIGHTS',
by: DimensionName.RIGHTS,
results: [
{
count: 1,
percentage: 100,
value: 'https://creativecommons.org/licenses/by/2.0/uk',
breakdown: {
by: 'contentTier',
by: DimensionName.contentTier,
results: [
{
count: 1,
Expand Down
12 changes: 11 additions & 1 deletion src/app/_models/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
export enum DimensionName {
contentTier = 'contentTier',
COUNTRY = 'COUNTRY',
DATA_PROVIDER = 'DATA_PROVIDER',
metadataTier = 'metadataTier',
PROVIDER = 'PROVIDER',
RIGHTS = 'RIGHTS',
TYPE = 'TYPE'
}

export interface FacetField {
count: number;
label: string;
Expand All @@ -9,7 +19,7 @@ export interface FacetFieldProcessed extends FacetField {
}

export interface Facet {
name: string;
name: DimensionName;
fields: Array<FacetField>;
}

Expand Down
45 changes: 29 additions & 16 deletions src/app/filter/filter.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormBuilder, FormControl, ReactiveFormsModule } from '@angular/forms';

import { toInputSafeName } from '../_helpers';
import { createMockPipe } from '../_mocked';
import { DimensionName } from '../_models';

import { FilterComponent } from '.';

Expand Down Expand Up @@ -39,11 +40,17 @@ describe('FilterComponent', () => {
});

it('should determine if a select option is enabled', () => {
expect(component.selectOptionEnabled('contentTier', '0')).toBeFalsy();
expect(
component.selectOptionEnabled(DimensionName.contentTier, '0')
).toBeFalsy();
component.form.get('contentTierZero').setValue(true);
expect(component.selectOptionEnabled('contentTier', '0')).toBeTruthy();
expect(
component.selectOptionEnabled(DimensionName.contentTier, '0')
).toBeTruthy();
component.form.get('contentTierZero').setValue(true);
expect(component.selectOptionEnabled('contentTier', '1')).toBeTruthy();
expect(
component.selectOptionEnabled(DimensionName.contentTier, '1')
).toBeTruthy();
});

it('should set the filter options', () => {
Expand All @@ -62,7 +69,7 @@ describe('FilterComponent', () => {

it('should get the values', () => {
const createFormControls = (
grp: string,
grp: DimensionName,
ops: Array<string>
): Array<FormControl> => {
const fGroup = new FormBuilder().group({});
Expand All @@ -78,27 +85,33 @@ describe('FilterComponent', () => {
return res;
};

createFormControls('COUNTRY', ['xxx', 'yyy', 'zzz']);
expect(component.getSetCheckboxValues('COUNTRY')).toEqual('xxx, yyy, zzz');
createFormControls(DimensionName.COUNTRY, ['xxx', 'yyy', 'zzz']);
expect(component.getSetCheckboxValues(DimensionName.COUNTRY)).toEqual(
'xxx, yyy, zzz'
);

createFormControls('metadataTier', ['aaa', 'bbb']);
expect(component.getSetCheckboxValues('metadataTier')).toEqual('aaa, bbb');
createFormControls(DimensionName.metadataTier, ['aaa', 'bbb']);
expect(component.getSetCheckboxValues(DimensionName.metadataTier)).toEqual(
'aaa, bbb'
);

component.group = 'metadataTier';
expect(component.getSetCheckboxValues('metadataTier')).toEqual(
component.group = DimensionName.metadataTier;
expect(component.getSetCheckboxValues(DimensionName.metadataTier)).toEqual(
'Tier aaa, Tier bbb'
);

component.group = 'PROVIDER';
createFormControls('PROVIDER', ['Europeana']);
expect(component.getSetCheckboxValues('PROVIDER')).toEqual('Europeana');
component.group = DimensionName.PROVIDER;
createFormControls(DimensionName.PROVIDER, ['Europeana']);
expect(component.getSetCheckboxValues(DimensionName.PROVIDER)).toEqual(
'Europeana'
);

component.group = 'RIGHTS';
createFormControls('RIGHTS', [
component.group = DimensionName.RIGHTS;
createFormControls(DimensionName.RIGHTS, [
'xxx',
toInputSafeName('//creativecommons.org/licenses/by-nc-nd')
]);
expect(component.getSetCheckboxValues('RIGHTS')).toEqual(
expect(component.getSetCheckboxValues(DimensionName.RIGHTS)).toEqual(
'xxx, CC BY-NC-ND'
);
});
Expand Down
Loading

0 comments on commit ea21c15

Please sign in to comment.