-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/#230 experience and studies sorted by date #234
Changes from 7 commits
11d242a
721cf05
f9a941e
f95266f
64ec177
7735145
21b84ba
4ad246c
46769fb
79751c1
e022a05
2ec9708
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ExperienceVm } from './experience-section.vm'; | ||
import { dateExtractor, sortByDate } from '../../helpers'; | ||
|
||
export const sortRolesByDate = (experience: ExperienceVm): ExperienceVm => ({ | ||
...experience, | ||
roles: sortByDate(experience.roles, 'startDate'), | ||
}); | ||
|
||
export const mapSortedRolesIntoExperience = (experience: ExperienceVm[]): ExperienceVm[] => | ||
experience.map(experienceItem => sortRolesByDate(experienceItem)); | ||
|
||
export const sortExperienceByDate = (experience: ExperienceVm[]): ExperienceVm[] => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between sortExperienceByDate and sortByDate functions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In sortExperienceByDate, specifies that the sorting is performed on the first element of the array as a parameter of dateExtractor |
||
experience.sort( | ||
(a: ExperienceVm, b) => dateExtractor(b.roles[0], 'startDate') - dateExtractor(a.roles[0], 'startDate') | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { ManfredAwesomicCV } from '../../model'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use '@/model' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||
import { ExperienceVm, Type } from './experience-section.vm'; | ||
import { types } from './experience-section.contants'; | ||
import { mapSortedRolesIntoExperience, sortExperienceByDate } from './experience-section.helpers'; | ||
|
||
export const mapFromMacCvToExperienceSectionVm = (cv: ManfredAwesomicCV): ExperienceVm[] => { | ||
let jobs: ExperienceVm[] = []; | ||
|
@@ -16,7 +17,10 @@ export const mapFromMacCvToExperienceSectionVm = (cv: ManfredAwesomicCV): Experi | |
jobs = [...jobs, { name: organizationName, description: organizationDescription, type: mapType, roles }]; | ||
}); | ||
|
||
return jobs; | ||
const jobsWithMappedRoles: ExperienceVm[] = mapSortedRolesIntoExperience(jobs); | ||
const jobsSortedByDate: ExperienceVm[] = sortExperienceByDate(jobsWithMappedRoles); | ||
|
||
return jobsSortedByDate; | ||
}; | ||
|
||
export const mapOrganizationType = (type: string, types: Type[]): string => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
import { sortStudiesByDate } from './studies-section.helpers'; | ||
import { StudiesSectionVm } from './studies-section.vm'; | ||
|
||
describe('studies-section.helpers specs', () => { | ||
describe('sortStudiesByDate', () => { | ||
it('should return studies section sorted by starting date', () => { | ||
// Arrange | ||
const studies: StudiesSectionVm[] = [ | ||
{ | ||
studyType: 'Certificación', | ||
degreeAchieved: true, | ||
name: 'name2', | ||
startDate: '2020-12-03', | ||
finishDate: '2022-07-08', | ||
description: 'description2', | ||
institution: { | ||
name: 'name2', | ||
location: { | ||
country: 'Italia', | ||
region: 'region2', | ||
address: 'address2', | ||
}, | ||
}, | ||
}, | ||
{ | ||
studyType: 'Certificación', | ||
degreeAchieved: true, | ||
name: 'name2', | ||
startDate: '2009-04-02', | ||
finishDate: '2011-03-20', | ||
description: 'description2', | ||
institution: { | ||
name: 'name2', | ||
location: { | ||
country: 'Italia', | ||
region: 'region2', | ||
address: 'address2', | ||
}, | ||
}, | ||
}, | ||
{ | ||
studyType: 'Grado oficial', | ||
degreeAchieved: false, | ||
name: 'name', | ||
startDate: '2022-11-17', | ||
finishDate: '2023-05-01', | ||
description: 'description', | ||
institution: { | ||
name: 'name', | ||
location: { | ||
country: 'España', | ||
region: 'region', | ||
address: 'address', | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
// Act | ||
const result: StudiesSectionVm[] = sortStudiesByDate(studies); | ||
|
||
const expectedResult: StudiesSectionVm[] = [ | ||
{ | ||
studyType: 'Grado oficial', | ||
degreeAchieved: false, | ||
name: 'name', | ||
startDate: '2022-11-17', | ||
finishDate: '2023-05-01', | ||
description: 'description', | ||
institution: { | ||
name: 'name', | ||
location: { | ||
country: 'España', | ||
region: 'region', | ||
address: 'address', | ||
}, | ||
}, | ||
}, | ||
{ | ||
studyType: 'Certificación', | ||
degreeAchieved: true, | ||
name: 'name2', | ||
startDate: '2020-12-03', | ||
finishDate: '2022-07-08', | ||
description: 'description2', | ||
institution: { | ||
name: 'name2', | ||
location: { | ||
country: 'Italia', | ||
region: 'region2', | ||
address: 'address2', | ||
}, | ||
}, | ||
}, | ||
{ | ||
studyType: 'Certificación', | ||
degreeAchieved: true, | ||
name: 'name2', | ||
startDate: '2009-04-02', | ||
finishDate: '2011-03-20', | ||
description: 'description2', | ||
institution: { | ||
name: 'name2', | ||
location: { | ||
country: 'Italia', | ||
region: 'region2', | ||
address: 'address2', | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
// Assert | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
|
||
it('should return studies section sorted by starting date. No changes if already sorted', () => { | ||
// Arrange | ||
const studies: StudiesSectionVm[] = [ | ||
{ | ||
studyType: 'Grado oficial', | ||
degreeAchieved: false, | ||
name: 'name', | ||
startDate: '2022-11-17', | ||
finishDate: '2023-05-01', | ||
description: 'description', | ||
institution: { | ||
name: 'name', | ||
location: { | ||
country: 'España', | ||
region: 'region', | ||
address: 'address', | ||
}, | ||
}, | ||
}, | ||
{ | ||
studyType: 'Certificación', | ||
degreeAchieved: true, | ||
name: 'name2', | ||
startDate: '2020-12-03', | ||
finishDate: '2022-07-08', | ||
description: 'description2', | ||
institution: { | ||
name: 'name2', | ||
location: { | ||
country: 'Italia', | ||
region: 'region2', | ||
address: 'address2', | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
// Act | ||
const result: StudiesSectionVm[] = sortStudiesByDate(studies); | ||
|
||
const expectedResult: StudiesSectionVm[] = [ | ||
{ | ||
studyType: 'Grado oficial', | ||
degreeAchieved: false, | ||
name: 'name', | ||
startDate: '2022-11-17', | ||
finishDate: '2023-05-01', | ||
description: 'description', | ||
institution: { | ||
name: 'name', | ||
location: { | ||
country: 'España', | ||
region: 'region', | ||
address: 'address', | ||
}, | ||
}, | ||
}, | ||
{ | ||
studyType: 'Certificación', | ||
degreeAchieved: true, | ||
name: 'name2', | ||
startDate: '2020-12-03', | ||
finishDate: '2022-07-08', | ||
description: 'description2', | ||
institution: { | ||
name: 'name2', | ||
location: { | ||
country: 'Italia', | ||
region: 'region2', | ||
address: 'address2', | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
// Assert | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
|
||
it('should return same array with one element when array has one element', () => { | ||
// Arrange | ||
const studies: StudiesSectionVm[] = [ | ||
{ | ||
studyType: 'Certificación', | ||
degreeAchieved: true, | ||
name: 'name2', | ||
startDate: '2020-12-03', | ||
finishDate: '2022-07-08', | ||
description: 'description2', | ||
institution: { | ||
name: 'name2', | ||
location: { | ||
country: 'Italia', | ||
region: 'region2', | ||
address: 'address2', | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
// Act | ||
const result: StudiesSectionVm[] = sortStudiesByDate(studies); | ||
|
||
const expectedResult: StudiesSectionVm[] = [ | ||
{ | ||
studyType: 'Certificación', | ||
degreeAchieved: true, | ||
name: 'name2', | ||
startDate: '2020-12-03', | ||
finishDate: '2022-07-08', | ||
description: 'description2', | ||
institution: { | ||
name: 'name2', | ||
location: { | ||
country: 'Italia', | ||
region: 'region2', | ||
address: 'address2', | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
// Assert | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { sortByDate } from '../../helpers'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use '@/helpers" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as with experience. With import in this way I get test failures |
||
|
||
import { StudiesSectionVm } from './studies-section.vm'; | ||
|
||
export const sortStudiesByDate = (studies: StudiesSectionVm[]): StudiesSectionVm[] => sortByDate(studies, 'startDate'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const dateExtractor = <T>(item: T, path: keyof T): number => { | ||
const date = item[path]; | ||
if (typeof date === 'string') { | ||
return new Date(date).getTime(); | ||
} | ||
throw new Error(`Invalid path: ${path.toString()}`); | ||
}; | ||
|
||
export const sortByDate = <T>(array: T[], path: keyof T): T[] => | ||
array.sort((a: T, b: T) => dateExtractor(b, path) - dateExtractor(a, path)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './date-helpers'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use '@/helpers' on import and move it at first line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With import in this way I get test failures