-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into IS-2027-2-Add-age-filter
- Loading branch information
Showing
11 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Checkbox, CheckboxGroup } from '@navikt/ds-react'; | ||
import React from 'react'; | ||
import { AgeFilterOption } from '@/utils/hendelseFilteringUtils'; | ||
import * as Amplitude from '@/utils/amplitude'; | ||
import { EventType } from '@/utils/amplitude'; | ||
|
||
const text = { | ||
legend: 'Alder', | ||
option: { | ||
underThirty: 't.o.m. 30 år', | ||
overThirty: 'Over 30 år', | ||
}, | ||
}; | ||
|
||
interface Props { | ||
onChange(value: AgeFilterOption[]): void; | ||
|
||
selectedAgeFilters: AgeFilterOption[]; | ||
} | ||
|
||
function logOptionSelectedEvent(option: AgeFilterOption[]) { | ||
Amplitude.logEvent({ | ||
type: EventType.OptionSelected, | ||
data: { | ||
url: window.location.href, | ||
tekst: 'Aldersfilter endret', | ||
option: option.toString(), | ||
}, | ||
}); | ||
} | ||
|
||
export function AgeFilter({ onChange, selectedAgeFilters }: Props) { | ||
return ( | ||
<CheckboxGroup | ||
legend={text.legend} | ||
onChange={(val: AgeFilterOption[]) => { | ||
onChange(val); | ||
logOptionSelectedEvent(val); | ||
}} | ||
value={selectedAgeFilters} | ||
size="small" | ||
> | ||
<Checkbox value={AgeFilterOption.ThirtyAndUnder}> | ||
{text.option.underThirty} | ||
</Checkbox> | ||
<Checkbox value={AgeFilterOption.OverThirty}> | ||
{text.option.overThirty} | ||
</Checkbox> | ||
</CheckboxGroup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { AgeFilterOption, filterOnAge } from '@/utils/hendelseFilteringUtils'; | ||
import { PersonregisterState } from '@/api/types/personregisterTypes'; | ||
import { createPersonDataWithName } from '../utils/hendelseFilteringUtilsTest'; | ||
import { expect } from 'chai'; | ||
|
||
describe('Filters unit tests', () => { | ||
const currentYear = new Date().getFullYear(); | ||
const yearBornTwentyFive = (currentYear - 25).toString().slice(2); | ||
const yearBornThirty = (currentYear - 30).toString().slice(2); | ||
const yearBornThirtyFive = (currentYear - 35).toString().slice(2); | ||
const yearBornFourty = (currentYear - 40).toString().slice(2); | ||
const yearBornFourtyFive = (currentYear - 45).toString().slice(2); | ||
|
||
const twentyFiveFnr = `0101${yearBornTwentyFive}99999`; | ||
const thirtyFnr = `0101${yearBornThirty}99999`; | ||
const thirtyFiveFnr = `0101${yearBornThirtyFive}99999`; | ||
const fourtyFnr = `0101${yearBornFourty}99999`; | ||
const fourtyFiveFnr = `0101${yearBornFourtyFive}99999`; | ||
|
||
console.log( | ||
`FNR: ${twentyFiveFnr}, ${thirtyFnr}, ${thirtyFiveFnr}, ${fourtyFnr}, ${fourtyFiveFnr}` | ||
); | ||
|
||
const personregister: PersonregisterState = { | ||
[twentyFiveFnr]: createPersonDataWithName('Bjarne Bjarnson'), | ||
[thirtyFnr]: createPersonDataWithName('Vetle Vetlesen'), | ||
[thirtyFiveFnr]: createPersonDataWithName('Geir Geirsson'), | ||
[fourtyFnr]: createPersonDataWithName('Eirik Eiriksson'), | ||
[fourtyFiveFnr]: createPersonDataWithName('John Johnson'), | ||
}; | ||
|
||
it('Filters out all people over 30 years old', () => { | ||
const thirtyAndUnderPersons = filterOnAge(personregister, [ | ||
AgeFilterOption.ThirtyAndUnder, | ||
]); | ||
expect(Object.values(thirtyAndUnderPersons).length).to.deep.equal(2); | ||
expect(Object.values(thirtyAndUnderPersons)[0]?.navn).to.deep.equal( | ||
'Bjarne Bjarnson' | ||
); | ||
expect(Object.values(thirtyAndUnderPersons)[1]?.navn).to.deep.equal( | ||
'Vetle Vetlesen' | ||
); | ||
}); | ||
|
||
it('Filters out all people 30 years old and younger', () => { | ||
const overThirtyPersons = filterOnAge(personregister, [ | ||
AgeFilterOption.OverThirty, | ||
]); | ||
expect(Object.values(overThirtyPersons).length).to.deep.equal(3); | ||
expect(Object.values(overThirtyPersons)[0]?.navn).to.deep.equal( | ||
'Geir Geirsson' | ||
); | ||
expect(Object.values(overThirtyPersons)[1]?.navn).to.deep.equal( | ||
'Eirik Eiriksson' | ||
); | ||
expect(Object.values(overThirtyPersons)[2]?.navn).to.deep.equal( | ||
'John Johnson' | ||
); | ||
}); | ||
|
||
it('Filters no persons when no age filter is selected', () => { | ||
const noPersonsFiltered = filterOnAge(personregister, []); | ||
expect(Object.values(noPersonsFiltered).length).to.deep.equal(5); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters