From 7468b3011fa23f251dc0393f9292cede3b65a4aa Mon Sep 17 00:00:00 2001 From: Anirudh <70373803+techwithanirudh@users.noreply.github.com> Date: Fri, 2 Jun 2023 10:02:35 +0530 Subject: [PATCH] Added Settings Modal (#342) * Improve UI with style changes and add Settings button - Improved the UI of the `Input` and `Message` components. - Added a `Settings` button to the `NavLinks` component. - Introduced a `Settings` component to handle user settings. - Refactored the `Dialog` component for consistency. * Revert not needed changes * Updated style.css to only work for select * feat: Remove Dark Mode component and add theme selection feature This commit removes the Dark Mode component from the navigation bar and replaces it with a theme selection dropdown menu in the Settings dialog. The implementation of the theme selection feature includes a function that allows the user to set the theme based on the system, light, or dark mode. * Add auto theme setting to Settings component. This commit adds a new state variable to keep track of whether the auto theme is enabled or not. It also registers an event listener to update the theme based on system preference changes. The event listener is removed when the component is unmounted. * Improve user experience by allowing customized themes - Create `selectedOption` state to track user-selected theme - Remove unused `isAutoTheme` state variable * feat(Nav): Add SVG icon to settings gear This commit adds an SVG icon to the settings gear in the Navigation component's Settings file. The new SVG icon replaces the previous GearIcon component. * refactor(ui): Update overlay background color This commit updates the background color of the overlay in the AlertDialog and Dialog components by changing the classes applied to the elements. The new color is a transition from `bg-black/50 backdrop-blur-sm` to `bg-gray-500/90 dark:bg-gray-800/90`. This change improves the readability of the dialog boxes. * Refactor ThemeContext to include system theme and fix bug in Settings The ThemeContext now includes a "system" theme and ClearConvos no longer relies on the "selected option" state to update the theme. The bug is now fixed if the system theme changes. * Refactor DialogTemplate styles and color scheme Adjusted the color scheme of the DialogTemplate component to dark mode, updated the background color to gray-900 and removed unnecessary classes. * Refactor: Change button logic to require confirmation before clearing convos This commit refactors the code by adding a confirmation dialog to prompt for a user's confirmation before clearing all conversations in the Settings.jsx file. The change ensures the user is aware of the irreversible action before initiating the clearConvos function. Additionally, the commit updates the clear chat button's class name and changes the button's onClick logic to call the confirmClearConvos function instead of directly invoking the clearConvos method. * Refactor component name to reflect functionality change. - Changed component name from ClearConvos to Settings to support potential future use cases. * Refactor conversation clearing functionality in `Settings.jsx` This commit optimizes the conversation clearing functionality in the `Settings.jsx` component by removing the `confirmClearConvos` function and directly calling the `clearConvos` function on confirmation. This change will simplify the code and improve the user experience. * Refactor Input component UI styles Simplify Input component styles by simplifying the gradient background, removing border color styles, and updating button styles. * feat: Add e2e test for Settings modal This commit adds an e2e test to verify whether the Settings modal is displayed on the landing page. It uses a headless browser to navigate to the page and interacts with it to verify if the dialog and its components are visible. * test: Add Navigation and Settings tests Add Navigation and Settings tests to verify that the navigation bar and Settings button are visible and that the Settings modal displays the expected content. The settings modal verification includes checking whether the modal is visible, if the modal title, tab list, clear conversation button and theme are present, and if the theme option can be selected to change the mode. * Quick fix * feat(navbar): Add confirmation before clearing conversations Adding confirmation modal to prevent accidentally clearing conversations. Before, once you clicked on the "Clear" button it immediately clears all conversations. With this change, if you click on "Clear" the first time, it will change the text to "Confirm Clear" and if you click it again, it will clear all conversations. * Add click functionality to the navigation bar and improve UI design The code introduced click functionality to the nav bar and improved the user interface. It also used the new theme select feature to change the theme to dark. * test: Add test for dark mode theme change Refactor the test for Navigation suite to check for the 'dark' class in the HTML element when the 'dark' theme is selected in the modal. This ensures that the dark mode theme change works correctly, and improves test coverage. * Improve navigation test clarity This commit improves code clarity and adds more detailed test assertions to the navigation suite. New assert statements are added to check whether the modal theme selection changes the theme and that the HTML element receives the 'dark' class. A new function `changeMode` was introduced to avoid code repetition. A short description was added to the commit message to adhere to best practices. * Improve navigation test clarity This commit improves code clarity and adds more detailed test assertions to the navigation suite. New assert statements are added to check whether the modal theme selection changes the theme and that the HTML element receives the 'dark' class. A new function `changeMode` was introduced to avoid code repetition. A short description was added to the commit message to adhere to best practices. * Hotfix * Removed repetation * Refactor: Change text-gray-400 to text-white/50 to make tailwind more cleaner * style: Update CSS classes to improve the conversation UI - Update Conversation component to improve UX - Changed styling for group hover effect using shades of gray - Improved color contrast of the Message component for easy readability - Replaced class names in buildTree.js with a new class name - Added a new color theme (gray-1000) in tailwind.config to replace an old background color. * Refactor EndpointItem, EndpointItems, and NewConversationMenu for better user experience - The `EndpointItem` component now accepts an `isSelected` prop instead of `onSelect` to better reflect its usage in `EndpointItems` and `NewConversationMenu`. - `EndpointItems` component now has a `selectedEndpoint` prop to highlight the selected item in the list. - `NewConversationMenu` now has a gap between the endpoint options to improve user experience. * Added error messages * refactor: Improve endpoint menu highlighting and error handling In the UI, when the user selects an endpoint, the active class is now properly set. In the error handling function, `isJson` is now a private function called by `getError`, which provides better parsing of error messages, and returns more succinct messages upon encountering specific errors. Finally, a new end-to-end test has been added to check if the active class is properly set on selecting an endpoint in the new conversation menu. * test: Add Conversation and Change Path of Auth JSON In the Landing spec, test the functionality to create conversations and check that the number of items has increased. In the Popup spec, change the path of the Auth JSON used by the context. * Fixed logo issues * Make everything not rounded * Added time --------- Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com> --- .../components/Conversations/Conversation.jsx | 2 +- .../NewConversationMenu/EndpointItem.jsx | 13 +- .../NewConversationMenu/EndpointItems.jsx | 4 +- .../Input/NewConversationMenu/index.jsx | 4 +- client/src/components/Messages/Message.jsx | 30 +--- client/src/components/Nav/DarkMode.jsx | 23 --- client/src/components/Nav/NavLinks.jsx | 20 ++- client/src/components/Nav/Settings.jsx | 170 ++++++++++++++++++ client/src/components/svg/GearIcon.jsx | 19 ++ client/src/components/ui/AlertDialog.tsx | 2 +- client/src/components/ui/Dialog.tsx | 16 +- client/src/components/ui/DialogTemplate.jsx | 22 +-- client/src/hooks/ThemeContext.jsx | 8 +- client/src/style.css | 18 ++ client/src/utils/buildTree.js | 2 +- client/src/utils/getError.ts | 29 +++ client/tailwind.config.cjs | 3 +- e2e/specs/landing.spec.js | 36 +++- e2e/specs/nav.spec.js | 59 ++++++ e2e/specs/popup.spec.js | 24 +++ 20 files changed, 414 insertions(+), 90 deletions(-) delete mode 100644 client/src/components/Nav/DarkMode.jsx create mode 100644 client/src/components/Nav/Settings.jsx create mode 100644 client/src/components/svg/GearIcon.jsx create mode 100644 client/src/utils/getError.ts create mode 100644 e2e/specs/nav.spec.js create mode 100644 e2e/specs/popup.spec.js diff --git a/client/src/components/Conversations/Conversation.jsx b/client/src/components/Conversations/Conversation.jsx index 94c26713e..d2859c858 100644 --- a/client/src/components/Conversations/Conversation.jsx +++ b/client/src/components/Conversations/Conversation.jsx @@ -123,7 +123,7 @@ export default function Conversation({ conversation, retainView }) { /> ) : ( -
+
)} ); diff --git a/client/src/components/Input/NewConversationMenu/EndpointItem.jsx b/client/src/components/Input/NewConversationMenu/EndpointItem.jsx index 824ea9423..b3e07ef8c 100644 --- a/client/src/components/Input/NewConversationMenu/EndpointItem.jsx +++ b/client/src/components/Input/NewConversationMenu/EndpointItem.jsx @@ -6,6 +6,7 @@ import { useRecoilValue } from 'recoil'; import SetTokenDialog from '../SetTokenDialog'; import store from '../../../store'; +import { cn } from '~/utils/index.jsx'; const alternateName = { openAI: 'OpenAI', @@ -15,7 +16,7 @@ const alternateName = { google: 'PaLM' }; -export default function ModelItem({ endpoint, value }) { +export default function ModelItem({ endpoint, value, isSelected }) { const [setTokenDialogOpen, setSetTokenDialogOpen] = useState(false); const endpointsConfig = useRecoilValue(store.endpointsConfig); @@ -33,8 +34,11 @@ export default function ModelItem({ endpoint, value }) { <> {icon} {alternateName[endpoint] || endpoint} @@ -42,7 +46,10 @@ export default function ModelItem({ endpoint, value }) {
{isUserProvided ? ( - ); -}); - -export default DarkMode; diff --git a/client/src/components/Nav/NavLinks.jsx b/client/src/components/Nav/NavLinks.jsx index e12553c19..72085367c 100644 --- a/client/src/components/Nav/NavLinks.jsx +++ b/client/src/components/Nav/NavLinks.jsx @@ -3,11 +3,12 @@ import { Fragment, useState } from 'react'; import { useRecoilValue } from 'recoil'; import SearchBar from './SearchBar'; import TrashIcon from '../svg/TrashIcon'; +import GearIcon from '../svg/GearIcon'; +import Settings from './Settings'; import { Download } from 'lucide-react'; import NavLink from './NavLink'; import ExportModel from './ExportConversation/ExportModel'; import ClearConvos from './ClearConvos'; -import DarkMode from './DarkMode'; import Logout from './Logout'; import { useAuthContext } from '~/hooks/AuthContext'; import { cn } from '~/utils/'; @@ -18,6 +19,7 @@ import store from '~/store'; export default function NavLinks({ clearSearch, isSearchEnabled }) { const [showExports, setShowExports] = useState(false); const [showClearConvos, setShowClearConvos] = useState(false); + const [showSettings, setShowSettings] = useState(false); const { user } = useAuthContext(); const conversation = useRecoilValue(store.conversation) || {}; @@ -47,7 +49,7 @@ export default function NavLinks({ clearSearch, isSearchEnabled }) { @@ -78,7 +80,7 @@ export default function NavLinks({ clearSearch, isSearchEnabled }) { } text="Export conversation" @@ -86,9 +88,6 @@ export default function NavLinks({ clearSearch, isSearchEnabled }) { />
- - - setShowClearConvos(true)} /> + + } + text="Settings" + clickHandler={() => setShowSettings(true)} + /> +
@@ -108,6 +115,7 @@ export default function NavLinks({ clearSearch, isSearchEnabled }) { {showExports && } {showClearConvos && } + {showSettings && } ); } diff --git a/client/src/components/Nav/Settings.jsx b/client/src/components/Nav/Settings.jsx new file mode 100644 index 000000000..4e98f8573 --- /dev/null +++ b/client/src/components/Nav/Settings.jsx @@ -0,0 +1,170 @@ +import { Dialog } from '../ui/Dialog.tsx'; +import * as Tabs from '@radix-ui/react-tabs'; +import { DialogContent, DialogHeader, DialogTitle } from '../ui/Dialog.tsx'; +import { useEffect, useState, useContext } from 'react'; +import { cn } from '~/utils/'; +import { useClearConversationsMutation } from '~/data-provider'; +import { ThemeContext } from '~/hooks/ThemeContext'; +import store from '~/store'; +import { CheckIcon } from 'lucide-react'; + +export default function Settings({ open, onOpenChange }) { + const { theme, setTheme } = useContext(ThemeContext); + const { newConversation } = store.useConversation(); + const { refreshConversations } = store.useConversations(); + const clearConvosMutation = useClearConversationsMutation(); + const [isMobile, setIsMobile] = useState(false); + const [confirmClear, setConfirmClear] = useState(false); + + const clearConvos = () => { + if (confirmClear) { + console.log('Clearing conversations...'); + clearConvosMutation.mutate(); + setConfirmClear(false); + } else { + setConfirmClear(true); + } + }; + + const changeTheme = (e) => { + setTheme(e.target.value); + }; + + // check if mobile dynamically and update + useEffect(() => { + const checkMobile = () => { + if (window.innerWidth <= 768) { + setIsMobile(true); + } else { + setIsMobile(false); + } + }; + + checkMobile(); + window.addEventListener('resize', checkMobile); + }, []); + + useEffect(() => { + if (clearConvosMutation.isSuccess) { + newConversation(); + refreshConversations(); + } + }, [clearConvosMutation.isSuccess]); + + useEffect(() => { + // If the user clicks in the dialog when confirmClear is true, set it to false + const handleClick = (e) => { + if (confirmClear) { + if (e.target.id === 'clearConvosBtn' || e.target.id === 'clearConvosTxt') { + return; + } + + setConfirmClear(false); + } + }; + + window.addEventListener('click', handleClick); + return () => window.removeEventListener('click', handleClick); + }, [confirmClear]); + + return ( + + + + Settings + +
+ + + + + + + General + + + + +
+
+
+
Theme
+ +
+
+
+
+
Clear all chats
+ +
+
+
+
+
+
+
+
+ ); +} diff --git a/client/src/components/svg/GearIcon.jsx b/client/src/components/svg/GearIcon.jsx new file mode 100644 index 000000000..2f14b21d3 --- /dev/null +++ b/client/src/components/svg/GearIcon.jsx @@ -0,0 +1,19 @@ +export default function GearIcon() { + return ( + + + + + ); +} diff --git a/client/src/components/ui/AlertDialog.tsx b/client/src/components/ui/AlertDialog.tsx index bc0e7f43f..faa0b670f 100644 --- a/client/src/components/ui/AlertDialog.tsx +++ b/client/src/components/ui/AlertDialog.tsx @@ -28,7 +28,7 @@ const AlertDialogOverlay = React.forwardRef< >(({ className, children, ...props }, ref) => ( (({ className, children, ...props }, ref) => ( {children} - + Close @@ -59,13 +59,19 @@ const DialogContent = React.forwardRef< DialogContent.displayName = DialogPrimitive.Content.displayName; const DialogHeader = ({ className, ...props }: React.HTMLAttributes) => ( -
+
); DialogHeader.displayName = 'DialogHeader'; const DialogFooter = ({ className, ...props }: React.HTMLAttributes) => (
); diff --git a/client/src/components/ui/DialogTemplate.jsx b/client/src/components/ui/DialogTemplate.jsx index 0dc932ef4..eccb3010a 100644 --- a/client/src/components/ui/DialogTemplate.jsx +++ b/client/src/components/ui/DialogTemplate.jsx @@ -10,28 +10,22 @@ import { import { cn } from '~/utils/'; const DialogTemplate = forwardRef((props, ref) => { - const { - title, - description, - main, - buttons, - leftButtons, - selection, - className - } = props; + const { title, description, main, buttons, leftButtons, selection, className } = props; const { selectHandler, selectClasses, selectText } = selection || {}; const defaultSelect = 'bg-gray-900 text-white transition-colors hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-400 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-gray-100 dark:text-gray-900 dark:hover:bg-gray-200 dark:focus:ring-gray-400 dark:focus:ring-offset-gray-900'; return ( - + {title} - - {description} - + {description && ( + + {description} + + )} - {main ? main : null} +
{main ? main : null}
{leftButtons ? leftButtons : null}
diff --git a/client/src/hooks/ThemeContext.jsx b/client/src/hooks/ThemeContext.jsx index f575ab911..530f606f0 100644 --- a/client/src/hooks/ThemeContext.jsx +++ b/client/src/hooks/ThemeContext.jsx @@ -26,10 +26,14 @@ export const ThemeProvider = ({ initialTheme, children }) => { const rawSetTheme = (rawTheme) => { const root = window.document.documentElement; - const isDark = rawTheme === 'dark'; + let isDark = rawTheme === 'dark'; + + if (rawTheme === 'system') { + isDark = window.matchMedia('(prefers-color-scheme: dark)').matches; + } root.classList.remove(isDark ? 'light' : 'dark'); - root.classList.add(rawTheme); + root.classList.add(isDark ? 'dark' : 'light'); localStorage.setItem('color-theme', rawTheme); }; diff --git a/client/src/style.css b/client/src/style.css index bdbbea2b7..0cff4afb9 100644 --- a/client/src/style.css +++ b/client/src/style.css @@ -132,6 +132,24 @@ transition: all 1s ease-in-out; } */ +select { + --tw-shadow: 0 0 transparent; + -webkit-appearance: none; + appearance: none; + background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%238e8ea0' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3E%3C/svg%3E"); + background-position: right .5rem center; + background-repeat: no-repeat; + background-size: 1.5em 1.5em; + padding-right: 2.5rem; + background-color: #fff; + border-color: #8e8ea0; + border-radius: 0; + border-width: 1px; + font-size: 1rem; + line-height: 1.5rem; + padding: .5rem .75rem; +} + .overflow-y-auto { overflow-y: overlay; } diff --git a/client/src/utils/buildTree.js b/client/src/utils/buildTree.js index 4b5e0e0dd..b35e5eb3f 100644 --- a/client/src/utils/buildTree.js +++ b/client/src/utils/buildTree.js @@ -1,7 +1,7 @@ const even = 'w-full border-b border-black/10 dark:border-gray-900/50 text-gray-800 bg-white dark:text-gray-100 group dark:bg-gray-800 hover:bg-gray-100/25 hover:text-gray-700 dark:hover:bg-gray-900 dark:hover:text-gray-200'; const odd = - 'w-full border-b border-black/10 bg-gray-50 dark:border-gray-900/50 text-gray-800 dark:text-gray-100 group bg-gray-100 dark:bg-[#444654] hover:bg-gray-100/40 hover:text-gray-700 dark:hover:bg-[#3b3d49] dark:hover:text-gray-200'; + 'w-full border-b border-black/10 bg-gray-50 dark:border-gray-900/50 text-gray-800 dark:text-gray-100 group bg-gray-100 dark:bg-gray-1000 hover:bg-gray-100/40 hover:text-gray-700 dark:hover:bg-[#3b3d49] dark:hover:text-gray-200'; export default function buildTree(messages, groupAll = false) { if (messages === null) return null; diff --git a/client/src/utils/getError.ts b/client/src/utils/getError.ts new file mode 100644 index 000000000..915aa86ac --- /dev/null +++ b/client/src/utils/getError.ts @@ -0,0 +1,29 @@ + +const isJson = (str) => { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; +} + +const getError = (text) => { + const errorMessage = text.length > 512 ? text.slice(0, 512) + '...' : text; + const match = text.match(/\{[^{}]*\}/); + let json = match ? match[0] : ''; + if (isJson(json)) { + json = JSON.parse(json); + if (json.code === 'invalid_api_key') { + return 'Invalid API key. Please check your API key and try again. You can do this by clicking on the model logo in the left corner of the textbox and selecting "Set Token" for the current selected endpoint. Thank you for your understanding.'; + } else if (json.type === 'insufficient_quota') { + return 'We apologize for any inconvenience caused. The default API key has reached its limit. To continue using this service, please set up your own API key. You can do this by clicking on the model logo in the left corner of the textbox and selecting "Set Token" for the current selected endpoint. Thank you for your understanding.'; + } else { + return `Oops! Something went wrong. Please try again in a few moments. Here's the specific error message we encountered: ${errorMessage}`; + } + } else { + return `Oops! Something went wrong. Please try again in a few moments. Here's the specific error message we encountered: ${errorMessage}`; + } +}; + +export default getError; \ No newline at end of file diff --git a/client/tailwind.config.cjs b/client/tailwind.config.cjs index 6e118d2f0..92259f85f 100644 --- a/client/tailwind.config.cjs +++ b/client/tailwind.config.cjs @@ -39,7 +39,8 @@ module.exports = { '600': '#565869', '700': '#40414f', // Replacing .dark .dark:bg-gray-700 and .dark .dark:hover:bg-gray-700:hover '800': '#343541', // Replacing .dark .dark:bg-gray-800, .bg-gray-800, and .dark .dark:hover:bg-gray-800\/90 - '900': '#202123' // Replacing .dark .dark:bg-gray-900, .bg-gray-900, and .dark .dark:hover:bg-gray-900:hover + '900': '#202123', // Replacing .dark .dark:bg-gray-900, .bg-gray-900, and .dark .dark:hover:bg-gray-900:hover + '1000': '#444654' }, green: { 50: "#f1f9f7", diff --git a/e2e/specs/landing.spec.js b/e2e/specs/landing.spec.js index 0b8072d6e..bc88c4e93 100644 --- a/e2e/specs/landing.spec.js +++ b/e2e/specs/landing.spec.js @@ -12,7 +12,41 @@ test.describe('Landing suite', () => { test('Landing title', async () => { const page = await myBrowser.newPage(); await page.goto('http://localhost:3080/'); - const pageTitle = await page.textContent('#landing-title') + const pageTitle = await page.textContent('#landing-title'); expect(pageTitle.length).toBeGreaterThan(0); }); + + test('Create Conversation', async () => { + const page = await myBrowser.newPage(); + await page.goto('http://localhost:3080/'); + + async function getItems() { + const navDiv = await page.waitForSelector('nav > div'); + if (!navDiv) { + return []; + } + + const items = await navDiv.$$('a.group'); + return items || []; + } + + // Wait for the page to load and the SVG loader to disappear + await page.waitForSelector('nav > div'); + await page.waitForSelector('nav > div > div > svg', { state: 'detached' }); + + let beforeAdding = (await getItems()).length; + + const input = await page.locator('form').getByRole('textbox'); + await input.click(); + await input.fill('Hi!'); + + // Send the message + await page.locator('form').getByRole('button').nth(1).click(); + + // Wait for the message to be sent + await page.waitForTimeout(15000); + let afterAdding = (await getItems()).length; + + expect(afterAdding).toBeGreaterThan(beforeAdding); + }); }); diff --git a/e2e/specs/nav.spec.js b/e2e/specs/nav.spec.js new file mode 100644 index 000000000..429f0790b --- /dev/null +++ b/e2e/specs/nav.spec.js @@ -0,0 +1,59 @@ +import { expect, test } from '@playwright/test'; + +test.describe('Navigation suite', () => { + let myBrowser; + + test.beforeEach(async ({ browser }) => { + myBrowser = await browser.newContext({ + storageState: 'e2e/auth.json', + }); + }); + + test('Navigation bar', async () => { + const page = await myBrowser.newPage(); + await page.goto('http://localhost:3080/'); + + await page.locator('[id="headlessui-menu-button-\\:r0\\:"]').click(); + const navBar = await page.locator('[id="headlessui-menu-button-\\:r0\\:"]').isVisible(); + expect(navBar).toBeTruthy(); + }); + + test('Settings modal', async () => { + const page = await myBrowser.newPage(); + await page.goto('http://localhost:3080/'); + await page.locator('[id="headlessui-menu-button-\\:r0\\:"]').click(); + await page.getByText('Settings').click(); + + const modal = await page.getByRole('dialog', { name: 'Settings' }).isVisible(); + expect(modal).toBeTruthy(); + + const modalTitle = await page.getByRole('heading', { name: 'Settings' }).textContent(); + expect(modalTitle.length).toBeGreaterThan(0); + expect(modalTitle).toEqual('Settings'); + + const modalTabList = await page.getByRole('tablist', { name: 'Settings' }).isVisible(); + expect(modalTabList).toBeTruthy(); + + const generalTabPanel = await page.getByRole('tabpanel', { name: 'General' }).isVisible(); + expect(generalTabPanel).toBeTruthy(); + + const modalClearConvos = await page.getByRole('button', { name: 'Clear' }).isVisible(); + expect(modalClearConvos).toBeTruthy(); + + const modalTheme = await page.getByRole('combobox'); + expect(modalTheme.isVisible()).toBeTruthy(); + + async function changeMode(theme) { + // change the value to 'dark' and 'light' and see if the theme changes + await modalTheme.selectOption({ label: theme }); + await page.waitForTimeout(1000); + + // Check if the HTML element has the theme class + const html = await page.$eval('html', (element, theme) => element.classList.contains(theme.toLowerCase()), theme); + expect(html).toBeTruthy(); + } + + await changeMode('Dark'); + await changeMode('Light'); + }); +}); diff --git a/e2e/specs/popup.spec.js b/e2e/specs/popup.spec.js new file mode 100644 index 000000000..09158516a --- /dev/null +++ b/e2e/specs/popup.spec.js @@ -0,0 +1,24 @@ +import { expect, test } from '@playwright/test'; + +test.describe('Endpoints Presets suite', () => { + let myBrowser; + + test.beforeEach(async ({ browser }) => { + myBrowser = await browser.newContext({ + storageState: 'e2e/auth.json', + }); + }); + + test('Endpoints Suite', async () => { + const page = await myBrowser.newPage(); + await page.goto('http://localhost:3080/'); + await page.getByRole('button', { name: 'New Topic' }).click(); + + const endpointItem = await page.getByRole('menuitemradio', { name: 'OpenAI' }) + await endpointItem.click(); + + await page.getByRole('button', { name: 'New Topic' }).click(); + // Check if the active class is set on the selected endpoint + expect(await endpointItem.getAttribute('class')).toContain('active'); + }); +});