Skip to content

Commit

Permalink
review(JOB-172) : some bsr by VEN
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Trollé committed Nov 22, 2017
1 parent ac0d444 commit cabc1ef
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 58 deletions.
21 changes: 10 additions & 11 deletions client/src/utils/jobsSorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import projectStaffingNeededDate from '@/utils/projectStaffingNeededDate';
import moment from 'moment';

export default {

sort(jobs, availabityDate = moment()) {
const regexToFindOnlyMissions = /^mission_/;
let jobsWithStatusMission = jobs.filter(job => regexToFindOnlyMissions.test(job.project.status));
let jobsWithOtherStatus = jobs.filter(job => !regexToFindOnlyMissions.test(job.project.status));
const jobsWithStatusMission = jobs.filter(job => regexToFindOnlyMissions.test(job.project.status));
const jobsWithOtherStatus = jobs.filter(job => !regexToFindOnlyMissions.test(job.project.status));

if (jobsWithStatusMission.length > 1) {
jobsWithStatusMission = projectStaffingNeededDate.sortAll(jobsWithStatusMission);
}
if (jobsWithOtherStatus.length > 1) {
jobsWithOtherStatus = projectStaffingNeededDate.sortAfter(jobsWithOtherStatus, availabityDate);
}
return [...jobsWithStatusMission, ...jobsWithOtherStatus];
},
const sortedJobsWithStatusMission = jobsWithStatusMission.length > 1 ?
projectStaffingNeededDate.sortAll(jobsWithStatusMission) :
jobsWithStatusMission;
const sortedJobsWithOtherStatus = jobsWithOtherStatus.length > 1 ?
projectStaffingNeededDate.sortAfter(jobsWithOtherStatus, availabityDate) :
jobsWithOtherStatus;

return [...sortedJobsWithStatusMission, ...sortedJobsWithOtherStatus];
},
};
6 changes: 3 additions & 3 deletions client/src/utils/projectStaffingNeededDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function _sortChronologically(jobs) {
});
}

function _filterOldJobs(jobs, availabilityDate) {
function _keepOnlyAvailableJobs(jobs, availabilityDate) {
return jobs.filter((job) => {
const jobDate = moment(job.activity.staffing_needed_from, 'YYYY-MM-DD');
return jobDate.isSameOrAfter(availabilityDate);
Expand All @@ -24,7 +24,7 @@ export default {
return _sortChronologically(jobs);
},
sortAfter(jobs, availabilityDate) {
const filteredJobs = _filterOldJobs(jobs, availabilityDate);
return _sortChronologically(filteredJobs);
const availableJobs = _keepOnlyAvailableJobs(jobs, availabilityDate);
return _sortChronologically(availableJobs);
},
};
3 changes: 1 addition & 2 deletions client/test/unit/specs/components/CountryPicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ describe('Unit | Component | CountryPicker.vue', () => {
});

it('should be named "CountryPicker"', () => {
// when
expect(component.$options.name).to.equal('CountryPicker');
});

describe('$data', () => {
it('should have onlyOneCountry property set to anyCountry', () => {
it('should have onlyOneCountry property set by default to anyCountry', () => {
expect(component.$data.onlyOneCountry).to.equal('anyCountry');
});
});
Expand Down
3 changes: 1 addition & 2 deletions client/test/unit/specs/components/DatePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ describe('Unit | Component | DatePicker.vue', () => {
});

it('should be named "DatePicker"', () => {
// when
expect(component.$options.name).to.equal('DatePicker');
});

describe('$data', () => {
// TODO find a better solution to write this assertion
it('should have date property set to today', () => {
it('should have date property set by default to today', () => {
expect(component.$data.date - new Date(2017, 9, 4)).to.equal(0);
});
});
Expand Down
1 change: 0 additions & 1 deletion client/test/unit/specs/components/JobList.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ describe('Unit | Component | JobList.vue', () => {
const interestModal = component.$el.querySelectorAll('.interest-modal-wrapper');
expect(interestModal.length).to.equal(1);
});
// TODO check that interest modal use chosenJob

it('should have a date picker', () => {
const datePicker = component.$el.querySelectorAll('.date-picker');
Expand Down
43 changes: 4 additions & 39 deletions client/test/unit/specs/utils/projectStaffingNeededDate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,56 +76,21 @@ describe('Unit | Utils | Project Staffing Needed Date', () => {
clock.restore();
});

it('should sort chronologically two jobs according to project staffing needed date', () => {
// Given
const futureJob = { activity: { id: 1, staffing_needed_from: '2017-11-03' } };
const todayJob = { activity: { id: 2, staffing_needed_from: '2017-10-04' } };

const givenJobs = [futureJob, todayJob];
const expectedSortedJobs = [todayJob, futureJob];

// When
const sortedJobs = projectStaffingNeededDate.sortAfter(givenJobs, availabityDate);

// Then
expect(sortedJobs).to.deep.equal(expectedSortedJobs);
});

it('should sort chronologically five jobs according to project staffing needed date', () => {
it('should sort three jobs whose staffing_needed_from chronologically after availability date', () => {
// Given
const futureJob = { activity: { id: 1, staffing_needed_from: '2017-11-03' } };
const todayJob = { activity: { id: 1, staffing_needed_from: '2017-10-04' } };
const yesterdayJob = { activity: { id: 2, staffing_needed_from: '2017-10-03' } };
const beforeYesterdayJob = { activity: { id: 3, staffing_needed_from: '2017-10-02' } };
const oldJob = { activity: { id: 4, staffing_needed_from: '2017-06-01' } };
const tomorrowJob = { activity: { id: 5, staffing_needed_from: '2017-10-05' } };
const notAvailableJob = { activity: { id: 3, staffing_needed_from: '2017-09-02' } };

const givenJobs = [futureJob, todayJob, yesterdayJob, beforeYesterdayJob, oldJob, tomorrowJob];
const expectedSortedJobs = [yesterdayJob, todayJob, tomorrowJob, futureJob];
const givenJobs = [futureJob, todayJob, notAvailableJob];
const expectedSortedJobs = [todayJob, futureJob];

// When
const sortedJobs = projectStaffingNeededDate.sortAfter(givenJobs, availabityDate);

// Then
expect(sortedJobs).to.deep.equal(expectedSortedJobs);
});

it('should sort chronologically five jobs with the same date according to project staffing needed date', () => {
// Given
const todayJob1 = { activity: { id: 1, staffing_needed_from: '2017-10-04' } };
const todayJob2 = { activity: { id: 2, staffing_needed_from: '2017-10-04' } };
const todayJob3 = { activity: { id: 3, staffing_needed_from: '2017-10-04' } };
const todayJob4 = { activity: { id: 4, staffing_needed_from: '2017-10-04' } };
const todayJob5 = { activity: { id: 5, staffing_needed_from: '2017-10-04' } };

const givenJobs = [todayJob1, todayJob2, todayJob3, todayJob4, todayJob5];
const expectedSortedJobs = [todayJob1, todayJob2, todayJob3, todayJob4, todayJob5];

// When
const sortedJobs = projectStaffingNeededDate.sortAfter(givenJobs, availabityDate);
// Then
expect(sortedJobs).to.deep.equal(expectedSortedJobs);
});
});
});

0 comments on commit cabc1ef

Please sign in to comment.