From fa0374d6ab9595c738ea986f3bc1e6b0afc01432 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Wed, 23 Oct 2024 05:00:46 +0200 Subject: [PATCH 1/6] . --- package-lock.json | 102 +++++++++++++++++++++++++++------------------- package.json | 4 +- 2 files changed, 62 insertions(+), 44 deletions(-) diff --git a/package-lock.json b/package-lock.json index 31b1ca1b4..990224088 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "framer-motion": "11.11.9", "graphql": "^16.9.0", "lodash": "^4.17.21", - "next": "^14.2.15", + "next": "^14.2.16", "nprogress": "^0.2.0", "postcss": "^8.4.47", "react": "^18.3.1", @@ -35,7 +35,7 @@ "@typescript-eslint/eslint-plugin": "^8.11.0", "@typescript-eslint/parser": "^8.11.0", "babel-plugin-styled-components": "^2.1.4", - "eslint-config-next": "^14.2.15", + "eslint-config-next": "^14.2.16", "postcss-preset-env": "^10.0.7", "prettier": "^3.3.3", "tailwindcss": "^3.4.14", @@ -1770,11 +1770,15 @@ } }, "node_modules/@next/env": { - "version": "14.2.15", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.16.tgz", + "integrity": "sha512-fLrX5TfJzHCbnZ9YUSnGW63tMV3L4nSfhgOQ0iCcX21Pt+VSTDuaLsSuL8J/2XAiVA5AnzvXDpf6pMs60QxOag==", "license": "MIT" }, "node_modules/@next/eslint-plugin-next": { - "version": "14.2.15", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-14.2.16.tgz", + "integrity": "sha512-noORwKUMkKc96MWjTOwrsUCjky0oFegHbeJ1yEnQBGbMHAaTEIgLZIIfsYF0x3a06PiS+2TXppfifR+O6VWslg==", "dev": true, "license": "MIT", "dependencies": { @@ -1782,12 +1786,13 @@ } }, "node_modules/@next/swc-darwin-arm64": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.15.tgz", - "integrity": "sha512-Rvh7KU9hOUBnZ9TJ28n2Oa7dD9cvDBKua9IKx7cfQQ0GoYUwg9ig31O2oMwH3wm+pE3IkAQ67ZobPfEgurPZIA==", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.16.tgz", + "integrity": "sha512-uFT34QojYkf0+nn6MEZ4gIWQ5aqGF11uIZ1HSxG+cSbj+Mg3+tYm8qXYd3dKN5jqKUm5rBVvf1PBRO/MeQ6rxw==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "darwin" @@ -1797,12 +1802,13 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.15.tgz", - "integrity": "sha512-5TGyjFcf8ampZP3e+FyCax5zFVHi+Oe7sZyaKOngsqyaNEpOgkKB3sqmymkZfowy3ufGA/tUgDPPxpQx931lHg==", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.16.tgz", + "integrity": "sha512-mCecsFkYezem0QiZlg2bau3Xul77VxUD38b/auAjohMA22G9KTJneUYMv78vWoCCFkleFAhY1NIvbyjj1ncG9g==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "darwin" @@ -1812,12 +1818,13 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.15.tgz", - "integrity": "sha512-3Bwv4oc08ONiQ3FiOLKT72Q+ndEMyLNsc/D3qnLMbtUYTQAmkx9E/JRu0DBpHxNddBmNT5hxz1mYBphJ3mfrrw==", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.16.tgz", + "integrity": "sha512-yhkNA36+ECTC91KSyZcgWgKrYIyDnXZj8PqtJ+c2pMvj45xf7y/HrgI17hLdrcYamLfVt7pBaJUMxADtPaczHA==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -1827,12 +1834,13 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.15.tgz", - "integrity": "sha512-k5xf/tg1FBv/M4CMd8S+JL3uV9BnnRmoe7F+GWC3DxkTCD9aewFRH1s5rJ1zkzDa+Do4zyN8qD0N8c84Hu96FQ==", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.16.tgz", + "integrity": "sha512-X2YSyu5RMys8R2lA0yLMCOCtqFOoLxrq2YbazFvcPOE4i/isubYjkh+JCpRmqYfEuCVltvlo+oGfj/b5T2pKUA==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -1842,12 +1850,13 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.15.tgz", - "integrity": "sha512-kE6q38hbrRbKEkkVn62reLXhThLRh6/TvgSP56GkFNhU22TbIrQDEMrO7j0IcQHcew2wfykq8lZyHFabz0oBrA==", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.16.tgz", + "integrity": "sha512-9AGcX7VAkGbc5zTSa+bjQ757tkjr6C/pKS7OK8cX7QEiK6MHIIezBLcQ7gQqbDW2k5yaqba2aDtaBeyyZh1i6Q==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -1857,12 +1866,13 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.15.tgz", - "integrity": "sha512-PZ5YE9ouy/IdO7QVJeIcyLn/Rc4ml9M2G4y3kCM9MNf1YKvFY4heg3pVa/jQbMro+tP6yc4G2o9LjAz1zxD7tQ==", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.16.tgz", + "integrity": "sha512-Klgeagrdun4WWDaOizdbtIIm8khUDQJ/5cRzdpXHfkbY91LxBXeejL4kbZBrpR/nmgRrQvmz4l3OtttNVkz2Sg==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -1872,12 +1882,13 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.15.tgz", - "integrity": "sha512-2raR16703kBvYEQD9HNLyb0/394yfqzmIeyp2nDzcPV4yPjqNUG3ohX6jX00WryXz6s1FXpVhsCo3i+g4RUX+g==", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.16.tgz", + "integrity": "sha512-PwW8A1UC1Y0xIm83G3yFGPiOBftJK4zukTmk7DI1CebyMOoaVpd8aSy7K6GhobzhkjYvqS/QmzcfsWG2Dwizdg==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -1887,12 +1898,13 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.2.15", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.15.tgz", - "integrity": "sha512-fyTE8cklgkyR1p03kJa5zXEaZ9El+kDNM5A+66+8evQS5e/6v0Gk28LqA0Jet8gKSOyP+OTm/tJHzMlGdQerdQ==", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.16.tgz", + "integrity": "sha512-jhPl3nN0oKEshJBNDAo0etGMzv0j3q3VYorTSFqH1o3rwv1MQRdor27u1zhkgsHPNeY1jxcgyx1ZsCkDD1IHgg==", "cpu": [ "ia32" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -1902,7 +1914,9 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "14.2.15", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.16.tgz", + "integrity": "sha512-OA7NtfxgirCjfqt+02BqxC3MIgM/JaGjw9tOe4fyZgPsqfseNiMPnCRP44Pfs+Gpo9zPN+SXaFsgP6vk8d571A==", "cpu": [ "x64" ], @@ -3458,11 +3472,13 @@ } }, "node_modules/eslint-config-next": { - "version": "14.2.15", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-14.2.16.tgz", + "integrity": "sha512-HOcnCJsyLXR7B8wmjaCgkTSpz+ijgOyAkP8OlvANvciP8PspBYFEBTmakNMxOf71fY0aKOm/blFIiKnrM4K03Q==", "dev": true, "license": "MIT", "dependencies": { - "@next/eslint-plugin-next": "14.2.15", + "@next/eslint-plugin-next": "14.2.16", "@rushstack/eslint-patch": "^1.3.3", "@typescript-eslint/eslint-plugin": "^5.4.2 || ^6.0.0 || ^7.0.0 || ^8.0.0", "@typescript-eslint/parser": "^5.4.2 || ^6.0.0 || ^7.0.0 || ^8.0.0", @@ -5211,10 +5227,12 @@ "license": "MIT" }, "node_modules/next": { - "version": "14.2.15", + "version": "14.2.16", + "resolved": "https://registry.npmjs.org/next/-/next-14.2.16.tgz", + "integrity": "sha512-LcO7WnFu6lYSvCzZoo1dB+IO0xXz5uEv52HF1IUN0IqVTUIZGHuuR10I5efiLadGt+4oZqTcNZyVVEem/TM5nA==", "license": "MIT", "dependencies": { - "@next/env": "14.2.15", + "@next/env": "14.2.16", "@swc/helpers": "0.5.5", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", @@ -5229,15 +5247,15 @@ "node": ">=18.17.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "14.2.15", - "@next/swc-darwin-x64": "14.2.15", - "@next/swc-linux-arm64-gnu": "14.2.15", - "@next/swc-linux-arm64-musl": "14.2.15", - "@next/swc-linux-x64-gnu": "14.2.15", - "@next/swc-linux-x64-musl": "14.2.15", - "@next/swc-win32-arm64-msvc": "14.2.15", - "@next/swc-win32-ia32-msvc": "14.2.15", - "@next/swc-win32-x64-msvc": "14.2.15" + "@next/swc-darwin-arm64": "14.2.16", + "@next/swc-darwin-x64": "14.2.16", + "@next/swc-linux-arm64-gnu": "14.2.16", + "@next/swc-linux-arm64-musl": "14.2.16", + "@next/swc-linux-x64-gnu": "14.2.16", + "@next/swc-linux-x64-musl": "14.2.16", + "@next/swc-win32-arm64-msvc": "14.2.16", + "@next/swc-win32-ia32-msvc": "14.2.16", + "@next/swc-win32-x64-msvc": "14.2.16" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", diff --git a/package.json b/package.json index e3ac9299f..5bbd74293 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "framer-motion": "11.11.9", "graphql": "^16.9.0", "lodash": "^4.17.21", - "next": "^14.2.15", + "next": "^14.2.16", "nprogress": "^0.2.0", "postcss": "^8.4.47", "react": "^18.3.1", @@ -49,7 +49,7 @@ "@typescript-eslint/eslint-plugin": "^8.11.0", "@typescript-eslint/parser": "^8.11.0", "babel-plugin-styled-components": "^2.1.4", - "eslint-config-next": "^14.2.15", + "eslint-config-next": "^14.2.16", "postcss-preset-env": "^10.0.7", "prettier": "^3.3.3", "tailwindcss": "^3.4.14", From aaaca8d6f14e214aee6d424f13a16ccf8fa40a14 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Wed, 23 Oct 2024 05:16:17 +0200 Subject: [PATCH 2/6] Update playwright.config.ts --- playwright.config.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/playwright.config.ts b/playwright.config.ts index 436c1e6ae..e1d49977d 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -12,13 +12,13 @@ import { devices } from '@playwright/test'; const config: PlaywrightTestConfig = { testDir: './src/tests', /* Maximum time one test can run for. */ - timeout: 30 * 1000, + timeout: 60 * 1000, // Increased to 60 seconds expect: { /** * Maximum time expect() should wait for the condition to be met. * For example in `await expect(locator).toHaveText();` */ - timeout: 15000, + timeout: 30000, // Increased to 30 seconds }, /* Run tests in files in parallel */ fullyParallel: true, @@ -33,7 +33,7 @@ const config: PlaywrightTestConfig = { /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ - actionTimeout: 0, + actionTimeout: 30000, // Added 30 second timeout for actions /* Base URL to use in actions like `await page.goto('/')`. */ baseURL: 'http://localhost:3000', @@ -103,6 +103,7 @@ const config: PlaywrightTestConfig = { reuseExistingServer: true, command: 'npm run dev', port: 3000, + timeout: 120000, // Added 2 minute timeout for server start }, }; From fa5906cee4295075ed3c7083a6e3739983fe7e06 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Wed, 23 Oct 2024 05:21:02 +0200 Subject: [PATCH 3/6] Update playwright.yml --- .github/workflows/playwright.yml | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 8cd4ac11c..e3700d201 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -17,14 +17,36 @@ jobs: run: npm ci - name: Install Playwright Browsers run: npx playwright install --with-deps + - name: Build the project + run: npm run build + env: + NEXT_PUBLIC_GRAPHQL_URL: ${{ secrets.NEXT_PUBLIC_GRAPHQL_URL }} + - name: Start the application + run: npm run start & + env: + NEXT_PUBLIC_GRAPHQL_URL: ${{ secrets.NEXT_PUBLIC_GRAPHQL_URL }} + - name: Wait for the application to be ready + run: | + echo "Waiting for the application to be ready..." + timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:3000)" != "200" ]]; do sleep 5; done' || false + echo "Application is ready!" - name: Run Playwright tests run: npx playwright test env: - CI: true - NEXT_PUBLIC_GRAPHQL_URL: ${{ secrets.NEXT_PUBLIC_GRAPHQL_URL }} - - uses: actions/upload-artifact@v4 + CI: true + NEXT_PUBLIC_GRAPHQL_URL: ${{ secrets.NEXT_PUBLIC_GRAPHQL_URL }} + DEBUG: pw:api + - name: Upload test results if: always() + uses: actions/upload-artifact@v4 with: name: playwright-report path: playwright-report/ retention-days: 30 + - name: Upload test traces + if: failure() + uses: actions/upload-artifact@v4 + with: + name: playwright-traces + path: test-results/ + retention-days: 30 From bf093fe8199350f2d20a519af7880d2c80a052a7 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Wed, 23 Oct 2024 05:34:32 +0200 Subject: [PATCH 4/6] . --- .../Product/AddToCart.component.tsx | 46 +++++++++---------- src/stores/CartProvider.tsx | 25 ++++++---- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/components/Product/AddToCart.component.tsx b/src/components/Product/AddToCart.component.tsx index f2fa39c1b..6875e2022 100644 --- a/src/components/Product/AddToCart.component.tsx +++ b/src/components/Product/AddToCart.component.tsx @@ -96,7 +96,7 @@ const AddToCart = ({ variationId, fullWidth = false, }: IProductRootObject) => { - const { setCart } = useContext(CartContext); + const { updateCart } = useContext(CartContext); const [requestError, setRequestError] = useState(false); const productId = product?.databaseId ? product?.databaseId : variationId; @@ -107,20 +107,14 @@ const AddToCart = ({ }; // Get cart data query - const { data, refetch } = useQuery(GET_CART, { + const { refetch } = useQuery(GET_CART, { notifyOnNetworkStatusChange: true, - onCompleted: () => { - // Update cart in the localStorage. + onCompleted: (data) => { + // Update cart in the localStorage and React Context. const updatedCart = getFormattedCart(data); - - if (!updatedCart) { - return; + if (updatedCart) { + updateCart(updatedCart); } - - localStorage.setItem('woocommerce-cart', JSON.stringify(updatedCart)); - - // Update cart data in React Context. - setCart(updatedCart); }, }); @@ -129,29 +123,33 @@ const AddToCart = ({ variables: { input: productQueryInput, }, - - onCompleted: () => { - // Update the cart with new values in React context. - refetch(); + onCompleted: (data) => { + // Immediately update the cart with new values + const updatedCart = getFormattedCart(data); + if (updatedCart) { + updateCart(updatedCart); + } }, - onError: () => { setRequestError(true); }, }); - const handleAddToCart = () => { - addToCart(); - // Refetch cart after 2 seconds - setTimeout(() => { - refetch(); - }, 2000); + const handleAddToCart = async () => { + try { + await addToCart(); + // Refetch cart immediately after adding to cart + await refetch(); + } catch (error) { + console.error('Error adding to cart:', error); + setRequestError(true); + } }; return ( <> + {requestError && ( +

+ Det oppstod en feil ved tillegging i handlekurven. Vennligst prøv + igjen. +

+ )} ); };