Fix issue where the save repro button was not available for admins

This commit is contained in:
Jason Laster 2025-03-20 14:01:41 -07:00
parent 5fe9f297e7
commit 3f2ba43c2e
4 changed files with 25 additions and 7 deletions

View File

@ -1,7 +1,6 @@
import { motion, type Variants } from 'framer-motion';
import { useCallback, useEffect, useRef, useState } from 'react';
import { toast } from 'react-toastify';
import { useStore } from '@nanostores/react';
import { Dialog, DialogButton, DialogDescription, DialogRoot, DialogTitle } from '~/components/ui/Dialog';
import { ThemeSwitch } from '~/components/ui/ThemeSwitch';
import { SettingsWindow } from '~/components/settings/SettingsWindow';
@ -14,7 +13,7 @@ import { binDates } from './date-binning';
import { useSearchFilter } from '~/lib/hooks/useSearchFilter';
import { SaveProblem } from './SaveProblem';
import { SaveReproductionModal } from './SaveReproduction';
import { isAdminStore } from '~/lib/stores/user';
import { useAdminStatus } from '~/lib/stores/user';
const menuVariants = {
closed: {
@ -47,7 +46,7 @@ export const Menu = () => {
const [open, setOpen] = useState(false);
const [dialogContent, setDialogContent] = useState<DialogContent>(null);
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
const isAdmin = useStore(isAdminStore);
const { isAdmin } = useAdminStatus();
const { filteredItems: filteredList, handleSearchChange } = useSearchFilter({
items: list,

View File

@ -22,7 +22,9 @@ export function SaveReproductionModal() {
const [savedReproduction, setSavedReproduction] = useState<boolean>(false);
const [problem, setProblem] = useState<BoltProblem | null>(null);
const handleSaveReproduction = async () => {
const handleSaveReproduction = async (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
const loadId = toast.loading('Loading problem...');
try {

View File

@ -1,5 +1,5 @@
import { test, expect } from '@playwright/test';
import { isSupabaseEnabled, login, setLoginKey } from './setup/test-utils';
import { isSupabaseEnabled, login, setLoginKey, openSidebar } from './setup/test-utils';
test('Should be able to load a problem', async ({ page }) => {
await page.goto('/problems');
@ -29,7 +29,7 @@ test('Should be able to save a problem ', async ({ page }) => {
const useSupabase = await isSupabaseEnabled(page);
if (useSupabase) {
await page.locator('[data-testid="sidebar-icon"]').click();
await openSidebar(page);
await page.getByRole('button', { name: 'Save Problem' }).click();
await page.getByRole('button', { name: 'Log In' }).click();
await page.getByRole('textbox', { name: 'Email' }).click();
@ -134,3 +134,16 @@ test('Should be able to add a comment to a problem', async ({ page }) => {
await page.reload();
await expect(page.locator('[data-testid="problem-comment"]').filter({ hasText: comment })).toBeVisible();
});
test('Confirm that admins see the "Save Reproduction" button', async ({ page }) => {
await page.goto('/problems?showAll=true');
if (await isSupabaseEnabled(page)) {
await login(page);
} else {
await setLoginKey(page);
}
await openSidebar(page);
await expect(page.getByRole('link', { name: 'Save Reproduction' })).toBeVisible();
});

View File

@ -54,6 +54,10 @@ export async function getElementText(page: Page, selector: string): Promise<stri
return page.locator(selector).textContent() as Promise<string>;
}
export async function openSidebar(page: Page): Promise<void> {
await page.locator('[data-testid="sidebar-icon"]').click();
}
export async function login(page: Page): Promise<void> {
await page.getByRole('button', { name: 'Sign In' }).click();
await page.getByRole('textbox', { name: 'Email' }).click();
@ -64,7 +68,7 @@ export async function login(page: Page): Promise<void> {
}
export async function setLoginKey(page: Page): Promise<void> {
await page.locator('[data-testid="sidebar-icon"]').click();
await openSidebar(page);
await page.getByRole('button', { name: 'Settings' }).click();
await page.getByRole('button', { name: 'User Info' }).click();
await page.getByRole('textbox').nth(1).click();