Skip to content

Commit

Permalink
Override lemmy server URL when 'VITE__TEST_MODE' is set (aeharding#1593)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aashu16 authored Aug 29, 2024
1 parent f2d4444 commit f8867f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/features/auth/authSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 5 additions & 0 deletions src/features/auth/authSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -142,6 +143,10 @@ export const authSlice = createSlice({
},

updateConnectedInstance(state, action: PayloadAction<string>) {
if (import.meta.env.VITE__TEST_MODE) {
state.connectedInstance = getDefaultServer();
return;
}
state.connectedInstance = action.payload;
},
},
Expand Down

0 comments on commit f8867f3

Please sign in to comment.