Skip to content

Commit 394a575

Browse files
Playwright tests + readme update (#32)
1 parent 3026166 commit 394a575

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+497
-19
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
images export-ignore
2+
tests/playwright/**/*.png filter=lfs diff=lfs merge=lfs -text

.github/workflows/playwright.yml

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
name: Playwright
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- '*.x'
8+
pull_request:
9+
schedule:
10+
- cron: '0 0 * * *'
11+
workflow_dispatch:
12+
inputs:
13+
update_all_screenshots:
14+
description: 'Update all screenshots?'
15+
type: boolean
16+
17+
env:
18+
PACKAGE: reviews
19+
20+
jobs:
21+
test:
22+
timeout-minutes: 60
23+
runs-on: ubuntu-latest
24+
25+
defaults:
26+
run:
27+
working-directory: ./rapidez/rapidez
28+
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
include:
33+
- magento-version: 2.4.7-p7
34+
magento-php-version: php83-fpm
35+
rapidez-php-version: 8.3
36+
- magento-version: 2.4.8-p2
37+
magento-php-version: php84-fpm
38+
rapidez-php-version: 8.4
39+
screenshots: true
40+
41+
services:
42+
magento:
43+
image: michielgerritsen/magento-project-community-edition:${{matrix.magento-php-version}}-magento${{matrix.magento-version}}-sample-data
44+
env:
45+
URL: http://localhost:1234/
46+
FLAT_TABLES: true
47+
CUSTOM_ENTRYPOINT_COMMAND: "php bin/magento encryption:key:change -k 5AM3SD5SkwT8iwIxL6L1q8XQhzK3wk51; magerun2 config:store:set system/smtp/disable 1; magerun2 config:store:set checkout/options/enable_guest_checkout_login 1"
48+
ports:
49+
- 3307:3306
50+
- 1234:80
51+
52+
elasticsearch:
53+
image: docker.elastic.co/elasticsearch/elasticsearch:8.18.2
54+
ports:
55+
- 9200:9200
56+
env:
57+
discovery.type: single-node
58+
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
59+
http.cors.enabled: "true"
60+
http.cors.allow-credentials: "true"
61+
http.cors.allow-origin: "http://localhost:8000"
62+
http.cors.allow-headers: X-Requested-With, X-Auth-Token, Content-Type, Content-Length, Authorization, Access-Control-Allow-Headers, Accept
63+
xpack.security.enabled: "false"
64+
options: >-
65+
--health-cmd="curl http://localhost:9200/_cluster/health"
66+
--health-interval=10s
67+
--health-timeout=5s
68+
--health-retries=10
69+
70+
name: P${{ matrix.rapidez-php-version }} - M${{matrix.magento-version}} on ${{matrix.magento-php-version}}
71+
72+
steps:
73+
- uses: actions/checkout@v4
74+
with:
75+
path: rapidez/${{ env.PACKAGE }}
76+
fetch-depth: 0
77+
lfs: true
78+
79+
- uses: actions/checkout@v4
80+
with:
81+
repository: rapidez/rapidez
82+
path: rapidez/rapidez
83+
84+
- uses: actions/setup-node@v4
85+
with:
86+
node-version: lts/*
87+
88+
- name: Setup PHP
89+
uses: shivammathur/setup-php@v2
90+
with:
91+
php-version: ${{ matrix.rapidez-php-version }}
92+
extensions: mbstring, dom, fileinfo, mysql
93+
coverage: none
94+
95+
- name: Copy testing .env
96+
run: cp ../$PACKAGE/tests/playwright/.env.testing .env
97+
98+
- name: Use Rapidez package from source
99+
run: composer config repositories.$PACKAGE path ../$PACKAGE
100+
101+
- name: Get commit hash and tag of the package
102+
working-directory: ./rapidez/${{ env.PACKAGE }}
103+
run: |
104+
echo "PACKAGE_HASH=$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse HEAD | sed 's|/|_|g')" >> $GITHUB_ENV
105+
echo "LATEST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
106+
107+
- name: Composer require the local rapidez package
108+
run: composer require rapidez/$PACKAGE:"dev-${{ env.PACKAGE_HASH }} as ${{ env.LATEST_TAG }}"
109+
110+
- name: Publish Rapidez configs
111+
run: php artisan vendor:publish --provider="Rapidez\Core\RapidezServiceProvider" --tag="config"
112+
113+
- name: Install Rapidez command
114+
run: php artisan rapidez:install --frontendonly
115+
116+
- name: Install Yarn dependencies
117+
run: npm install -g yarn && yarn
118+
119+
- name: Install Playwright Browsers
120+
run: yarn playwright install --with-deps
121+
122+
- name: Frontend Build
123+
run: yarn run prod
124+
125+
- name: Install Playwright tests
126+
run: |
127+
cp -r vendor/rapidez/$PACKAGE/tests/playwright tests/playwright
128+
cp vendor/rapidez/$PACKAGE/playwright.config.js playwright.config.js
129+
130+
- name: Wait for index to finish
131+
run: for i in {1..60}; do [[ $(mysql -h 127.0.0.1 -P 3307 -u magento -ppassword -ss -r -e "CALL sys.table_exists('magento', 'catalog_product_flat_1', @exists); SELECT @exists;") == *"BASE TABLE"* ]] && break || sleep 5; done
132+
133+
- name: Rapidez index
134+
run: php artisan rapidez:index
135+
136+
- name: Start the webserver
137+
run: php artisan serve &
138+
139+
- name: Run Playwright tests
140+
run: yarn playwright test
141+
142+
# Screenshots
143+
- name: Collect failed tests
144+
if: (failure() || inputs.update_all_screenshots)
145+
run: yarn playwright test --last-failed --list --reporter=dot --pass-with-no-tests > failed-tests.txt
146+
147+
- name: Update screenshots
148+
if: failure() && matrix.screenshots == true && github.event_name != 'schedule' && !(github.event_name == 'push' && (github.ref_name == 'master' || endsWith(github.ref_name, '.x')))
149+
run: |
150+
while read -r test_name; do
151+
yarn playwright test "$test_name" --update-snapshots --reporter=list
152+
done < <(awk -F ' › ' 'NF>1{print $2}' failed-tests.txt | sort -u)
153+
154+
- name: Update all screenshots
155+
if: ${{ inputs.update_all_screenshots && matrix.screenshots == true }}
156+
run: yarn playwright test --update-snapshots --reporter=list
157+
158+
- name: Move the screenshots
159+
if: (failure() || inputs.update_all_screenshots) && matrix.screenshots == true && github.event_name != 'schedule' && !(github.event_name == 'push' && (github.ref_name == 'master' || endsWith(github.ref_name, '.x')))
160+
run: cp -r tests/playwright/. ../$PACKAGE/tests/playwright/
161+
162+
- name: Commit the screenshots
163+
if: (failure() || inputs.update_all_screenshots) && matrix.screenshots == true && github.event_name != 'schedule' && !(github.event_name == 'push' && (github.ref_name == 'master' || endsWith(github.ref_name, '.x')))
164+
uses: stefanzweifel/git-auto-commit-action@v4
165+
with:
166+
commit_message: "[CI] Update Snapshots"
167+
repository: rapidez/${{ env.PACKAGE }}
168+
169+
# Artifact
170+
- name: Dump docker logs
171+
if: failure()
172+
uses: jwalton/gh-docker-logs@v2
173+
with:
174+
dest: './docker-logs'
175+
176+
- name: Dump magento logs
177+
if: failure()
178+
working-directory: ${{ github.workspace }}
179+
run: |
180+
mkdir -p magento/var
181+
docker cp ${{ job.services.magento.id }}:/data/var/log magento/var/log
182+
183+
- name: Upload Artifact
184+
if: failure()
185+
uses: actions/upload-artifact@v4
186+
with:
187+
name: artifact-P${{ matrix.rapidez-php-version }}-M${{matrix.magento-version}}-on-${{matrix.magento-php-version}}
188+
path: |
189+
rapidez/rapidez/blob-report
190+
rapidez/rapidez/storage/logs/laravel.log
191+
docker-logs
192+
magento/var/log
193+
194+
report:
195+
if: failure()
196+
needs: [test]
197+
runs-on: ubuntu-latest
198+
env:
199+
HTML_REPORT_PATH: ${{ github.repository }}/${{ github.ref_name }}/${{ github.run_id }}/${{ github.run_attempt }}
200+
201+
steps:
202+
- uses: actions/checkout@v4
203+
with:
204+
repository: rapidez/playwright-reports
205+
206+
- uses: actions/setup-node@v4
207+
with:
208+
node-version: lts/*
209+
210+
- name: Install dependencies
211+
run: npm install
212+
213+
- name: Download artifacts
214+
uses: actions/download-artifact@v4
215+
with:
216+
path: ./reports
217+
merge-multiple: true
218+
219+
- name: Generate HTML report
220+
run: npx playwright merge-reports --reporter html ./reports/rapidez/rapidez/blob-report
221+
222+
- name: Upload Artifact
223+
uses: actions/upload-artifact@v4
224+
with:
225+
name: playwright-report
226+
path: playwright-report
227+
228+
- name: Push the new files to github pages
229+
uses: peaceiris/actions-gh-pages@v3
230+
with:
231+
personal_token: ${{ secrets.RAPIDEZ_ACTIONS_ACCOUNT_PAT }}
232+
external_repository: rapidez/playwright-reports
233+
publish_dir: ./playwright-report
234+
destination_dir: ${{ env.HTML_REPORT_PATH }}
235+
236+
- name: URL in summary
237+
run: echo "### Test results - https://${{ github.repository_owner }}.github.io/playwright-reports/${{ env.HTML_REPORT_PATH }}/" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
composer.lock
22
vendor
3+
yarn.lock
4+
5+
# Playwright
6+
node_modules/
7+
/test-results/
8+
/playwright-report/
9+
/blob-report/
10+
/playwright/.cache/
11+
/tests/playwright/**/*-darwin.png

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Rapidez Reviews
22

3+
![](images/pdp-review-stars.png)
4+
![](images/pdp-with-reviews.png)
5+
![](images/pdp-reviews-form.png)
6+
![](images/pdp-without-reviews.png)
7+
![](images/product-tile-reviews.png)
8+
39
## Installation
410

511
```bash
@@ -23,27 +29,31 @@ If you'd like to show product reviews on out-of-stock product pages you need to
2329

2430
Add the stars where you'd like in `resources/views/vendor/rapidez/product/overview.blade.php`:
2531
```blade
26-
@if($product->reviews_score)
27-
<x-rapidez-reviews::stars :score="$product->reviews_score" :count="$product->reviews_count" />
32+
@if (App::providerIsLoaded('Rapidez\Reviews\ReviewsServiceProvider'))
33+
@if ($product->reviews_score)
34+
<x-dynamic-component component="rapidez-reviews::stars" :score="$product->reviews_score :count="$product->reviews_count" />
35+
@endif
2836
@endif
2937
```
3038

3139
#### Review list
3240

3341
The review list can be added with:
3442
```blade
35-
@include('rapidez-reviews::reviews', [
36-
'sku' => $product->sku,
37-
'reviews_count' => $product->reviews_count,
38-
'reviews_score' => $product->reviews_score,
39-
])
43+
@if (App::providerIsLoaded('Rapidez\Reviews\ReviewsServiceProvider'))
44+
<div class="container my-5">
45+
@include('rapidez-reviews::reviews')
46+
</div>
47+
@endif
4048
```
4149

42-
#### Review form
50+
#### Microdata
4351

44-
And the form to add a review:
52+
This should be included in `resources/views/vendor/rapidez/product/overview.blade.php` inside the: `<div itemtype="https://schema.org/Product" itemscope>`
4553
```blade
46-
@include('rapidez-reviews::form', ['sku' => $product->sku])
54+
@if (App::providerIsLoaded('Rapidez\Reviews\ReviewsServiceProvider'))
55+
@include('rapidez-reviews::components.microdata')
56+
@endif
4757
```
4858

4959
### Product listing
@@ -52,8 +62,9 @@ And the form to add a review:
5262

5363
Add somewhere in `resources/views/category/partials/listing/item.blade.php`:
5464
```blade
55-
<x-rapidez-reviews::stars v-if="item.reviews_count" count="item.reviews_count" score="item.reviews_score"/>
56-
65+
@if (App::providerIsLoaded('Rapidez\Reviews\ReviewsServiceProvider'))
66+
<x-dynamic-component component="rapidez-reviews::stars" v-if="item.reviews_count" count="item.reviews_count" score="item.reviews_score" />
67+
@endif
5768
```
5869

5970
## Views

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"require": {
2020
"php": "^8.0",
2121
"blade-ui-kit/blade-icons": "^1.8",
22-
"rapidez/core": "^3.0|^4.0"
22+
"rapidez/core": "^4.7"
2323
},
2424
"autoload": {
2525
"psr-4": {

images/pdp-review-stars.png

593 KB
Loading

images/pdp-reviews-form.png

739 KB
Loading

images/pdp-with-reviews.png

280 KB
Loading

images/pdp-without-reviews.png

218 KB
Loading

images/product-tile-reviews.png

457 KB
Loading

0 commit comments

Comments
 (0)