-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ContactShowViewHelperTest.php
126 lines (113 loc) · 4.27 KB
/
ContactShowViewHelperTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace Tests\Unit\Domains\Contact\ManageContact\Web\ViewHelpers;
use App\Domains\Contact\ManageContact\Web\ViewHelpers\ContactShowViewHelper;
use App\Models\Contact;
use App\Models\Module;
use App\Models\Template;
use App\Models\TemplatePage;
use App\Models\User;
use App\Models\Vault;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use function env;
class ContactShowViewHelperTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_gets_the_data_needed_for_the_view(): void
{
$contact = Contact::factory()->create();
$user = User::factory()->create();
$vault = Vault::factory()->create([
'account_id' => $user->account_id,
]);
$contact = Contact::factory()->create([
'vault_id' => $vault->id,
]);
$vault->users()->save($user, [
'permission' => 1,
'contact_id' => $contact->id,
]);
$template = Template::factory()->create();
TemplatePage::factory()->create([
'template_id' => $template->id,
'type' => TemplatePage::TYPE_CONTACT,
'position' => 1,
]);
$templatePage = TemplatePage::factory()->create([
'template_id' => $template->id,
'position' => 2,
]);
$contact->template_id = $template->id;
$contact->save();
$array = ContactShowViewHelper::data($contact, $user);
$this->assertEquals(
10,
count($array)
);
$this->assertArrayHasKey('contact_name', $array);
$this->assertArrayHasKey('listed', $array);
$this->assertArrayHasKey('template_pages', $array);
$this->assertArrayHasKey('contact_information', $array);
$this->assertArrayHasKey('group_summary_information', $array);
$this->assertArrayHasKey('quick_fact_template_entries', $array);
$this->assertArrayHasKey('modules', $array);
$this->assertArrayHasKey('options', $array);
$this->assertArrayHasKey('avatar', $array);
$this->assertArrayHasKey('url', $array);
$this->assertEquals(
[
1 => [
'id' => $templatePage->id,
'name' => $templatePage->name,
'selected' => true,
'url' => [
'show' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id.'/tabs/'.$templatePage->slug,
],
],
],
$array['template_pages']->toArray()
);
$this->assertEquals(
$contact->listed,
$array['listed']
);
$this->assertEquals(
[
'toggle_archive' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id.'/toggle',
'update_template' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id.'/update-template',
'destroy' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id,
'update_avatar' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id.'/avatar',
'move_contact' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id.'/move',
'destroy_avatar' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id.'/avatar',
],
$array['url']
);
}
/** @test */
public function it_gets_the_modules_in_a_given_page(): void
{
$contact = Contact::factory()->create();
$user = User::factory()->create();
$templatePage = TemplatePage::factory()->create([
'position' => 2,
]);
$module = Module::factory()->create([
'type' => Module::TYPE_NOTES,
]);
$templatePage->modules()->syncWithoutDetaching($module);
$collection = ContactShowViewHelper::modules($templatePage, $contact, $user);
$this->assertEquals(
1,
$collection->count()
);
$this->assertEquals(
$module->id,
$collection[0]['id']
);
$this->assertEquals(
$module->type,
$collection[0]['type']
);
}
}