HomePageTest.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. use Illuminate\Support\Facades\Mail;
  3. use Illuminate\Support\Str;
  4. use Webkul\Core\Models\SubscribersList;
  5. use Webkul\Customer\Models\CompareItem;
  6. use Webkul\Faker\Helpers\Product as ProductFaker;
  7. use Webkul\Shop\Mail\Customer\SubscriptionNotification;
  8. use function Pest\Laravel\deleteJson;
  9. use function Pest\Laravel\get;
  10. use function Pest\Laravel\postJson;
  11. it('returns a successful response', function () {
  12. // Act and Assert.
  13. get(route('shop.home.index'))
  14. ->assertOk();
  15. });
  16. it('displays the current currency code and channel code', function () {
  17. // Act
  18. $response = get(route('shop.home.index'));
  19. // Assert
  20. $response->assertOk();
  21. /**
  22. * We avoid using the `assertSeeText` method of the response because it may sometimes
  23. * produce false positive results when dealing with large DOM sizes.
  24. */
  25. expect(Str::contains($response->content(), core()->getCurrentChannelCode()))
  26. ->toBeTruthy();
  27. expect(Str::contains($response->content(), core()->getCurrentCurrencyCode()))
  28. ->toBeTruthy();
  29. });
  30. it('displays the "Sign In" and "Sign Up" buttons when the customer is not logged in', function () {
  31. // Act
  32. $response = get(route('shop.home.index'));
  33. // Assert
  34. $response->assertOk();
  35. /**
  36. * We avoid using the `assertSeeText` method of the response because it may sometimes
  37. * produce false positive results when dealing with large DOM sizes.
  38. */
  39. expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.sign-in')))
  40. ->toBeTruthy();
  41. expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.sign-up')))
  42. ->toBeTruthy();
  43. });
  44. it('displays navigation buttons when the customer is logged in', function () {
  45. // Act
  46. $this->loginAsCustomer();
  47. $response = get(route('shop.home.index'));
  48. // Assert
  49. $response->assertOk();
  50. /**
  51. * We avoid using the `assertSeeText` method of the response because it may sometimes
  52. * produce false positive results when dealing with large DOM sizes.
  53. */
  54. expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.profile')))
  55. ->toBeTruthy();
  56. expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.orders')))
  57. ->toBeTruthy();
  58. expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.wishlist')))
  59. ->toBeTruthy();
  60. expect(Str::contains($response->content(), trans('shop::app.components.layouts.header.desktop.bottom.logout')))
  61. ->toBeTruthy();
  62. });
  63. it('should returns the home page of the store', function () {
  64. get(route('shop.home.index'))
  65. ->assertOk()
  66. ->assertSeeText('The game with our new additions!')
  67. ->assertSeeText('Our Collections')
  68. ->assertSeeText('Get Ready for our new Bold Collections!')
  69. ->assertSeeText('Get UPTO 40% OFF on your 1st order SHOP NOW');
  70. });
  71. it('should returns the search page of the products', function () {
  72. // Arrange.
  73. $product = (new ProductFaker([
  74. 'attributes' => [
  75. 5 => 'new',
  76. 6 => 'featured',
  77. 11 => 'price',
  78. 26 => 'guest_checkout',
  79. ],
  80. 'attribute_value' => [
  81. 'new' => [
  82. 'boolean_value' => true,
  83. ],
  84. 'featured' => [
  85. 'boolean_value' => true,
  86. ],
  87. 'price' => [
  88. 'float_value' => fake()->randomFloat(2, 1000, 5000),
  89. ],
  90. 'guest_checkout' => [
  91. 'boolean_value' => true,
  92. ],
  93. ],
  94. ]))->getSimpleProductFactory()->create();
  95. // Act and Assert.
  96. get(route('shop.search.index', [
  97. 'query' => $query = $product->name,
  98. ]))
  99. ->assertOk()
  100. ->assertSeeText($query)
  101. ->assertSeeText(trans('shop::app.search.title', ['query' => $query]));
  102. });
  103. it('should fails the validation error when provided wrong email address when subscribe to the shop', function () {
  104. // Act and Assert.
  105. postJson(route('shop.subscription.store'))
  106. ->assertJsonValidationErrorFor('email')
  107. ->assertUnprocessable();
  108. });
  109. it('should store the subscription of the shop', function () {
  110. // Act and Assert.
  111. postJson(route('shop.subscription.store'), [
  112. 'email' => $email = fake()->email(),
  113. ])
  114. ->assertRedirect();
  115. $this->assertModelWise([
  116. SubscribersList::class => [
  117. [
  118. 'email' => $email,
  119. 'is_subscribed' => 1,
  120. ],
  121. ],
  122. ]);
  123. });
  124. it('should store the subscription of the shop and send the mail to the admin', function () {
  125. // Act and Assert.
  126. Mail::fake();
  127. postJson(route('shop.subscription.store'), [
  128. 'email' => $email = fake()->email(),
  129. ])
  130. ->assertRedirect();
  131. $this->assertModelWise([
  132. SubscribersList::class => [
  133. [
  134. 'email' => $email,
  135. 'is_subscribed' => 1,
  136. ],
  137. ],
  138. ]);
  139. Mail::assertQueued(SubscriptionNotification::class);
  140. Mail::assertQueuedCount(1);
  141. });
  142. it('should unsubscribe from the shop', function () {
  143. // Arrange.
  144. $subscriber = SubscribersList::factory()->create();
  145. // Act and Assert.
  146. get(route('shop.subscription.destroy', [
  147. 'token' => $subscriber->token,
  148. ]))
  149. ->assertRedirect();
  150. $this->assertDatabaseMissing('subscribers_list', [
  151. 'id' => $subscriber->id,
  152. ]);
  153. });
  154. it('should store the products to the compare list', function () {
  155. // Arrange.
  156. $product = (new ProductFaker([
  157. 'attributes' => [
  158. 5 => 'new',
  159. 6 => 'featured',
  160. 11 => 'price',
  161. 26 => 'guest_checkout',
  162. ],
  163. 'attribute_value' => [
  164. 'new' => [
  165. 'boolean_value' => true,
  166. ],
  167. 'featured' => [
  168. 'boolean_value' => true,
  169. ],
  170. 'price' => [
  171. 'float_value' => fake()->randomFloat(2, 1000, 5000),
  172. ],
  173. 'guest_checkout' => [
  174. 'boolean_value' => true,
  175. ],
  176. ],
  177. ]))->getSimpleProductFactory()->create();
  178. // Act and Assert.
  179. $this->loginAsCustomer();
  180. postJson(route('shop.api.compare.store'), [
  181. 'product_id' => $product->id,
  182. ])
  183. ->assertOk()
  184. ->assertSeeText(trans('shop::app.compare.item-add-success'));
  185. });
  186. it('should fails the validation error when not provided product id when move the compare list item', function () {
  187. // Act and Assert.
  188. $this->loginAsCustomer();
  189. postJson(route('shop.api.compare.store'))
  190. ->assertJsonValidationErrorFor('product_id')
  191. ->assertUnprocessable();
  192. });
  193. it('should remove product from compare list', function () {
  194. // Arrange.
  195. $product = (new ProductFaker([
  196. 'attributes' => [
  197. 5 => 'new',
  198. 6 => 'featured',
  199. 11 => 'price',
  200. 26 => 'guest_checkout',
  201. ],
  202. 'attribute_value' => [
  203. 'new' => [
  204. 'boolean_value' => true,
  205. ],
  206. 'featured' => [
  207. 'boolean_value' => true,
  208. ],
  209. 'price' => [
  210. 'float_value' => fake()->randomFloat(2, 1000, 5000),
  211. ],
  212. 'guest_checkout' => [
  213. 'boolean_value' => true,
  214. ],
  215. ],
  216. ]))->getSimpleProductFactory()->create();
  217. // Act and Assert.
  218. $this->loginAsCustomer();
  219. CompareItem::factory()->create([
  220. 'customer_id' => auth()->guard('customer')->user()->id,
  221. 'product_id' => $product->id,
  222. ]);
  223. deleteJson(route('shop.api.compare.destroy'), [
  224. 'product_id' => $product->id,
  225. ])
  226. ->assertOk()
  227. ->assertJsonPath('message', trans('shop::app.compare.remove-success'));
  228. });
  229. it('should remove all the products from compare list', function () {
  230. // Arrange.
  231. $products = (new ProductFaker([
  232. 'attributes' => [
  233. 5 => 'new',
  234. 6 => 'featured',
  235. 11 => 'price',
  236. 26 => 'guest_checkout',
  237. ],
  238. 'attribute_value' => [
  239. 'new' => [
  240. 'boolean_value' => true,
  241. ],
  242. 'featured' => [
  243. 'boolean_value' => true,
  244. ],
  245. 'price' => [
  246. 'float_value' => fake()->randomFloat(2, 1000, 5000),
  247. ],
  248. 'guest_checkout' => [
  249. 'boolean_value' => true,
  250. ],
  251. ],
  252. ]))->getSimpleProductFactory()->count(5)->create();
  253. // Act and Assert.
  254. $this->loginAsCustomer();
  255. foreach ($products as $product) {
  256. CompareItem::factory()->create([
  257. 'customer_id' => auth()->guard('customer')->user()->id,
  258. 'product_id' => $product->id,
  259. ]);
  260. }
  261. deleteJson(route('shop.api.compare.destroy_all'))
  262. ->assertOk()
  263. ->assertJsonPath('data.message', trans('shop::app.compare.remove-all-success'));
  264. });