feat: add ability to favorite contacts (#1691)

This commit is contained in:
Régis Freyd
2018-08-17 00:03:02 +02:00
committed by Alexis Saettler
parent 5aa3afa08a
commit 1d35dea8b8
20 changed files with 288 additions and 78 deletions
+3 -1
View File
@@ -1,5 +1,7 @@
UNRELEASED CHANGES:
* Add ability to set a contact as favorite
* Add ability to search for a contact in the dropdown when creating a relationship
* Add activity reports page, which shows useful statistics about activities with a specific contact
* Fix reminders not being sent for single-digit hours
* Fix accounts with an empty reminder time
@@ -8,7 +10,7 @@ UNRELEASED CHANGES:
* Add end-2-end testing with Cypress
* Render timezone listbox dynamically
* Use a new formatter to display money (debts), with right locale handle
* Get first existing gravatar of all emails of the contact
* Get first existing gravatar if contact has multiple emails
RELEASED VERSIONS:
@@ -108,6 +108,7 @@ class ApiContactController extends ApiController
'food_preferencies',
'linkedin_profile_url',
'first_met_through_contact_id',
'is_starred',
'is_partial',
'is_dead',
'deceased_date',
@@ -304,6 +305,7 @@ class ApiContactController extends ApiController
'first_met_date_is_year_unknown' => 'boolean',
'first_met_date_age' => 'nullable|integer',
'first_met_through_contact_id' => 'nullable|integer',
'is_starred' => 'required|boolean',
'is_partial' => 'required|boolean',
'is_dead' => 'required|boolean',
'deceased_date' => 'nullable|date',
@@ -70,8 +70,19 @@ class ContactsController extends Controller
$contacts = $user->account->contacts()->real()->sortedBy($sort)->get();
}
// starred contacts
$starredContacts = $contacts->filter(function ($item) {
return $item->is_starred === true;
});
$unstarredContacts = $contacts->filter(function ($item) {
return $item->is_starred === false;
});
return view('people.index')
->withContacts($contacts->unique('id'))
->withUnstarredContacts($unstarredContacts)
->withStarredContacts($starredContacts)
->withTags($tags)
->withUserTags(auth()->user()->account->tags)
->withUrl($url)
@@ -499,4 +510,22 @@ class ContactsController extends Controller
return $frequency;
}
/**
* Toggle favorites of a contact.
* @param Request $request
* @param Contact $contact
* @return array
*/
public function favorite(Request $request, Contact $contact)
{
$bool = (bool) $request->get('toggle');
$contact->is_starred = $bool;
$contact->save();
return [
'is_starred' => $bool,
];
}
}
+1
View File
@@ -24,6 +24,7 @@ class Contact extends Resource
'last_name' => $this->last_name,
'nickname' => $this->nickname,
'gender' => $this->gender->name,
'is_starred' => (bool) $this->is_starred,
'is_partial' => (bool) $this->is_partial,
'is_dead' => (bool) $this->is_dead,
'last_called' => $this->when(! $this->is_partial, $this->getLastCalled()),
@@ -24,6 +24,7 @@ class ContactWithContactFields extends Resource
'last_name' => $this->last_name,
'nickname' => $this->nickname,
'gender' => $this->gender->name,
'is_starred' => (bool) $this->is_starred,
'is_partial' => (bool) $this->is_partial,
'is_dead' => (bool) $this->is_dead,
'last_called' => $this->when(! $this->is_partial, $this->getLastCalled()),
+1
View File
@@ -117,6 +117,7 @@ class Contact extends Model
'is_partial' => 'boolean',
'is_dead' => 'boolean',
'has_avatar' => 'boolean',
'is_starred' => 'boolean',
];
/**
@@ -0,0 +1,20 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddStarredToContacts extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('contacts', function (Blueprint $table) {
$table->boolean('is_starred')->after('gender_id')->default(false);
});
}
}
@@ -57,6 +57,7 @@ class FakeContentTableSeeder extends Seeder
$this->contact->first_name = $this->faker->firstName($gender);
$this->contact->last_name = (rand(1, 2) == 1) ? $this->faker->lastName : null;
$this->contact->nickname = (rand(1, 2) == 1) ? $this->faker->name : null;
$this->contact->is_starred = (rand(1, 5) == 1) ? true : false;
$this->contact->has_avatar = false;
$this->contact->setAvatarColor();
$this->contact->save();
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,5 +1,5 @@
{
"/js/app.js": "/js/app.js?id=852f70481d1353219d58",
"/js/app.js": "/js/app.js?id=7dd1a610af425991f0ad",
"/css/app.css": "/css/app.css?id=10b48a582263122f8bc7",
"/css/stripe.css": "/css/stripe.css?id=64c68c04c4e475fcc7c6",
"/js/vendor.js": "/js/vendor.js?id=490bf428af4c7224b600",
+2
View File
@@ -72,6 +72,8 @@ Monica allows people to keep track of everything that's important about their fr
* Export and import of data
* Export a contact as vCard
* Ability to set custom genders
* Ability to define custom activity types
* Ability to favorite contacts
* Multi users
* Labels to organize contacts
* Ability to define what section should appear on the contact sheet
+5
View File
@@ -93,6 +93,11 @@ Vue.component(
);
// Contacts
Vue.component(
'contact-favorite',
require('./components/people/SetFavorite.vue')
);
Vue.component(
'contact-address',
require('./components/people/Addresses.vue')
@@ -0,0 +1,77 @@
<style scoped>
</style>
<template>
<div class="di relative" style="top: 2px">
<notifications group="favorite" position="top middle" duration="5000" width="400" />
<svg v-tooltip.top="$t('people.set_favorite')" :cy-name="'set-favorite'" class="pointer" @click="store(true)" v-if="!isFavorite" width="23" height="22" viewBox="0 0 23 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14.6053 7.404L14.7224 7.68675L15.0275 7.7111C16.7206 7.84628 18.1486 7.92359 19.2895 7.98536C19.9026 8.01855 20.4327 8.04725 20.8765 8.07803C21.5288 8.12327 21.9886 8.17235 22.2913 8.24003C22.3371 8.25027 22.3765 8.26035 22.4102 8.27001C22.3896 8.29619 22.3651 8.32572 22.336 8.35877C22.1328 8.58945 21.7914 8.89714 21.2913 9.31475C20.9474 9.60184 20.5299 9.93955 20.0459 10.331C19.1625 11.0455 18.0577 11.9391 16.7762 13.0302L16.543 13.2288L16.614 13.5267C17.0045 15.1663 17.3689 16.5406 17.6601 17.6391C17.819 18.2381 17.956 18.7552 18.0638 19.1886C18.2209 19.8206 18.3149 20.2704 18.3428 20.5768C18.347 20.6222 18.3493 20.6616 18.3505 20.6957C18.3176 20.6838 18.2798 20.6688 18.2367 20.6502C17.9532 20.5277 17.5539 20.2981 17.0014 19.9522C16.6264 19.7175 16.1833 19.4306 15.671 19.099C14.7143 18.4797 13.5162 17.7042 12.0695 16.8199L11.8087 16.6604L11.5478 16.82C10.0753 17.7209 8.86032 18.5085 7.89223 19.136C7.3851 19.4648 6.94572 19.7496 6.57253 19.9838C6.01576 20.3332 5.61353 20.5656 5.32808 20.6899C5.28721 20.7077 5.25111 20.7222 5.21941 20.7339C5.22088 20.7009 5.22355 20.663 5.22783 20.6197C5.25839 20.3111 5.35605 19.8582 5.51781 19.2225C5.62627 18.7962 5.76269 18.2914 5.92018 17.7087C6.22053 16.5972 6.59748 15.2024 7.00309 13.5286L7.07553 13.2297L6.84141 13.0303C5.52399 11.9079 4.39683 10.9982 3.50024 10.2747C3.03915 9.90254 2.63904 9.57963 2.30539 9.30232C1.80195 8.88388 1.45729 8.57562 1.25116 8.34437C1.22315 8.31293 1.19929 8.28466 1.17903 8.25939C1.20999 8.25084 1.24557 8.24198 1.28628 8.233C1.58841 8.1663 2.048 8.11835 2.701 8.07418C3.1353 8.0448 3.65101 8.01744 4.24568 7.98589C5.39523 7.9249 6.83989 7.84824 8.56208 7.71111L8.86638 7.68688L8.98388 7.40514C9.61646 5.88824 10.1238 4.58366 10.5314 3.53571C10.7656 2.93365 10.9668 2.4163 11.1399 1.99205C11.3854 1.39027 11.5751 0.972355 11.7339 0.708729C11.7601 0.66516 11.7838 0.628777 11.8048 0.598565C11.8256 0.628571 11.849 0.664658 11.8748 0.707817C12.0327 0.971308 12.2212 1.38911 12.465 1.99089C12.6368 2.41509 12.8365 2.93242 13.0689 3.53445C13.4735 4.58244 13.9771 5.88709 14.6053 7.404Z" fill="#D9D8D8" fill-opacity="0.25" stroke="#C6C6C6"/>
</svg>
<svg class="pointer" @click="store(false)" :cy-name="'unset-favorite'" v-if="isFavorite" width="23" height="22" viewBox="0 0 23 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14.6053 7.404L14.7224 7.68675L15.0275 7.7111C16.7206 7.84628 18.1486 7.92359 19.2895 7.98536C19.9026 8.01855 20.4327 8.04725 20.8765 8.07803C21.5288 8.12327 21.9886 8.17235 22.2913 8.24003C22.3371 8.25027 22.3765 8.26035 22.4102 8.27001C22.3896 8.29619 22.3651 8.32572 22.336 8.35877C22.1328 8.58945 21.7914 8.89714 21.2913 9.31475C20.9474 9.60184 20.5299 9.93955 20.0459 10.331C19.1625 11.0455 18.0577 11.9391 16.7762 13.0302L16.543 13.2288L16.614 13.5267C17.0045 15.1663 17.3689 16.5406 17.6601 17.6391C17.819 18.2381 17.956 18.7552 18.0638 19.1886C18.2209 19.8206 18.3149 20.2704 18.3428 20.5768C18.347 20.6222 18.3493 20.6616 18.3505 20.6957C18.3176 20.6838 18.2798 20.6688 18.2367 20.6502C17.9532 20.5277 17.5539 20.2981 17.0014 19.9522C16.6264 19.7175 16.1833 19.4306 15.671 19.099C14.7143 18.4797 13.5162 17.7042 12.0695 16.8199L11.8087 16.6604L11.5478 16.82C10.0753 17.7209 8.86032 18.5085 7.89223 19.136C7.3851 19.4648 6.94572 19.7496 6.57253 19.9838C6.01576 20.3332 5.61353 20.5656 5.32808 20.6899C5.28721 20.7077 5.25111 20.7222 5.21941 20.7339C5.22088 20.7009 5.22355 20.663 5.22783 20.6197C5.25839 20.3111 5.35605 19.8582 5.51781 19.2225C5.62627 18.7962 5.76269 18.2914 5.92018 17.7087C6.22053 16.5972 6.59748 15.2024 7.00309 13.5286L7.07553 13.2297L6.84141 13.0303C5.52399 11.9079 4.39683 10.9982 3.50024 10.2747C3.03915 9.90254 2.63904 9.57963 2.30539 9.30232C1.80195 8.88388 1.45729 8.57562 1.25116 8.34437C1.22315 8.31293 1.19929 8.28466 1.17903 8.25939C1.20999 8.25084 1.24557 8.24198 1.28628 8.233C1.58841 8.1663 2.048 8.11835 2.701 8.07418C3.1353 8.0448 3.65101 8.01744 4.24568 7.98589C5.39523 7.9249 6.83989 7.84824 8.56208 7.71111L8.86638 7.68688L8.98388 7.40514C9.61646 5.88824 10.1238 4.58366 10.5314 3.53571C10.7656 2.93365 10.9668 2.4163 11.1399 1.99205C11.3854 1.39027 11.5751 0.972355 11.7339 0.708729C11.7601 0.66516 11.7838 0.628777 11.8048 0.598565C11.8256 0.628571 11.849 0.664658 11.8748 0.707817C12.0327 0.971308 12.2212 1.38911 12.465 1.99089C12.6368 2.41509 12.8365 2.93242 13.0689 3.53445C13.4735 4.58244 13.9771 5.88709 14.6053 7.404Z" fill="#F2C94C" stroke="#DCBB58"/>
</svg>
</div>
</template>
<script>
export default {
/*
* The component's data.
*/
data() {
return {
isFavorite: false,
dirltr: true,
};
},
/**
* Prepare the component (Vue 1.x).
*/
ready() {
this.prepareComponent();
},
/**
* Prepare the component (Vue 2.x).
*/
mounted() {
this.prepareComponent();
},
props: {
hash: {
type: String,
},
starred: {
type: Boolean,
},
},
methods: {
/**
* Prepare the component.
*/
prepareComponent() {
this.dirltr = $('html').attr('dir') == 'ltr';
this.isFavorite = this.starred;
},
store(toggle) {
axios.post('/people/' + this.hash + '/favorite', {'toggle': toggle})
.then(response => {
this.isFavorite = response.data.is_starred
this.$notify({
group: 'main',
title: this.$t('app.default_save_success'),
text: '',
type: 'success'
});
});
},
}
}
</script>
+1
View File
@@ -62,6 +62,7 @@ return [
// Header
'edit_contact_information' => 'Edit contact information',
'call_button' => 'Log a call',
'set_favorite' => 'Favorite contacts are placed at the top of the contact list',
// Stay in touch
'stay_in_touch' => 'Stay in touch',
+4 -1
View File
@@ -27,7 +27,10 @@
@endif
<h3 class="{{ \App\Helpers\LocaleHelper::getDirection() }}">
{{ $contact->name }}
<span class="mr1">{{ $contact->name }}</span>
<contact-favorite hash="{!! $contact->hashID() !!}" :starred="{{ json_encode($contact->is_starred) }}"></contact-favorite>
@if ($contact->birthday_special_date_id && !($contact->is_dead))
@if ($contact->birthdate->getAge())
<span class="ml3 light-silver f4">(<i class="fa fa-birthday-cake mr1"></i> {{ $contact->birthdate->getAge() }})</span>
+50 -17
View File
@@ -69,21 +69,22 @@
<div class="col-xs-12 col-md-9 mb4">
@if (! is_null($tags))
<p class="clear-filter">
{{ trans('people.people_list_filter_tag') }}
@foreach ($tags as $tag)
<span class="pretty-tag">
{{ $tag->name }}
</span>
@endforeach
<a class="{{ \App\Helpers\LocaleHelper::getDirection() }}" href="{{ route('people.index') }}">{{ trans('people.people_list_clear_filter') }}</a>
</p>
<p class="clear-filter">
{{ trans('people.people_list_filter_tag') }}
@foreach ($tags as $tag)
<span class="pretty-tag">
{{ $tag->name }}
</span>
@endforeach
<a class="{{ \App\Helpers\LocaleHelper::getDirection() }}" href="{{ route('people.index') }}">{{ trans('people.people_list_clear_filter') }}</a>
</p>
@endif
@if ($tagLess)
<p class="clear-filter">
<span class="mr2">{{ trans('people.people_list_filter_untag') }}</span>
<a class="{{ \App\Helpers\LocaleHelper::getDirection() }}" href="{{ route('people.index') }}">{{ trans('people.people_list_clear_filter') }}</a>
</p>
<p class="clear-filter">
<span class="mr2">{{ trans('people.people_list_filter_untag') }}</span>
<a class="{{ \App\Helpers\LocaleHelper::getDirection() }}" href="{{ route('people.index') }}">{{ trans('people.people_list_clear_filter') }}</a>
</p>
@endif
<ul class="list">
@@ -91,7 +92,6 @@
{{-- Sorting options --}}
<li class="people-list-item sorting">
{{ trans_choice('people.people_list_stats', $contacts->count(), ['count' => $contacts->count()]) }}
<div class="options {{ \App\Helpers\LocaleHelper::getDirection() }}">
<div class="options-dropdowns">
<a href="" class="dropdown-btn" data-toggle="dropdown" id="dropdownSort">{{ trans('people.people_list_sort') }}</a>
@@ -121,11 +121,44 @@
</a>
</div>
</div>
</div>
</li>
@foreach($contacts as $contact)
@foreach($starredContacts as $contact)
<li class="people-list-item bg-white pointer" @click="window.location.href='{{ route('people.show', $contact) }}'">
@if ($contact->has_avatar)
<img src="{{ $contact->getAvatarURL(110) }}" width="43">
@else
@if (! is_null($contact->gravatar_url))
<img src="{{ $contact->gravatar_url }}" width="43">
@else
@if (strlen($contact->getInitials()) == 1)
<div class="avatar one-letter" style="background-color: {{ $contact->getAvatarColor() }};">
{{ $contact->getInitials() }}
</div>
@else
<div class="avatar {{ \App\Helpers\LocaleHelper::getDirection() }}" style="background-color: {{ $contact->getAvatarColor() }};">
{{ $contact->getInitials() }}
</div>
@endif
@endif
@endif
<span class="people-list-item-name">
<span class="mr1">{{ $contact->name }}</span>
<svg class="relative" style="top: 5px" width="23" height="22" viewBox="0 0 23 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14.6053 7.404L14.7224 7.68675L15.0275 7.7111C16.7206 7.84628 18.1486 7.92359 19.2895 7.98536C19.9026 8.01855 20.4327 8.04725 20.8765 8.07803C21.5288 8.12327 21.9886 8.17235 22.2913 8.24003C22.3371 8.25027 22.3765 8.26035 22.4102 8.27001C22.3896 8.29619 22.3651 8.32572 22.336 8.35877C22.1328 8.58945 21.7914 8.89714 21.2913 9.31475C20.9474 9.60184 20.5299 9.93955 20.0459 10.331C19.1625 11.0455 18.0577 11.9391 16.7762 13.0302L16.543 13.2288L16.614 13.5267C17.0045 15.1663 17.3689 16.5406 17.6601 17.6391C17.819 18.2381 17.956 18.7552 18.0638 19.1886C18.2209 19.8206 18.3149 20.2704 18.3428 20.5768C18.347 20.6222 18.3493 20.6616 18.3505 20.6957C18.3176 20.6838 18.2798 20.6688 18.2367 20.6502C17.9532 20.5277 17.5539 20.2981 17.0014 19.9522C16.6264 19.7175 16.1833 19.4306 15.671 19.099C14.7143 18.4797 13.5162 17.7042 12.0695 16.8199L11.8087 16.6604L11.5478 16.82C10.0753 17.7209 8.86032 18.5085 7.89223 19.136C7.3851 19.4648 6.94572 19.7496 6.57253 19.9838C6.01576 20.3332 5.61353 20.5656 5.32808 20.6899C5.28721 20.7077 5.25111 20.7222 5.21941 20.7339C5.22088 20.7009 5.22355 20.663 5.22783 20.6197C5.25839 20.3111 5.35605 19.8582 5.51781 19.2225C5.62627 18.7962 5.76269 18.2914 5.92018 17.7087C6.22053 16.5972 6.59748 15.2024 7.00309 13.5286L7.07553 13.2297L6.84141 13.0303C5.52399 11.9079 4.39683 10.9982 3.50024 10.2747C3.03915 9.90254 2.63904 9.57963 2.30539 9.30232C1.80195 8.88388 1.45729 8.57562 1.25116 8.34437C1.22315 8.31293 1.19929 8.28466 1.17903 8.25939C1.20999 8.25084 1.24557 8.24198 1.28628 8.233C1.58841 8.1663 2.048 8.11835 2.701 8.07418C3.1353 8.0448 3.65101 8.01744 4.24568 7.98589C5.39523 7.9249 6.83989 7.84824 8.56208 7.71111L8.86638 7.68688L8.98388 7.40514C9.61646 5.88824 10.1238 4.58366 10.5314 3.53571C10.7656 2.93365 10.9668 2.4163 11.1399 1.99205C11.3854 1.39027 11.5751 0.972355 11.7339 0.708729C11.7601 0.66516 11.7838 0.628777 11.8048 0.598565C11.8256 0.628571 11.849 0.664658 11.8748 0.707817C12.0327 0.971308 12.2212 1.38911 12.465 1.99089C12.6368 2.41509 12.8365 2.93242 13.0689 3.53445C13.4735 4.58244 13.9771 5.88709 14.6053 7.404Z" fill="#F2C94C" stroke="#DCBB58"/>
</svg>
</span>
<span class="people-list-item-information {{ \App\Helpers\LocaleHelper::getDirection() }}">
{{ trans('people.people_list_last_updated') }} {{ \App\Helpers\DateHelper::getShortDate($contact->last_consulted_at) }}
</span>
</li>
@endforeach
@foreach($unstarredContacts as $contact)
<li class="people-list-item bg-white pointer" @click="window.location.href='{{ route('people.show', $contact) }}'">
@if ($contact->has_avatar)
@@ -159,7 +192,7 @@
</div>
<div class="col-xs-12 col-md-3 sidebar">
<a href="{{ route('people.create') }}" class="btn btn-primary sidebar-cta">
<a href="{{ route('people.create') }}" id="button-add-contact" class="btn btn-primary sidebar-cta">
{{ trans('people.people_list_blank_cta') }}
</a>
+3
View File
@@ -177,6 +177,9 @@ Route::middleware(['auth', 'auth.confirm', 'u2f', '2fa'])->group(function () {
// Stay in touch information
Route::post('/people/{contact}/stayintouch', 'ContactsController@stayInTouch');
// Set favorite
Route::post('/people/{contact}/favorite', 'ContactsController@favorite');
// Activities
Route::get('/people/{contact}/activities', 'Contacts\\ActivitiesController@index')->name('activities.index');
Route::get('/people/{contact}/activities/{year}', 'Contacts\\ActivitiesController@year')->name('activities.year');
@@ -22,6 +22,7 @@ class ApiContactControllerTest extends ApiTestCase
'last_name',
'nickname',
'gender',
'is_starred',
'is_partial',
'is_dead',
'last_called',
@@ -81,6 +82,7 @@ class ApiContactControllerTest extends ApiTestCase
'first_name',
'last_name',
'gender',
'is_starred',
'is_partial',
'is_dead',
'last_called',
@@ -511,6 +513,7 @@ class ApiContactControllerTest extends ApiTestCase
'nickname',
'is_partial',
'is_dead',
'is_starred',
]) + [
'gender_id' => $contact->gender_id,
'birthdate' => '2008-10-25',
@@ -566,6 +569,7 @@ class ApiContactControllerTest extends ApiTestCase
'nickname',
'is_partial',
'is_dead',
'is_starred',
]) + [
'gender_id' => $contact->gender_id,
'birthdate_age' => '18',
+81 -56
View File
@@ -3,67 +3,92 @@ describe('Contacts', function () {
cy.login()
})
it('lets you add a contact', function () {
// it('lets you add a contact', function () {
// cy.createContact('John', 'Doe', 'Man')
// cy.url().should('include', '/people/h:')
// cy.get('h3').should('contain', 'John Doe')
// })
// it('lets you add two contacts in a row', function () {
// cy.createContact('John', 'Doe', 'Man', 'save_and_add_another')
// cy.url().should('include', '/people/add')
// })
// it('requires at least a firstname and a gender to add a contact', function () {
// cy.visit('/people')
// cy.get('#button-add-contact').click()
// cy.get('button[name=save]').click()
// cy.url().should('include', '/people/add')
// cy.get('input[name=first_name]').type('John')
// cy.get('button[name=save]').click()
// cy.url().should('include', '/people/add')
// cy.get('select[name=gender]').select('Man')
// cy.get('button[name=save]').click()
// cy.url().should('include', '/people/h:')
// cy.get('h3').should('contain', 'John')
// })
// it('lets you edit a contact', function () {
// cy.createContact('John', 'Doe', 'Man')
// cy.get('#button-edit-contact').click();
// cy.url().should('include', '/edit')
// cy.get('input[name=firstname]').should('have.value', 'John')
// cy.get('input[name=lastname]').should('have.value', 'Doe')
// cy.get('select[name=gender]').should('have.value', '1')
// cy.get('input[name=firstname]').clear()
// cy.get('input[name=firstname]').type('Jane')
// cy.get('input[name=lastname]').clear()
// cy.get('button[name=save]').click()
// cy.url().should('include', '/people/h:')
// cy.get('h3').should('contain', 'Jane')
// })
// it('lets you delete a contact', function () {
// cy.createContact('John', 'Doe', 'Man')
// cy.visit('/people')
// cy.get('.people-list-item-name').should('contain', 'John Doe')
// cy.visit('/people/1')
// cy.get('#link-delete-contact').click()
// // cypress auto accepts window alerts (confirm or alert)
// cy.url().should('include', '/people')
// cy.visit('/people')
// cy.get('.people-list-item-name').should('not.exist')
// })
it('lets you add a contact as favorite', function () {
cy.createContact('John', 'Doe', 'Man')
cy.url().should('include', '/people/h:')
cy.get('h3').should('contain', 'John Doe')
})
it('lets you add two contacts in a row', function () {
cy.createContact('John', 'Doe', 'Man', 'save_and_add_another')
cy.url().should('include', '/people/add')
})
it('requires at least a firstname and a gender to add a contact', function () {
cy.visit('/people')
cy.get('#button-add-contact').click()
cy.get('button[name=save]').click()
cy.url().should('include', '/people/add')
cy.get('input[name=first_name]').type('John')
cy.get('button[name=save]').click()
cy.url().should('include', '/people/add')
cy.get('select[name=gender]').select('Man')
cy.get('button[name=save]').click()
cy.url().should('include', '/people/h:')
cy.get('h3').should('contain', 'John')
})
it('lets you edit a contact', function () {
cy.createContact('John', 'Doe', 'Man')
cy.get('#button-edit-contact').click();
cy.url().should('include', '/edit')
cy.get('input[name=firstname]').should('have.value', 'John')
cy.get('input[name=lastname]').should('have.value', 'Doe')
cy.get('select[name=gender]').should('have.value', '1')
cy.get('input[name=firstname]').clear()
cy.get('input[name=firstname]').type('Jane')
cy.get('input[name=lastname]').clear()
cy.get('button[name=save]').click()
cy.url().should('include', '/people/h:')
cy.get('h3').should('contain', 'Jane')
})
it('lets you delete a contact', function () {
cy.createContact('John', 'Doe', 'Man')
cy.visit('/people')
cy.get('.people-list-item-name').should('contain', 'John Doe')
cy.visit('/people/1')
cy.get('#link-delete-contact').click()
// cypress auto accepts window alerts (confirm or alert)
cy.url().should('include', '/people')
// tests if the favorite button can be toggled
cy.get('[cy-name=set-favorite]').should('be.visible')
cy.get('[cy-name=set-favorite]').click()
cy.get('[cy-name=set-favorite]').should('not.be.visible')
cy.get('[cy-name=unset-favorite]').should('be.visible')
cy.get('[cy-name=unset-favorite]').click()
cy.get('[cy-name=set-favorite]').should('be.visible')
// test to see if a contact appears on top of the contact list if favorited
cy.get('[cy-name=set-favorite]').click()
cy.visit('/dashboard')
cy.createContact('Abc', 'Abc', 'Man')
cy.visit('/people')
cy.get('.people-list-item-name').should('not.exist')
cy.get('.people-list-item-name span').should('contain', 'John Doe')
cy.get('.people-list-item-name svg').should('be.visible')
cy.get('.list > li:nth-child(3) > span.people-list-item-name').should('contain', 'Abc Abc')
})
})