|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | use Code16\Sharp\Form\Fields\SharpFormEditorField; |
| 4 | +use Code16\Sharp\Show\Fields\SharpShowTextField; |
4 | 5 | use Code16\Sharp\Tests\Fixtures\Entities\PersonEntity; |
5 | 6 | use Code16\Sharp\Tests\Fixtures\Entities\SinglePersonEntity; |
6 | 7 | use Code16\Sharp\Tests\Fixtures\Sharp\PersonForm; |
|
106 | 107 | ); |
107 | 108 | }); |
108 | 109 |
|
109 | | -it('uses custom labels on show leaf if configured, based on unformatted data', function () { |
| 110 | +it('uses custom labels on show leaf if configured', function () { |
110 | 111 | fakeShowFor('person', new class() extends PersonShow |
111 | 112 | { |
112 | 113 | public function buildShowConfig(): void |
@@ -139,7 +140,83 @@ public function find($id): array |
139 | 140 | ); |
140 | 141 | }); |
141 | 142 |
|
142 | | -it('uses custom labels on form leaf if configured, based on unformatted data', function () { |
| 143 | +it('uses custom labels limit on show leaf if configured', function () { |
| 144 | + fakeShowFor('person', new class() extends PersonShow |
| 145 | + { |
| 146 | + public function buildShowConfig(): void |
| 147 | + { |
| 148 | + $this->configureBreadcrumbCustomLabelAttribute('name', limit: 20); |
| 149 | + } |
| 150 | + |
| 151 | + public function find($id): array |
| 152 | + { |
| 153 | + return $this->transform([ |
| 154 | + 'id' => 1, |
| 155 | + 'name' => 'A very long name that should be limited', |
| 156 | + ]); |
| 157 | + } |
| 158 | + }); |
| 159 | + |
| 160 | + $this |
| 161 | + ->get( |
| 162 | + route('code16.sharp.show.show', [ |
| 163 | + 'parentUri' => 's-list/person/', |
| 164 | + 'person', |
| 165 | + 1, |
| 166 | + ]) |
| 167 | + ) |
| 168 | + ->assertOk() |
| 169 | + ->assertInertia(fn (Assert $page) => $page |
| 170 | + ->where('breadcrumb.items.0.label', 'List') |
| 171 | + // Data is not formatted for breadcrumb: |
| 172 | + ->where('breadcrumb.items.1.label', 'A very long name tha...') |
| 173 | + ); |
| 174 | +}); |
| 175 | + |
| 176 | +it('uses localized custom labels on show leaf if configured', function () { |
| 177 | + fakeShowFor('person', new class() extends PersonShow |
| 178 | + { |
| 179 | + public function buildShowFields(FieldsContainer $showFields): void |
| 180 | + { |
| 181 | + $showFields->addField(SharpShowTextField::make('name')->setLocalized()); |
| 182 | + } |
| 183 | + |
| 184 | + public function buildShowConfig(): void |
| 185 | + { |
| 186 | + $this->configureBreadcrumbCustomLabelAttribute('name', localized: true); |
| 187 | + } |
| 188 | + |
| 189 | + public function find($id): array |
| 190 | + { |
| 191 | + return $this->transform([ |
| 192 | + 'id' => 1, |
| 193 | + 'name' => ['fr' => 'Marie Curie', 'en' => 'Mary Curry'], |
| 194 | + ]); |
| 195 | + } |
| 196 | + |
| 197 | + public function getDataLocalizations(): array |
| 198 | + { |
| 199 | + return ['fr', 'en']; |
| 200 | + } |
| 201 | + }); |
| 202 | + |
| 203 | + $this |
| 204 | + ->get( |
| 205 | + route('code16.sharp.show.show', [ |
| 206 | + 'parentUri' => 's-list/person/', |
| 207 | + 'person', |
| 208 | + 1, |
| 209 | + ]) |
| 210 | + ) |
| 211 | + ->assertOk() |
| 212 | + ->assertInertia(fn (Assert $page) => $page |
| 213 | + ->where('breadcrumb.items.0.label', 'List') |
| 214 | + // Data is not formatted for breadcrumb: |
| 215 | + ->where('breadcrumb.items.1.label', 'Marie Curie') |
| 216 | + ); |
| 217 | +}); |
| 218 | + |
| 219 | +it('uses custom labels on form leaf if configured', function () { |
143 | 220 | fakeFormFor('person', new class() extends PersonForm |
144 | 221 | { |
145 | 222 | public function buildFormFields(FieldsContainer $formFields): void |
@@ -176,3 +253,46 @@ public function find($id): array |
176 | 253 | ->where('breadcrumb.items.1.label', 'Edit “Marie Curie”') |
177 | 254 | ); |
178 | 255 | }); |
| 256 | + |
| 257 | +it('uses localized custom labels on form leaf if configured', function () { |
| 258 | + fakeFormFor('person', new class() extends PersonForm |
| 259 | + { |
| 260 | + public function buildFormFields(FieldsContainer $formFields): void |
| 261 | + { |
| 262 | + $formFields->addField(SharpFormEditorField::make('name')->setLocalized()); |
| 263 | + } |
| 264 | + |
| 265 | + public function buildFormConfig(): void |
| 266 | + { |
| 267 | + $this->configureBreadcrumbCustomLabelAttribute('name', localized: true); |
| 268 | + } |
| 269 | + |
| 270 | + public function find($id): array |
| 271 | + { |
| 272 | + return $this->transform([ |
| 273 | + 'id' => 1, |
| 274 | + 'name' => ['fr' => 'Marie Curie', 'en' => 'Mary Curry'], |
| 275 | + ]); |
| 276 | + } |
| 277 | + |
| 278 | + public function getDataLocalizations(): array |
| 279 | + { |
| 280 | + return ['fr', 'en']; |
| 281 | + } |
| 282 | + }); |
| 283 | + |
| 284 | + $this |
| 285 | + ->get( |
| 286 | + route('code16.sharp.form.edit', [ |
| 287 | + 'parentUri' => 's-list/person', |
| 288 | + 'person', |
| 289 | + 1, |
| 290 | + ]) |
| 291 | + ) |
| 292 | + ->assertOk() |
| 293 | + ->assertInertia(fn (Assert $page) => $page |
| 294 | + ->where('breadcrumb.items.0.label', 'List') |
| 295 | + // Data is not formatted for breadcrumb: |
| 296 | + ->where('breadcrumb.items.1.label', 'Edit “Marie Curie”') |
| 297 | + ); |
| 298 | +}); |
0 commit comments