Skip to content

Commit

Permalink
Fix WebDriver screenshot size
Browse files Browse the repository at this point in the history
* Rename function

Signed-off-by: Marvin A. Ruder <[email protected]>
  • Loading branch information
marvinruder committed Jun 22, 2023
1 parent 17afa91 commit 13279ce
Show file tree
Hide file tree
Showing 23 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If applicable, add screenshots and log snippets to help explain your problem.

- Version: [e.g. 2.1.0]
- OS: [e.g. iOS]
- Browser [e.g. Chrome, Safari]
- Browser: [e.g. Chrome, Safari]

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion packages/backend/src/utils/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface RouterOptions {
// This way of using stable decorators is not yet supported by Vite(st).
const Router = <This>(options: RouterOptions): any => {
export default Router = <This>(options: RouterOptions): any => {
return (
controllerFn: (...args: [Request, Response]) => void | Promise<void>,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
10 changes: 6 additions & 4 deletions packages/backend/src/utils/webdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export const getDriver = async (headless?: boolean, pageLoadStrategy?: PageLoadS
// Wait up to 1 second randomly to avoid a not yet identified bottleneck
await new Promise<void>((resolve) => setTimeout(() => resolve(), Math.random() * 1000));
const url = process.env.SELENIUM_URL;
const options = new chrome.Options()
.addArguments("window-size=1080x3840") // convenient for screenshots
.addArguments("--blink-settings=imagesEnabled=false"); // Do not load images
const options = new chrome.Options().addArguments("--blink-settings=imagesEnabled=false"); // Do not load images
headless && options.addArguments("--headless=new"); // In headless mode, the browser window is not shown.

return await new Builder()
Expand All @@ -43,7 +41,11 @@ export const getDriver = async (headless?: boolean, pageLoadStrategy?: PageLoadS
)
.setChromeOptions(options)
.build()
.then((driver) => driver)
.then(async (driver) => {
// Use `setSize(…)` after https://github.com/SeleniumHQ/selenium/issues/12243 is resolved.
await driver.manage().window().setRect({ width: 1080, height: 3840 }); // convenient for screenshots
return driver;
})
.catch((e) => {
throw new APIError(502, `Unable to connect to Selenium WebDriver: ${e.message}`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const AddStock = (props: AddStockProps): JSX.Element => {
const [sustainalyticsIDRequestInProgress, setSustainalyticsIDRequestInProgress] = useState<boolean>(false);
// Whether the Sustainalytics ID has been transmitted to the server.
const [sustainalyticsIDSet, setSustainalyticsIDSet] = useState<boolean>(false);
const { setNotification, setErrorNotification } = useNotification();
const { setNotification, setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

/**
* Checks for errors in the input fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const AddStockToWatchlist = (props: AddStockToWatchlistProps): JSX.Elemen
const [watchlistsAlreadyContainingStock, setWatchlistsAlreadyContainingStock] = useState<number[]>([]);
const [watchlistSummariesFinal, setWatchlistSummariesFinal] = useState<boolean>(false);
const [addWatchlistOpen, setAddWatchlistOpen] = useState<boolean>(false);
const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

useEffect(() => getWatchlists(), []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const AddWatchlist = (props: AddWatchlistProps): JSX.Element => {
const [requestInProgress, setRequestInProgress] = useState<boolean>(false);
const [name, setName] = useState<string>("");
const [nameError, setNameError] = useState<boolean>(false); // Error in the name text field.
const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

/**
* Checks for errors in the input fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useNavigate } from "react-router";
export const DeleteStock = (props: DeleteStockProps): JSX.Element => {
const [requestInProgress, setRequestInProgress] = useState(false);

const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();
const navigate = useNavigate();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useNotification } from "../../../contexts/NotificationContext";
export const DeleteUser = (props: DeleteUserProps): JSX.Element => {
const [requestInProgress, setRequestInProgress] = useState(false);

const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

/**
* Deletes the user from the backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useNavigate } from "react-router";
export const DeleteWatchlist = (props: DeleteWatchlistProps): JSX.Element => {
const [requestInProgress, setRequestInProgress] = useState(false);

const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();
const navigate = useNavigate();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const EditStock = (props: EditStockProps): JSX.Element => {
const [spIDRequestInProgress, setSPIDRequestInProgress] = useState<boolean>(false);
const [sustainalyticsID, setSustainalyticsID] = useState<string>(props.stock?.sustainalyticsID);
const [sustainalyticsIDRequestInProgress, setSustainalyticsIDRequestInProgress] = useState<boolean>(false);
const { setNotification, setErrorNotification } = useNotification();
const { setNotification, setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

/**
* Checks for errors in the input fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useNotification } from "../../../contexts/NotificationContext";
export const RemoveStockFromWatchlist = (props: RemoveStockFromWatchlistProps): JSX.Element => {
const [requestInProgress, setRequestInProgress] = useState(false);

const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

/**
* Removes the stock from the watchlist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const RenameWatchlist = (props: RenameWatchlistProps): JSX.Element => {
const [requestInProgress, setRequestInProgress] = useState<boolean>(false);
const [name, setName] = useState<string>(props.watchlist?.name);
const [nameError, setNameError] = useState<boolean>(false); // Error in the name text field.
const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

/**
* Checks for errors in the input fields.
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/content/modules/Stock/Stock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const StockModule = (): JSX.Element => {
const [stock, setStock] = useState<Stock>();
const [isFavorite, setIsFavorite] = useState<boolean>(false);

const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

/**
* Fetches the stock with the given ticker.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const StockTable: FC<StockTableProps> = (props: StockTableProps): JSX.Element =>
const [stocksFinal, setStocksFinal] = useState<boolean>(false);
const [sortBy, setSortBy] = useState<SortableAttribute>("totalScore");
const [sortDesc, setSortDesc] = useState<boolean>(true);
const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

useEffect(() => {
getStocks(); // Get stocks whenever pagination, sorting or filtering changes, or when explicitly requested.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const UserRow = (props: UserRowProps): JSX.Element => {
const [requestInProgress, setRequestInProgress] = useState<boolean>(false);
const [accessRights, setAccessRights] = useState<number>(props.user.accessRights);

const { setNotification, setErrorNotification } = useNotification();
const { setNotification, setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

/**
* Updates the user’s access rights in the backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const UserTable: FC = (): JSX.Element => {
const [count, setCount] = useState<number>(-1);
const [users, setUsers] = useState<User[]>([]);
const [usersFinal, setUsersFinal] = useState<boolean>(false);
const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

/**
* Get the users from the backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
*/
const WatchlistModule = (): JSX.Element => {
const [watchlist, setWatchlist] = useState<Watchlist>();
const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

/**
* Fetches the watchlist with the given ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import WatchlistCard from "./WatchlistCard";
const WatchlistSummaryModule = (): JSX.Element => {
const [watchlistSummaries, setWatchlistSummaries] = useState<WatchlistSummary[]>([]);
const [watchlistSummariesFinal, setWatchlistSummariesFinal] = useState<boolean>(false);
const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

useEffect(() => getWatchlists(), []);

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/content/pages/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const LoginPage = (): JSX.Element => {
const [name, setName] = useState<string>("");
const [emailError, setEmailError] = useState<boolean>(false);
const [nameError, setNameError] = useState<boolean>(false);
const { setNotification, setErrorNotification } = useNotification();
const { setNotification, setErrorNotificationOrClearSession: setErrorNotification } = useNotification();
const { refetchUser } = useContext(UserContext);

/**
Expand Down
12 changes: 3 additions & 9 deletions packages/frontend/src/contexts/NotificationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type NotificationContextType = {
/**
* A method to set an error notification to be displayed after an API request failed.
*/
setErrorNotification: (e: unknown, actionDescription: string) => void; // rename to …OrClearSession in #295
setErrorNotificationOrClearSession: (e: unknown, actionDescription: string) => void;
};

/**
Expand All @@ -37,7 +37,7 @@ export const NotificationProvider = (props: NotificationProviderProps): JSX.Elem
const [notification, setNotification] = useState<Notification | undefined>(undefined);
const { clearUser } = useContext(UserContext);

const setErrorNotification = (e: AxiosError<{ message: string }>, actionDescription: string) => {
const setErrorNotificationOrClearSession = (e: AxiosError<{ message: string }>, actionDescription: string) => {
setNotification({
severity: "error",
title: `Error while ${actionDescription}`,
Expand All @@ -51,13 +51,7 @@ export const NotificationProvider = (props: NotificationProviderProps): JSX.Elem
};

return (
<NotificationContext.Provider
value={{
notification,
setNotification,
setErrorNotification,
}}
>
<NotificationContext.Provider value={{ notification, setNotification, setErrorNotificationOrClearSession }}>
{props.children}
</NotificationContext.Provider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const HeaderSearch = (): JSX.Element => {
const [count, setCount] = useState<number>(0);
const [stocksFinal, setStocksFinal] = useState<boolean>(false);

const { setErrorNotification } = useNotification();
const { setErrorNotificationOrClearSession: setErrorNotification } = useNotification();
const theme = useTheme();
const navigate = useNavigate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import ConvertAvatarWorker from "../../../../utils/imageManipulation?worker";
*/
export const ProfileSettings = (props: ProfileSettingsProps): JSX.Element => {
const { user, refetchUser } = useContext(UserContext);
const { setNotification, setErrorNotification } = useNotification();
const { setNotification, setErrorNotificationOrClearSession: setErrorNotification } = useNotification();

const [requestInProgress, setRequestInProgress] = useState<boolean>(false);
const [name, setName] = useState<string>(user.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { sessionEndpointPath } from "@rating-tracker/commons";
export const HeaderUserbox = (): JSX.Element => {
const [open, setOpen] = useState(false);
const navigate = useNavigate();
const { setNotification, setErrorNotification } = useContext(NotificationContext);
const { setNotification, setErrorNotificationOrClearSession: setErrorNotification } = useContext(NotificationContext);
const { user } = useContext(UserContext);

/**
Expand Down

0 comments on commit 13279ce

Please sign in to comment.