From cfacaeb9c1ff4c6717605b146641c7b4268a6d04 Mon Sep 17 00:00:00 2001 From: Aashu Anshuman Date: Tue, 13 Aug 2024 13:07:41 +0100 Subject: [PATCH 1/6] Update e2e action to use a better testing setup (#1585) * The e2e action now launches a local Lemmy instance to use as target for all lemmy related API calls made by Playwright tests. * The action no longer uses the custom Docker image provided by the Playwright team. * Also added are configs for the Lemmy instance and nginx, and a docker-compose.yml file to launch the Lemmy stack. The nginx configs and docker-compose.yml are stripped down versions of the official files provided by the Lemmy developers. --- .github/workflows/e2e.yml | 22 +++++++++---------- e2e/ci/docker-compose.yml | 46 +++++++++++++++++++++++++++++++++++++++ e2e/ci/lemmy.hjson | 20 +++++++++++++++++ e2e/ci/nginx.conf | 34 +++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 e2e/ci/docker-compose.yml create mode 100644 e2e/ci/lemmy.hjson create mode 100644 e2e/ci/nginx.conf diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index efaba06e7..d3e2a8029 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,17 +1,9 @@ name: Run e2e tests -on: - push: - branches: - - main - pull_request: - branches: - - main +on: workflow_dispatch jobs: playwright: name: Run Playwright tests runs-on: ubuntu-latest - container: - image: mcr.microsoft.com/playwright:v1.46.0-jammy steps: - uses: actions/checkout@v4 - run: corepack enable @@ -23,5 +15,13 @@ jobs: run: pnpm install --frozen-lockfile - name: Build project run: pnpm build - - name: Run tests - run: env HOME=/root pnpm test:e2e + env: + VITE_FORCE_LEMMY_INSECURE: 1 + VITE_CUSTOM_LEMMY_SERVERS: localhost:8536 + - name: Install Playwright dependencies + run: npx playwright install --with-deps + - name: Run Playwright tests + run: | + docker compose -f e2e/ci/docker-compose.yml up -d + sleep 10 + pnpm run test:e2e diff --git a/e2e/ci/docker-compose.yml b/e2e/ci/docker-compose.yml new file mode 100644 index 000000000..d3781c5f6 --- /dev/null +++ b/e2e/ci/docker-compose.yml @@ -0,0 +1,46 @@ +# Based on the nginx config made available by Lemmy developers. +# https://github.com/LemmyNet/lemmy + +x-logging: &default-logging + driver: "json-file" + options: + max-size: "50m" + max-file: "4" + +services: + proxy: + image: nginx:1-alpine + ports: + - "8536:8536" + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf:ro,Z + restart: unless-stopped + logging: *default-logging + + lemmy: + image: dessalines/lemmy:0.19.5 + platform: linux/x86_64 + hostname: lemmy + restart: unless-stopped + environment: + - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug" + - RUST_BACKTRACE=full + volumes: + - ./lemmy.hjson:/config/config.hjson:Z + depends_on: + - postgres + logging: *default-logging + + postgres: + image: postgres + hostname: postgres + ports: + - "5433:5432" + environment: + - POSTGRES_USER=lemmy + - POSTGRES_PASSWORD=password + - POSTGRES_DB=lemmy + volumes: + - ./volumes/postgres:/var/lib/postgresql/data:Z + restart: unless-stopped + logging: *default-logging diff --git a/e2e/ci/lemmy.hjson b/e2e/ci/lemmy.hjson new file mode 100644 index 000000000..35d84b8d5 --- /dev/null +++ b/e2e/ci/lemmy.hjson @@ -0,0 +1,20 @@ +{ + setup: { + admin_username: "voyager" + admin_password: "voyagerapp" + site_name: "voyager" + } + + database: { + host: postgres + } + + hostname: "localhost" + bind: "0.0.0.0" + port: 8536 + + pictrs: { + url: "http://pictrs:8080/" + image_mode: None + } +} diff --git a/e2e/ci/nginx.conf b/e2e/ci/nginx.conf new file mode 100644 index 000000000..bc05bbfeb --- /dev/null +++ b/e2e/ci/nginx.conf @@ -0,0 +1,34 @@ +# Based on the nginx config made available by Lemmy developers. +# https://github.com/LemmyNet/lemmy + +worker_processes 1; +events { + worker_connections 1024; +} +http { + upstream lemmy { + # this needs to map to the lemmy (server) docker service hostname + server "lemmy:8536"; + } + + server { + listen 8536; + # change if needed, this is facing the public web + server_name localhost; + server_tokens off; + + # backend + location ~ ^/(api|pictrs|feeds|nodeinfo|version|.well-known) { + proxy_pass "http://lemmy"; + # proxy common stuff + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # Send actual client IP upstream + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + } +} From f2d4444dca3c8054fdadce39675a437a0f989fda Mon Sep 17 00:00:00 2001 From: Alexander Harding <2166114+aeharding@users.noreply.github.com> Date: Tue, 20 Aug 2024 22:20:03 -0500 Subject: [PATCH 2/6] Fix large numbered lists cut off in spoiler tags (#1591) Resolves #1589 --- src/features/shared/markdown/Markdown.tsx | 2 +- .../shared/markdown/components/spoiler/Details.tsx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/features/shared/markdown/Markdown.tsx b/src/features/shared/markdown/Markdown.tsx index 9e86c9edb..8cc0c910b 100644 --- a/src/features/shared/markdown/Markdown.tsx +++ b/src/features/shared/markdown/Markdown.tsx @@ -17,7 +17,7 @@ const markdownCss = css` @media (max-width: 700px) { ul, ol { - padding-left: 24px; + padding-left: 28px; } } diff --git a/src/features/shared/markdown/components/spoiler/Details.tsx b/src/features/shared/markdown/components/spoiler/Details.tsx index abef9b95c..41adbb59a 100644 --- a/src/features/shared/markdown/components/spoiler/Details.tsx +++ b/src/features/shared/markdown/components/spoiler/Details.tsx @@ -14,12 +14,12 @@ import store, { useAppDispatch } from "../../../../../store"; import { getSpoilerId, updateSpoilerState } from "./spoilerSlice"; const StyledIonAccordionGroup = styled(IonAccordionGroup)` - margin: 1em 0; + margin: 1em -12px; `; const HeaderItem = styled(IonItem)` - --padding-start: 0; - --padding-end: 0; + --padding-start: 12px; + --padding-end: 12px; --inner-padding-end: 0; --inner-padding-start: 0; @@ -39,7 +39,7 @@ const StyledIonAccordion = styled(IonAccordion)` background: none; [slot="content"] { - padding: 1em 0; + padding: 1em 12px; background: transparent; From f8867f3d5b3c88172656525302ec2272e59f35fc Mon Sep 17 00:00:00 2001 From: Aashu Anshuman Date: Thu, 29 Aug 2024 05:18:03 +0100 Subject: [PATCH 3/6] Override lemmy server URL when 'VITE__TEST_MODE' is set (#1593) * Override lemmy server URL when 'VITE__TEST_MODE' is set * Change `urlSelector` and `updateConnectedInstance` to always use `getDefaultServer` as instance. * In e2e.yml, include this in the build project step env. * Import getDefaultServer --- .github/workflows/e2e.yml | 1 + src/features/auth/authSelectors.ts | 7 +++++-- src/features/auth/authSlice.ts | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index d3e2a8029..1ccd70ec4 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -18,6 +18,7 @@ jobs: env: VITE_FORCE_LEMMY_INSECURE: 1 VITE_CUSTOM_LEMMY_SERVERS: localhost:8536 + VITE__TEST_MODE: 1 - name: Install Playwright dependencies run: npx playwright install --with-deps - name: Run Playwright tests diff --git a/src/features/auth/authSelectors.ts b/src/features/auth/authSelectors.ts index bafa3954f..fc7d47d39 100644 --- a/src/features/auth/authSelectors.ts +++ b/src/features/auth/authSelectors.ts @@ -49,8 +49,11 @@ export const instanceSelector = createSelector([handleSelector], (handle) => { return getInstanceFromHandle(handle); }); -export const urlSelector = (state: RootState) => - instanceSelector(state) ?? state.auth.connectedInstance; +export const urlSelector = (state: RootState) => { + if (import.meta.env.VITE__TEST_MODE) return state.auth.connectedInstance; + + return instanceSelector(state) ?? state.auth.connectedInstance; +}; export const clientSelector = createSelector( [urlSelector, jwtSelector], diff --git a/src/features/auth/authSlice.ts b/src/features/auth/authSlice.ts index 8d56b21bc..cff698a4c 100644 --- a/src/features/auth/authSlice.ts +++ b/src/features/auth/authSlice.ts @@ -16,6 +16,7 @@ import { getInstanceFromHandle, instanceSelector } from "./authSelectors"; import { receivedSite, resetSite } from "./siteSlice"; import { Register } from "lemmy-js-client"; import { setDefaultFeed } from "../settings/settingsSlice"; +import { getDefaultServer } from "../../services/app"; const MULTI_ACCOUNT_STORAGE_NAME = "credentials"; @@ -142,6 +143,10 @@ export const authSlice = createSlice({ }, updateConnectedInstance(state, action: PayloadAction) { + if (import.meta.env.VITE__TEST_MODE) { + state.connectedInstance = getDefaultServer(); + return; + } state.connectedInstance = action.payload; }, }, From e4a46fa865d08338511c4af9ecb8d13b73ce4ec8 Mon Sep 17 00:00:00 2001 From: Alexander Harding <2166114+aeharding@users.noreply.github.com> Date: Sun, 8 Sep 2024 14:51:49 -0500 Subject: [PATCH 4/6] Fix flakey inbox count update on marking item(s) read (#1596) --- src/features/inbox/inboxSlice.ts | 9 +++++---- src/features/inbox/messages/Message.tsx | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/features/inbox/inboxSlice.ts b/src/features/inbox/inboxSlice.ts index dff2e3c87..1438ab25c 100644 --- a/src/features/inbox/inboxSlice.ts +++ b/src/features/inbox/inboxSlice.ts @@ -108,7 +108,8 @@ export const totalUnreadSelector = (state: RootState) => state.inbox.counts.replies; export const getInboxCounts = - () => async (dispatch: AppDispatch, getState: () => RootState) => { + (force = false) => + async (dispatch: AppDispatch, getState: () => RootState) => { const jwt = jwtSelector(getState()); if (!jwt) { @@ -118,7 +119,7 @@ export const getInboxCounts = const lastUpdatedCounts = getState().inbox.lastUpdatedCounts; - if (Date.now() - lastUpdatedCounts < 3_000) return; + if (!force && Date.now() - lastUpdatedCounts < 3_000) return; const result = await clientSelector(getState()).getUnreadCount(); @@ -190,7 +191,7 @@ export const markAllRead = await clientSelector(getState()).markAllAsRead(); dispatch(markAllReadInCache()); - dispatch(getInboxCounts()); + dispatch(getInboxCounts(true)); }; export const conversationsByPersonIdSelector = createSelector( @@ -284,5 +285,5 @@ export const markRead = throw error; } - dispatch(getInboxCounts()); + dispatch(getInboxCounts(true)); }; diff --git a/src/features/inbox/messages/Message.tsx b/src/features/inbox/messages/Message.tsx index ca6181112..061cc539a 100644 --- a/src/features/inbox/messages/Message.tsx +++ b/src/features/inbox/messages/Message.tsx @@ -154,7 +154,7 @@ export default function Message({ message, first }: MessageProps) { } await dispatch(receivedMessages([response.private_message_view])); - await dispatch(getInboxCounts()); + await dispatch(getInboxCounts(true)); } return ( From 047bdca29d2cb43ffeb2d5ae422f7081f9180d04 Mon Sep 17 00:00:00 2001 From: Alexander Harding <2166114+aeharding@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:00:49 -0500 Subject: [PATCH 5/6] Fix invalid link preview (#1599) Resolves #1598 --- src/features/comment/CommentLinks.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/comment/CommentLinks.tsx b/src/features/comment/CommentLinks.tsx index 763626538..56e3cd148 100644 --- a/src/features/comment/CommentLinks.tsx +++ b/src/features/comment/CommentLinks.tsx @@ -8,9 +8,9 @@ import customRemarkGfm from "../shared/markdown/customRemarkGfm"; import { useAppSelector } from "../../store"; import { Text } from "mdast"; import { uniqBy } from "lodash"; -import { isValidUrl } from "../../helpers/url"; import spoiler from "@aeharding/remark-lemmy-spoiler"; import { buildBaseLemmyUrl } from "../../services/lemmy"; +import { defaultUrlTransform } from "react-markdown"; const Container = styled.div` display: flex; @@ -68,7 +68,7 @@ export default function CommentLinks({ markdown }: CommentLinksProps) { links = uniqBy(links, (l) => l.url); // e.g. `http://127.0.0.1:8080”` - links = links.filter(({ url }) => isValidUrl(url)); + links = links.filter(({ url }) => defaultUrlTransform(url)); // Max 4 links links = links.slice(0, 4); From fb05847bd15d12ed8025be96388ebd27cc08b826 Mon Sep 17 00:00:00 2001 From: Alexander Harding <2166114+aeharding@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:01:19 -0500 Subject: [PATCH 6/6] Release 2.17.1 --- android/app/build.gradle | 4 ++-- ios/App/App/Info.plist | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 9f3d8129d..d8b200b2f 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "app.vger.voyager" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 260 - versionName "2.17.0" + versionCode 261 + versionName "2.17.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/ios/App/App/Info.plist b/ios/App/App/Info.plist index 5aad4b923..f6d7be325 100644 --- a/ios/App/App/Info.plist +++ b/ios/App/App/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.17.0 + 2.17.1 CFBundleURLTypes @@ -32,7 +32,7 @@ CFBundleVersion - 260 + 261 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/package.json b/package.json index f2e0b5e92..47f0a3fc6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "voyager", "description": "A progressive webapp Lemmy client", "private": true, - "version": "2.17.0", + "version": "2.17.1", "type": "module", "packageManager": "pnpm@9.6.0+sha512.38dc6fba8dba35b39340b9700112c2fe1e12f10b17134715a4aa98ccf7bb035e76fd981cf0bb384dfa98f8d6af5481c2bef2f4266a24bfa20c34eb7147ce0b5e", "scripts": {