Skip to content

Commit

Permalink
feat: display contract info on employee profile page (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss committed Feb 2, 2021
1 parent 75c8327 commit 8e87749
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 28 deletions.
11 changes: 11 additions & 0 deletions app/Http/ViewHelpers/Employee/EmployeeShowViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function informationAboutEmployee(Employee $employee, array $permi
$address = $employee->getCurrentAddress();
$company = $employee->company;
$teams = $employee->teams;
$rate = $employee->consultantRates()->where('active', true)->first();

return [
'id' => $employee->id,
Expand Down Expand Up @@ -66,6 +67,11 @@ public static function informationAboutEmployee(Employee $employee, array $permi
($permissions['can_see_contract_renewal_date'] ? [
'date' => DateHelper::formatDate($employee->contract_renewed_at),
] : null),
'contract_rate' => (! $rate) ? null :
($permissions['can_see_contract_renewal_date'] ? [
'rate' => $rate->rate,
'currency' => $company->currency,
] : null),
'raw_description' => $employee->description,
'parsed_description' => is_null($employee->description) ? null : StringHelper::parse($employee->description),
'address' => is_null($address) ? null : [
Expand All @@ -86,6 +92,7 @@ public static function informationAboutEmployee(Employee $employee, array $permi
'status' => (! $employee->status) ? null : [
'id' => $employee->status->id,
'name' => $employee->status->name,
'type' => $employee->status->type,
],
'teams' => ($teams->count() == 0) ? null : self::teams($teams, $company),
'url' => [
Expand All @@ -97,6 +104,10 @@ public static function informationAboutEmployee(Employee $employee, array $permi
'company' => $company,
'employee' => $employee,
]),
'edit_contract' => route('employee.show.edit.contract', [
'company' => $company,
'employee' => $employee,
]),
'lock' => route('account.lock', [
'company' => $company,
'employee' => $employee,
Expand Down
8 changes: 4 additions & 4 deletions resources/js/Pages/Employee/Edit/Contract.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
:min="1"
:max="10000"
:errors="$page.props.errors.name"
:datacy="'add-title-input'"
:datacy="'add-rate-input'"
required
:placeholder="$t('account.employee_statuses_placeholder')"
:extra-class-upper-div="'w-30 dib'"
Expand All @@ -177,15 +177,15 @@
<a class="btn dib-l db mb2 mb0-ns" @click.prevent="addRateMode = false ; form.name = ''">
{{ $t('app.cancel') }}
</a>
<loading-button :classes="'btn add w-auto-ns w-100 mb2 mb0-ns pv2 ph3'" data-cy="modal-add-cta" :state="loadingState" :text="$t('app.add')" />
<loading-button :classes="'btn add w-auto-ns w-100 mb2 mb0-ns pv2 ph3'" data-cy="modal-add-rate-cta" :state="loadingState" :text="$t('app.add')" />
</div>
</div>
</form>

<!-- list of rates -->
<ul class="list pl0 mv0 center ba br2 bb-gray">
<ul data-cy="contract-rates-list" :data-cy-items="localRates.map(r => r.id)" class="list pl0 mv0 center ba br2 bb-gray">
<!-- list of past and current rates -->
<li v-for="rate in localRates" :key="rate.id" class="pv3 ph2 bb bb-gray bb-gray-hover">
<li v-for="rate in localRates" :key="rate.id" :data-cy="'rate-item-' + rate.id" class="pv3 ph2 bb bb-gray bb-gray-hover">
{{ $t('employee.edit_contract_rate_desc', { rate: rate.rate, currency: rates.company_currency} ) }}

<!-- status -->
Expand Down
22 changes: 18 additions & 4 deletions resources/js/Pages/Employee/Partials/EmployeeStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
<span class="f6 title">
{{ $t('employee.status_title') }}
</span>

<a v-show="permissions.can_manage_status" data-cy="edit-status-button" class="bb b--dotted bt-0 bl-0 br-0 pointer di f7 ml2" @click.prevent="displayModal()">{{ $t('app.edit') }}</a>
</div>

<!-- Modal -->
Expand Down Expand Up @@ -103,15 +101,31 @@
</div>

<!-- Case when there is a status -->
<ul v-if="updatedEmployee.status" class="ma0 pa0 di existing-statuses">
<li class="di" data-cy="status-name-right-permission">
<ul v-if="updatedEmployee.status" class="ma0 pa0 di existing-statuses list">
<li class="mb2" data-cy="status-name-right-permission">
{{ updatedEmployee.status.name }}

<a v-show="permissions.can_manage_status" data-cy="edit-status-button" class="bb b--dotted bt-0 bl-0 br-0 pointer di f7 ml2" @click.prevent="displayModal()">{{ $t('app.edit') }}</a>
</li>

<!-- contract renewed at date -->
<li v-if="updatedEmployee.contract_renewed_at && permissions.can_manage_status" class="lh-copy mb1" data-cy="employee-contract-renewal-date">
{{ $t('employee.contract_renewal_date', { date: updatedEmployee.contract_renewed_at.date }) }}

<inertia-link :href="employee.url.edit_contract" class="bb b--dotted bt-0 bl-0 br-0 pointer di f7 ml2">{{ $t('app.edit') }}</inertia-link>
</li>

<!-- contract rate -->
<li v-if="updatedEmployee.contract_rate && permissions.can_manage_status" class="lh-copy mb1" data-cy="employee-contract-rate">
{{ $t('employee.contract_renewal_rate', { rate: updatedEmployee.contract_rate.rate, currency: updatedEmployee.contract_rate.currency }) }}
</li>
</ul>

<!-- Action when there is no status defined -->
<span v-else class="f6">
{{ $t('employee.status_modal_blank') }}

<a v-show="permissions.can_manage_status" data-cy="edit-status-button" class="bb b--dotted bt-0 bl-0 br-0 pointer di f7 ml2" @click.prevent="displayModal()">{{ $t('app.edit') }}</a>
</span>
</div>
</template>
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/en/employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@

'contacts_title' => 'Contact information',

'contract_renewal_date' => 'Contract renewed on',
'contract_renewal_date' => 'Contract renews on {date}',
'contract_renewal_rate' => '{currency} {rate} per hour',

'work_from_home_title' => 'Work from home',
'work_from_home_link' => 'View history',
Expand Down
4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
Route::get('{employee}/logs', 'Company\\Employee\\EmployeeLogsController@index')->name('employee.show.logs');

Route::get('{employee}/edit', 'Company\\Employee\\EmployeeEditController@show')->name('employee.show.edit');
Route::get('{employee}/address/edit', 'Company\\Employee\\EmployeeEditController@address');
Route::get('{employee}/contract/edit', 'Company\\Employee\\EmployeeEditController@contract');
Route::get('{employee}/address/edit', 'Company\\Employee\\EmployeeEditController@address')->name('employee.show.edit.address');
Route::get('{employee}/contract/edit', 'Company\\Employee\\EmployeeEditController@contract')->name('employee.show.edit.contract');
Route::post('{employee}/contract/update', 'Company\\Employee\\EmployeeEditController@updateContractInformation');
Route::post('{employee}/update', 'Company\\Employee\\EmployeeEditController@update');
Route::post('{employee}/address/update', 'Company\\Employee\\EmployeeEditController@updateAddress');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Employee - manage contract renewal date information', function () {
it('should let an admin edit a contract renewal date', function () {
describe('Employee - manage contract information', function () {
it('should let an admin edit contract information', function () {
cy.loginLegacy();

cy.createCompany();
Expand All @@ -13,6 +13,7 @@ describe('Employee - manage contract renewal date information', function () {
// make sure the employee profile page doesn't contain any information about the contract renewal date
cy.visit('/1/employees/1');
cy.get('[data-cy=employee-contract-renewal-date]').should('not.exist');
cy.get('[data-cy=employee-contract-rate]').should('not.exist');

// make sure the edit profile page doesn't show the "Contract" tab
cy.visit('/1/employees/1/edit');
Expand All @@ -35,26 +36,44 @@ describe('Employee - manage contract renewal date information', function () {
cy.get('[data-cy=menu-contract-link]').should('exist');
cy.get('[data-cy=menu-contract-link]').click();
cy.setContractRenewalDate(1, 1, 3);
cy.setContractRate(1, 1, 100);

// check on the employee profile page that the date is there
cy.visit('/1/employees/1');
cy.get('[data-cy=employee-contract-renewal-date]').should('exist');
cy.get('[data-cy=employee-contract-rate]').should('exist');

// the contract renewal date is very close - it should also appear on the dashboard
cy.visit('/1/dashboard/me');
cy.get('[data-cy=contract-renewal]').should('exist');

// change the contract renewal date in a very far future and the date shouldn't appear on the dashboard
cy.setContractRenewalDate(1, 1, 35);

cy.visit('/1/dashboard/me');
cy.get('[data-cy=contract-renewal]').should('not.exist');

cy.visit('/1/employees/1/contract/edit');

// destroy the contract rate
cy.get('[data-cy=contract-rates-list]', { timeout: 500 })
.invoke('attr', 'data-cy-items').then(function (items) {
let rateId = _.last(items.split(','));

cy.get('[data-cy=list-delete-button-' + rateId + ']').click();
cy.get('[data-cy=list-delete-confirm-button-' + rateId + ']').click();

cy.get('[data-cy=rate-item-' + rateId + ']').should('not.exist');
});

// check that the renewal date is not displayed anymore on the employee profile page
cy.get('[data-cy=employee-contract-renewal-date]').should('not.exist');
cy.get('[data-cy=employee-contract-rate]').should('not.exist');

// remove the contract renewal date entirely
cy.visit('/1/employees/1');
cy.get('[data-cy=edit-status-button').click();
cy.get('[data-cy=status-reset-button]').click();
cy.visit('/1/employees/1');

// check that the renewal date is not displayed anymore on the employee profile page
cy.get('[data-cy=employee-contract-renewal-date]').should('not.exist');

// check that the renewal date is not displayed anymore on the employee dashboard
cy.visit('/1/dashboard/me');
Expand All @@ -64,7 +83,7 @@ describe('Employee - manage contract renewal date information', function () {
cy.visit('/1/employees/1');
});

it('should let an HR edit a contract renewal date', function () {
it('should let an HR edit contract information', function () {
cy.loginLegacy();

cy.createCompany();
Expand All @@ -80,6 +99,7 @@ describe('Employee - manage contract renewal date information', function () {
// make sure the employee profile page doesn't contain any information about the contract renewal date
cy.visit('/1/employees/1');
cy.get('[data-cy=employee-contract-renewal-date]').should('not.exist');
cy.get('[data-cy=employee-contract-rate]').should('not.exist');

// make sure the edit profile page doesn't show the "Contract" tab
cy.visit('/1/employees/1/edit');
Expand All @@ -102,28 +122,44 @@ describe('Employee - manage contract renewal date information', function () {
cy.get('[data-cy=menu-contract-link]').should('exist');
cy.get('[data-cy=menu-contract-link]').click();
cy.setContractRenewalDate(1, 1, 3);

cy.wait(100);
cy.setContractRate(1, 1, 100);

// check on the employee profile page that the date is there
cy.visit('/1/employees/1');
cy.get('[data-cy=employee-contract-renewal-date]').should('exist');
cy.get('[data-cy=employee-contract-rate]').should('exist');

// the contract renewal date is very close - it should also appear on the dashboard
cy.visit('/1/dashboard/me');
cy.get('[data-cy=contract-renewal]').should('exist');

// change the contract renewal date in a very far future and the date shouldn't appear on the dashboard
cy.setContractRenewalDate(1, 1, 35);

cy.visit('/1/dashboard/me');
cy.get('[data-cy=contract-renewal]').should('not.exist');

cy.visit('/1/employees/1/contract/edit');

// destroy the contract rate
cy.get('[data-cy=contract-rates-list]', { timeout: 500 })
.invoke('attr', 'data-cy-items').then(function (items) {
let rateId = _.last(items.split(','));

cy.get('[data-cy=list-delete-button-' + rateId + ']').click();
cy.get('[data-cy=list-delete-confirm-button-' + rateId + ']').click();

cy.get('[data-cy=rate-item-' + rateId + ']').should('not.exist');
});

// check that the renewal date is not displayed anymore on the employee profile page
cy.get('[data-cy=employee-contract-renewal-date]').should('not.exist');
cy.get('[data-cy=employee-contract-rate]').should('not.exist');

// remove the contract renewal date entirely
cy.visit('/1/employees/1');
cy.get('[data-cy=edit-status-button').click();
cy.get('[data-cy=status-reset-button]').click();
cy.visit('/1/employees/1');

// check that the renewal date is not displayed anymore on the employee profile page
cy.get('[data-cy=employee-contract-renewal-date]').should('not.exist');

// check that the renewal date is not displayed anymore on the employee dashboard
cy.visit('/1/dashboard/me');
Expand All @@ -133,7 +169,7 @@ describe('Employee - manage contract renewal date information', function () {
cy.visit('/1/employees/1');
});

it('should not let a normal user edit a contract renewal date', function () {
it('should not let a normal user edit contract information', function () {
cy.loginLegacy();

cy.createCompany();
Expand All @@ -145,7 +181,7 @@ describe('Employee - manage contract renewal date information', function () {
cy.url().should('include', '/home');
});

it('should not let a normal user edit someone elses contract renewal date', function () {
it('should not let a normal user edit someone elses contract information', function () {
cy.loginLegacy();

cy.createCompany();
Expand Down
10 changes: 10 additions & 0 deletions tests/Features/support/helpers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ Cypress.Commands.add('setContractRenewalDate', (companyId = 1, employeeId = 1, n
cy.get('[data-cy=submit-edit-contract-employee-button]').click();
});

// Set the contract rate
Cypress.Commands.add('setContractRate', (companyId = 1, employeeId = 1, rate = 10) => {
cy.visit('/' + companyId + '/employees/' + employeeId + '/contract/edit');

cy.get('[data-cy=add-rate-button]').click();
cy.get('[data-cy=add-rate-input]').clear();
cy.get('[data-cy=add-rate-input]').type(rate);
cy.get('[data-cy=modal-add-rate-cta]').click();
});

// fill and submit timesheet for time tracking
Cypress.Commands.add('fillAndSubmitTimesheet', (companyId = 1) => {
cy.visit('/' + companyId + '/dashboard/timesheet');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Unit\Services\Company\Employee\Birthdate;
namespace Tests\Unit\Services\Company\Employee\ConsultantRate;

use Carbon\Carbon;
use Tests\TestCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Unit\Services\Company\Employee\Birthdate;
namespace Tests\Unit\Services\Company\ConsultantRate\Birthdate;

use Carbon\Carbon;
use Tests\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function it_gets_the_information_about_the_employee(): void
$this->assertArrayHasKey('slack_handle', $array);
$this->assertArrayHasKey('hired_at', $array);
$this->assertArrayHasKey('contract_renewed_at', $array);
$this->assertArrayHasKey('contract_rate', $array);
$this->assertArrayHasKey('email', $array);
$this->assertArrayHasKey('phone', $array);
$this->assertArrayHasKey('locked', $array);
Expand Down

0 comments on commit 8e87749

Please sign in to comment.