|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace AmirHossein5\LaravelComponents\Tests\Feature; |
| 4 | + |
| 5 | +use AmirHossein5\LaravelComponents\Tests\TestCase; |
| 6 | + |
| 7 | +class PaginationTest extends TestCase |
| 8 | +{ |
| 9 | + public function test_pagination_component_renders_correctly() |
| 10 | + { |
| 11 | + $blade = $this->blade( |
| 12 | + '<x-pagination::gray-circled :elems="$users"/>', |
| 13 | + ['users' => $this->makePagination()] |
| 14 | + ); |
| 15 | + |
| 16 | + $blade->assertSee('Showing'); |
| 17 | + $blade->assertSee('results'); |
| 18 | + $blade->assertSee('?page=4'); |
| 19 | + } |
| 20 | + |
| 21 | + public function test_prev_and_next_will_change() |
| 22 | + { |
| 23 | + $blade = $this->blade( |
| 24 | + '<x-pagination::gray-circled :elems="$users" prev="prev" next="next"/>', |
| 25 | + ['users' => $this->makePagination()] |
| 26 | + ); |
| 27 | + |
| 28 | + $blade->assertSee('prev'); |
| 29 | + $blade->assertSee('next'); |
| 30 | + $blade->assertDontSee('d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"'); |
| 31 | + } |
| 32 | + |
| 33 | + public function test_prev_in_responsive_and_next_in_responsive_will_change() |
| 34 | + { |
| 35 | + $blade = $this->blade( |
| 36 | + '<x-pagination::gray-circled |
| 37 | + :elems="$users" |
| 38 | + prevInResponsive="prevInResponsive" |
| 39 | + nextInResponsive="nextInResponsive" |
| 40 | + />', |
| 41 | + ['users' => $this->makePagination()] |
| 42 | + ); |
| 43 | + |
| 44 | + $blade->assertSee('prevInResponsive'); |
| 45 | + $blade->assertSee('nextInResponsive'); |
| 46 | + $blade->assertDontSee('&laquo; Previous'); |
| 47 | + $blade->assertDontSee('Next &raquo;'); |
| 48 | + } |
| 49 | + |
| 50 | + public function test_showDisabledButtons_works() |
| 51 | + { |
| 52 | + $blade = $this->blade( |
| 53 | + '<x-pagination::gray-circled :elems="$users" :showDisabledButtons="false"/>', |
| 54 | + ['users' => $this->makePagination()] |
| 55 | + ); |
| 56 | + |
| 57 | + $blade->assertDontSee('first-button'); |
| 58 | + |
| 59 | + $blade = $this->blade( |
| 60 | + '<x-pagination::gray-circled :elems="$users" :showDisabledButtons="false"/>', |
| 61 | + ['users' => $this->makePagination(false, 3)] |
| 62 | + ); |
| 63 | + |
| 64 | + $blade->assertSee('first-button'); |
| 65 | + $blade->assertSee('last-button'); |
| 66 | + |
| 67 | + $blade = $this->blade( |
| 68 | + '<x-pagination::gray-circled :elems="$users" :showDisabledButtons="false"/>', |
| 69 | + ['users' => $this->makePagination(false, 5)] |
| 70 | + ); |
| 71 | + |
| 72 | + $blade->assertDontSee('last-button'); |
| 73 | + } |
| 74 | + |
| 75 | + public function test_show_paginator_details_can_disable_showing_pagination_details() |
| 76 | + { |
| 77 | + $blade = $this->blade( |
| 78 | + '<x-pagination::gray-circled :elems="$users" :showPaginatorDetails="false"/>', |
| 79 | + ['users' => $this->makePagination()] |
| 80 | + ); |
| 81 | + |
| 82 | + $blade->assertDontSee('Showing'); |
| 83 | + $blade->assertDontSee('results'); |
| 84 | + } |
| 85 | + |
| 86 | + public function test_class_can_be_added_to_component() |
| 87 | + { |
| 88 | + $blade = $this->blade( |
| 89 | + '<x-pagination::gray-circled :elems="$users" class="test"/>', |
| 90 | + ['users' => $this->makePagination()] |
| 91 | + ); |
| 92 | + |
| 93 | + $blade->assertSee('test"', false); |
| 94 | + } |
| 95 | + |
| 96 | + public function test_default_setted_variables_are_changeable() |
| 97 | + { |
| 98 | + $blade = $this->blade( |
| 99 | + '<x-pagination::gray :elems="$users"/>', |
| 100 | + ['users' => $this->makePagination()] |
| 101 | + ); |
| 102 | + |
| 103 | + $blade->assertDontSee('first-button', false); |
| 104 | + |
| 105 | + $blade = $this->blade( |
| 106 | + '<x-pagination::gray :elems="$users" :showDisabledButtons="true"/>', |
| 107 | + ['users' => $this->makePagination()] |
| 108 | + ); |
| 109 | + |
| 110 | + $blade->assertSee('first-button', false); |
| 111 | + |
| 112 | + $blade = $this->blade( |
| 113 | + '<x-pagination::gray-circled :elems="$users"/>', |
| 114 | + ['users' => $this->makePagination()] |
| 115 | + ); |
| 116 | + |
| 117 | + $blade->assertSee('first-button', false); |
| 118 | + |
| 119 | + $blade = $this->blade( |
| 120 | + '<x-pagination::gray-circled :elems="$users" :showDisabledButtons="false"/>', |
| 121 | + ['users' => $this->makePagination()] |
| 122 | + ); |
| 123 | + |
| 124 | + $blade->assertDontSee('first-button', false); |
| 125 | + } |
| 126 | + |
| 127 | + public function test_simple_pagination_view_is_different() |
| 128 | + { |
| 129 | + foreach (config('components-components.pagination') as $theme) { |
| 130 | + $blade = $this->blade( |
| 131 | + '<x-pagination::' . $theme . ' :elems="$users"/>', |
| 132 | + ['users' => $this->makePagination(true)] |
| 133 | + ); |
| 134 | + |
| 135 | + $blade->assertDontSee('hidden sm:flex-1 sm:flex sm:items-center sm:justify-between'); |
| 136 | + }; |
| 137 | + } |
| 138 | + |
| 139 | + public function test_themes_load_correctly() |
| 140 | + { |
| 141 | + foreach ($this->uniqueContent['pagination'] as $theme => $contents) { |
| 142 | + $blade = $this->blade( |
| 143 | + '<x-pagination::' . $theme . ' :elems="$users"/>', |
| 144 | + ['users' => $this->makePagination()] |
| 145 | + ); |
| 146 | + foreach ($contents as $content) { |
| 147 | + $blade->assertSee($content, false); |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | +} |
0 commit comments