Skip to content
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

#720 Added a message if vacancy was unpublished #732

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/store/vacancies.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,49 @@ export default {
let firestoreRef = firestore.collection('vacancies');
if (params && params.vacancyIds.length) {
firestoreRef = firestoreRef.where(firebase.firestore.FieldPath.documentId(), 'in', params.vacancyIds);
return bindFirestoreRef('records', firestoreRef, { serialize: vuexfireSerialize });
} else {
firestoreRef = firestoreRef.orderBy('referenceNumber', 'desc');
return bindFirestoreRef('allRecords', firestoreRef, { serialize: vuexfireSerialize });
}
return bindFirestoreRef('records', firestoreRef, { serialize: vuexfireSerialize });
}),
unbind: firestoreAction(({ unbindFirestoreRef }) => {
return unbindFirestoreRef('records');
unbindFirestoreRef('records');
mbrookeswebdev marked this conversation as resolved.
Show resolved Hide resolved
unbindFirestoreRef('allRecords');
return true;
}),
},
state: {
records: [],
},
allRecords: [],
},

getters: {
vacancies: state => {
return state.records;
},
allVacancies: state => {
return state.allRecords;
},
openVacancies: (state, getters) => {
const vacancies = getters.vacancies.concat(getStaticVacancies());

const vacancies = getters.allVacancies.concat(getStaticVacancies());
return vacancies.filter(vacancy => {

const openDate = vacancy.applicationOpenDate || parseEstimatedDate(vacancy.estimatedLaunchDate);
const closeDate = vacancy.applicationCloseDate || new Date(2050, 1, 1);
const hasOnlyEstimates = (vacancy.estimatedLaunchDate && (!vacancy.applicationOpenDate && !vacancy.applicationCloseDate));

if (!isDate(openDate)) return false;

// FIXME: workaround for hardcoded times
openDate.setHours(13);
closeDate.setHours(13);

return (!isDateInFuture(openDate) && isDateInFuture(closeDate)) && !hasOnlyEstimates;
});
},
futureVacancies: (state, getters) => {
const vacancies = getters.vacancies.concat(getStaticVacancies());

const vacancies = getters.allVacancies.concat(getStaticVacancies());
return vacancies.filter(vacancy => {
const openDate = vacancy.applicationOpenDate || parseEstimatedDate(vacancy.estimatedLaunchDate);
const hasOnlyEstimates = (vacancy.estimatedLaunchDate && (!vacancy.applicationOpenDate && !vacancy.applicationCloseDate));
Expand All @@ -62,8 +67,7 @@ export default {
});
},
inProgressVacancies: (state, getters) => {
const vacancies = getters.vacancies.concat(getStaticVacancies());

const vacancies = getters.allVacancies.concat(getStaticVacancies());
return vacancies.filter(vacancy => {
if (!vacancy.applicationCloseDate) {
return false;
Expand All @@ -77,7 +81,7 @@ export default {
});
},
getVacancy: (state, getters) => (vacancyId) => {
const vacancies = getters.vacancies;
const vacancies = getters.allVacancies;
const returnVacancies = vacancies.filter(vacancy => vacancy.id === vacancyId);
return returnVacancies.length == 1 ? returnVacancies[0] : {};
},
Expand Down
93 changes: 53 additions & 40 deletions src/views/Applications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,43 +58,50 @@

<div class="moj-button-menu">
<div class="moj-button-menu__wrapper">
<RouterLink
v-if="isOpen(application.dateExtension, application.exerciseId) && application.status == 'draft'"
:class="`govuk-button moj-button-menu__item info-link--applications--continue-with-application-${application.exerciseId}`"
:to="{ name: 'task-list', params: { id: application.exerciseId } }"
role="button"
data-module="govuk-button"
<div
v-if="!vacancyExists(application.exerciseId)"
class="govuk-body govuk-!-margin-top-3 govuk-!-margin-bottom-0"
>
Continue with application
</RouterLink>
<RouterLink
v-else
:class="`govuk-button govuk-button--secondary moj-button-menu__item info-link--applications--view-sent-application-${application.exerciseId}`"
:to="{ name: 'review', params: { id: application.exerciseId } }"
role="button"
data-module="govuk-button"
>
<span v-if="application.status == 'draft'">View draft application</span>
<span v-else>View sent application</span>
</RouterLink>
<RouterLink
:class="`govuk-button govuk-button--secondary moj-button-menu__item info-link--applications--view-advert-${application.exerciseId}`"
role="button"
data-module="govuk-button"
:to="{ name: 'vacancy-details', params: { id: application.exerciseId } }"
>
View advert
</RouterLink>

<RouterLink
v-if="application.characterChecks && application.characterChecks.declaration === true"
:class="`govuk-button govuk-button--secondary moj-button-menu__item float-right info-link--applications--view-good-character-checks-consent-${application.exerciseId}`"
:to="{ name: 'character-checks-review', params: { id: application.exerciseId } }"
role="button"
data-module="govuk-button"
>
View good character checks consent
</RouterLink>
Data is temporarily unavailable.
</div>
<div v-else>
<RouterLink
v-if="isOpen(application.dateExtension, application.exerciseId) && application.status == 'draft'"
:class="`govuk-button moj-button-menu__item info-link--applications--continue-with-application-${application.exerciseId}`"
:to="{ name: 'task-list', params: { id: application.exerciseId } }"
role="button"
data-module="govuk-button"
>
Continue with application
</RouterLink>
<RouterLink
v-else
:class="`govuk-button govuk-button--secondary moj-button-menu__item info-link--applications--view-sent-application-${application.exerciseId}`"
:to="{ name: 'review', params: { id: application.exerciseId } }"
role="button"
data-module="govuk-button"
>
<span v-if="application.status == 'draft'">View draft application</span>
<span v-else>View sent application</span>
</RouterLink>
<RouterLink
:class="`govuk-button govuk-button--secondary moj-button-menu__item info-link--applications--view-advert-${application.exerciseId}`"
role="button"
data-module="govuk-button"
:to="{ name: 'vacancy-details', params: { id: application.exerciseId } }"
>
View advert
</RouterLink>
<RouterLink
v-if="application.characterChecks && application.characterChecks.declaration === true"
:class="`govuk-button govuk-button--secondary moj-button-menu__item float-right info-link--applications--view-good-character-checks-consent-${application.exerciseId}`"
:to="{ name: 'character-checks-review', params: { id: application.exerciseId } }"
role="button"
data-module="govuk-button"
>
View good character checks consent
</RouterLink>
</div>
</div>
</div>
</li>
Expand Down Expand Up @@ -145,9 +152,10 @@ import isVacancyOpen from '@/helpers/isVacancyOpen';

export default {
computed: {
...mapState('applications', [
'records',
]),
...mapState('applications', ['records']),
allVacancies() {
return this.$store.getters['vacancies/allVacancies'];
},
},
created() {
this.$store.dispatch('applications/bind');
Expand All @@ -162,7 +170,12 @@ export default {
} else {
return false;
}

},
vacancyExists(exerciseId) {
if (!this.allVacancies) {
return false;
}
return this.allVacancies.find(vacancy => vacancy.id === exerciseId) !== undefined;
},
},
};
Expand Down
17 changes: 9 additions & 8 deletions tests/unit/store/vacancies.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('store/vacancies', () => {
beforeEach(() => {
state = {
records: [],
mbrookeswebdev marked this conversation as resolved.
Show resolved Hide resolved
allRecords: [],
};
});

Expand All @@ -52,7 +53,7 @@ describe('store/vacancies', () => {
describe('openVacancies', () => {
it('returns only open vacancies', () => {
getStaticVacancies.mockReturnValue([]);
const openVacancies = getters.openVacancies(state, { vacancies: mockVacancies });
const openVacancies = getters.openVacancies(state, { allVacancies: mockVacancies });

expect(openVacancies.length).toEqual(1);
expect(openVacancies[0].name).toEqual('OPEN VACANCY');
Expand All @@ -67,7 +68,7 @@ describe('store/vacancies', () => {
applicationCloseDate: futureDate,
};

const openVacancies = getters.openVacancies(state, { vacancies: [mockOpenVacancy, ...mockVacancies] });
const openVacancies = getters.openVacancies(state, { allVacancies: [mockOpenVacancy, ...mockVacancies] });

expect(openVacancies.length).toEqual(2);
expect(openVacancies[0].name).toEqual(mockName);
Expand All @@ -81,7 +82,7 @@ describe('store/vacancies', () => {
applicationOpenDate: pastDate,
};

const openVacancies = getters.openVacancies(state, { vacancies: [mockOpenVacancy, ...mockVacancies] });
const openVacancies = getters.openVacancies(state, { allVacancies: [mockOpenVacancy, ...mockVacancies] });

expect(openVacancies.length).toEqual(2);
expect(openVacancies[0].name).toEqual(mockName);
Expand All @@ -91,7 +92,7 @@ describe('store/vacancies', () => {
it('returns only future vacancies', () => {
getStaticVacancies.mockReturnValue([]);

const futureVacancies = getters.futureVacancies(state, { vacancies: mockVacancies });
const futureVacancies = getters.futureVacancies(state, { allVacancies: mockVacancies });

expect(futureVacancies.length).toEqual(1);
expect(futureVacancies[0].name).toEqual('FUTURE VACANCY');
Expand All @@ -105,7 +106,7 @@ describe('store/vacancies', () => {
estimatedLaunchDate: futureDate,
};

const futureVacancies = getters.futureVacancies(state, { vacancies: [mockFutureVacancy, ...mockVacancies] });
const futureVacancies = getters.futureVacancies(state, { allVacancies: [mockFutureVacancy, ...mockVacancies] });

expect(futureVacancies.length).toEqual(2);
expect(futureVacancies[0].name).toEqual(mockName);
Expand All @@ -118,7 +119,7 @@ describe('store/vacancies', () => {
applicationOpenDate: futureDate,
};

const futureVacancies = getters.futureVacancies(state, { vacancies: [mockFutureVacancy, ...mockVacancies] });
const futureVacancies = getters.futureVacancies(state, { allVacancies: [mockFutureVacancy, ...mockVacancies] });

expect(futureVacancies.length).toEqual(2);
expect(futureVacancies[0].name).toEqual(mockName);
Expand All @@ -129,7 +130,7 @@ describe('store/vacancies', () => {
it('returns only exercises in progress', () => {
getStaticVacancies.mockReturnValue([]);

const inProgressVacancies = getters.inProgressVacancies(state, { vacancies: mockVacancies });
const inProgressVacancies = getters.inProgressVacancies(state, { allVacancies: mockVacancies });

expect(inProgressVacancies.length).toEqual(1);
expect(inProgressVacancies[0].name).toEqual('PROGRESS VACANCY');
Expand All @@ -143,7 +144,7 @@ describe('store/vacancies', () => {
applicationOpenDate: pastDate,
};

const inProgressVacancies = getters.inProgressVacancies(state, { vacancies: [mockInProgressVacancy, ...mockVacancies] });
const inProgressVacancies = getters.inProgressVacancies(state, { allVacancies: [mockInProgressVacancy, ...mockVacancies] });

expect(inProgressVacancies.length).toEqual(1);
expect(inProgressVacancies[0].name).toEqual('PROGRESS VACANCY');
Expand Down