AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

StoreStyleTest.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace Tests\Feature\Stores;
  3. use App\Models\Store;
  4. use App\Models\User;
  5. use App\StorePlan\PlanSchema;
  6. use App\StorePlan\PlanValidator;
  7. use App\StorePlan\SamplePlan;
  8. use Illuminate\Foundation\Testing\RefreshDatabase;
  9. use Inertia\Testing\AssertableInertia as Assert;
  10. use Tests\Support\ScriptedDriver;
  11. use Tests\TestCase;
  12. class StoreStyleTest extends TestCase
  13. {
  14. use RefreshDatabase;
  15. private User $user;
  16. private Store $store;
  17. protected function setUp(): void
  18. {
  19. parent::setUp();
  20. $this->user = User::factory()->create();
  21. $this->store = Store::factory()->for($this->user)->create();
  22. $this->store->plan = SamplePlan::for($this->store);
  23. $this->store->save();
  24. $this->actingAs($this->user);
  25. }
  26. public function test_a_ready_made_look_sets_style_fonts_and_corners_but_keeps_colours()
  27. {
  28. $colours = $this->store->plan['theme']['colors'];
  29. $this->put(route('stores.style.update', $this->store->slug), ['preset' => 'bold'])
  30. ->assertRedirect(route('stores.show', $this->store->slug));
  31. $theme = $this->store->fresh()->plan['theme'];
  32. $bold = PlanSchema::STYLE_PRESETS['bold'];
  33. $this->assertSame($bold['style'], $theme['style']);
  34. $this->assertSame($bold['fonts'], $theme['fonts']);
  35. $this->assertSame('none', $theme['radius']);
  36. $this->assertSame($colours, $theme['colors']);
  37. $this->get(route('stores.show', $this->store->slug))
  38. ->assertInertia(fn (Assert $page) => $page
  39. ->where('style.options.buttons', 'shadow')
  40. ->where('style.fonts.heading', 'archivo-black')
  41. ->has('stylePresets', count(PlanSchema::STYLE_PRESETS)));
  42. }
  43. public function test_one_option_can_be_fine_tuned()
  44. {
  45. $this->put(route('stores.style.update', $this->store->slug), ['style' => ['spacing' => 'airy']])->assertSessionHasNoErrors();
  46. $style = $this->store->fresh()->plan['theme']['style'];
  47. $this->assertSame('airy', $style['spacing']);
  48. // The others keep their values.
  49. $this->assertSame('shadow', $style['cards']);
  50. $this->put(route('stores.style.update', $this->store->slug), ['style' => ['spacing' => 'enormous']])->assertSessionHasErrors('style.spacing');
  51. $this->put(route('stores.style.update', $this->store->slug), ['preset' => 'retro-80s'])->assertSessionHasErrors('preset');
  52. $this->actingAs(User::factory()->create())
  53. ->put(route('stores.style.update', $this->store->slug), ['preset' => 'bold'])
  54. ->assertNotFound();
  55. }
  56. public function test_old_designs_without_a_style_still_pass_and_look_the_same()
  57. {
  58. $plan = $this->store->plan;
  59. unset($plan['theme']['style']);
  60. $clean = app(PlanValidator::class)->validate($plan);
  61. $this->assertArrayNotHasKey('style', $clean['theme']);
  62. $this->store->plan = $clean;
  63. $this->store->save();
  64. $this->get(route('stores.show', $this->store->slug))
  65. ->assertInertia(fn (Assert $page) => $page->where('style.options', PlanSchema::STYLE_DEFAULTS));
  66. }
  67. public function test_the_checker_refuses_unknown_styles_and_heading_fonts_for_body_text()
  68. {
  69. $validator = app(PlanValidator::class);
  70. $plan = $this->store->plan;
  71. $this->assertFalse($validator->passes([...$plan, 'theme' => [...$plan['theme'], 'style' => ['buttons' => 'neon']]]));
  72. $this->assertFalse($validator->passes([...$plan, 'theme' => [...$plan['theme'], 'fonts' => ['heading' => 'inter', 'body' => 'bebas-neue']]]));
  73. $this->assertTrue($validator->passes([...$plan, 'theme' => [...$plan['theme'], 'fonts' => ['heading' => 'bebas-neue', 'body' => 'jost']]]));
  74. // Unknown style parts are thrown away.
  75. $clean = $validator->validate([...$plan, 'theme' => [...$plan['theme'], 'style' => ['cards' => 'hard', 'sparkles' => 'yes']]]);
  76. $this->assertSame(['cards' => 'hard'], $clean['theme']['style']);
  77. }
  78. public function test_the_ai_can_change_the_style_by_chat()
  79. {
  80. ScriptedDriver::use([(string) json_encode([
  81. 'reply' => 'I made the store bolder.',
  82. 'theme' => ['style' => ['buttons' => 'shadow', 'headings' => 'heavy'], 'fonts' => ['heading' => 'unbounded']],
  83. ])]);
  84. $this->post(route('stores.edits', $this->store->slug), ['instruction' => 'Make it look bolder and more futuristic']);
  85. $theme = $this->store->fresh()->plan['theme'];
  86. $this->assertSame('shadow', $theme['style']['buttons']);
  87. $this->assertSame('heavy', $theme['style']['headings']);
  88. // Untouched parts stay.
  89. $this->assertSame('alternate', $theme['style']['backgrounds']);
  90. $this->assertSame('unbounded', $theme['fonts']['heading']);
  91. $this->assertStringContainsString('These fonts are for headings only', ScriptedDriver::$requests[0]->system);
  92. }
  93. }