Skip to content

Commit

Permalink
feat: improve settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ReidyT authored Jan 4, 2024
2 parents b5be3f0 + d7629c5 commit 0a4be78
Show file tree
Hide file tree
Showing 18 changed files with 506 additions and 303 deletions.
50 changes: 27 additions & 23 deletions cypress/e2e/builder/enterSettings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ import { Context, PermissionLevel } from '@graasp/sdk';

import { KeywordsData } from '../../../src/config/appSettingTypes';
import {
ADD_KEYWORD_BUTTON_CY,
BUILDER_VIEW_CY,
CHATBOT_CONTAINER_CY,
DELETE_KEYWORD_BUTTON_CY,
ENTER_DEFINITION_FIELD_CY,
ENTER_KEYWORD_FIELD_CY,
INITIAL_CHATBOT_PROMPT_INPUT_FIELD_CY,
INITIAL_PROMPT_INPUT_FIELD_CY,
KEYWORD_LIST_ITEM_CY,
SAVE_KEYWORDS_BUTTON_CY,
SAVE_TEXT_BUTTON_CY,
SAVE_TITLE_BUTTON_CY,
SETTINGS_SAVE_BUTTON_CY,
TEXT_INPUT_FIELD_CY,
TITLE_INPUT_FIELD_CY,
USE_CHATBOT_DATA_CY,
buildDataCy,
} from '../../../src/config/selectors';
import {
MOCK_APP_SETTINGS,
MOCK_APP_SETTINGS_USING_CHATBOT,
MOCK_INITIAL_CHATBOT_PROMPT_SETTING,
MOCK_INITIAL_PROMPT_SETTING,
MOCK_KEYWORDS_SETTING,
Expand Down Expand Up @@ -47,16 +49,17 @@ describe('Enter Settings', () => {
cy.get(buildDataCy(TITLE_INPUT_FIELD_CY))
.should('be.visible')
.type('Title');
cy.get(buildDataCy(SETTINGS_SAVE_BUTTON_CY)).click();
cy.get(buildDataCy(SETTINGS_SAVE_BUTTON_CY)).should('be.disabled');

cy.get(buildDataCy(SAVE_TITLE_BUTTON_CY)).click();
cy.get(buildDataCy(TITLE_INPUT_FIELD_CY)).type('New Title');
cy.get(buildDataCy(SETTINGS_SAVE_BUTTON_CY)).should('not.be.disabled');
cy.get(buildDataCy(SETTINGS_SAVE_BUTTON_CY)).click();
cy.get(buildDataCy(SETTINGS_SAVE_BUTTON_CY)).should('be.disabled');

cy.get(buildDataCy(SAVE_TITLE_BUTTON_CY)).should('be.disabled');

cy.get(buildDataCy(TITLE_INPUT_FIELD_CY)).type(
'{backspace}{backspace}{backspace}',
);

cy.get(buildDataCy(SAVE_TITLE_BUTTON_CY)).should('not.be.disabled');
// test that multiline is disabled, because it is rendered inline in player
cy.get(buildDataCy(TITLE_INPUT_FIELD_CY)).type('{enter}');
cy.get(buildDataCy(SETTINGS_SAVE_BUTTON_CY)).should('be.disabled');
});

it('set text', () => {
Expand All @@ -66,41 +69,42 @@ describe('Enter Settings', () => {
'Lorem ipsum dolor sit amet. Ut optio laborum qui ducimus rerum eum illum possimus non quidem facere.',
);

cy.get(buildDataCy(SAVE_TEXT_BUTTON_CY)).click();
cy.get(buildDataCy(SETTINGS_SAVE_BUTTON_CY)).click();

cy.get(buildDataCy(SAVE_TEXT_BUTTON_CY)).should('be.disabled');
cy.get(buildDataCy(SETTINGS_SAVE_BUTTON_CY)).should('be.disabled');

cy.get(buildDataCy(TEXT_INPUT_FIELD_CY)).type(
'{backspace}{backspace}{backspace}{backspace}{backspace}',
'Quis ea quod necessitatibus sit voluptas culpa ut laborum quia ad nobis numquam.',
);

cy.get(buildDataCy(SAVE_TEXT_BUTTON_CY)).should('not.be.disabled');
cy.get(buildDataCy(SETTINGS_SAVE_BUTTON_CY)).should('not.be.disabled');
});

it('set keywords', () => {
cy.get(buildDataCy(ENTER_KEYWORD_FIELD_CY))
.should('be.visible')
.type('Lorem');

cy.get(buildDataCy(KEYWORD_LIST_ITEM_CY)).should('not.exist');
cy.get(buildDataCy(ENTER_DEFINITION_FIELD_CY))
.should('be.visible')
.type('Latin');

cy.get(buildDataCy(ENTER_KEYWORD_FIELD_CY)).type('{enter}');
cy.get(buildDataCy(KEYWORD_LIST_ITEM_CY)).should('exist');
cy.get(buildDataCy(KEYWORD_LIST_ITEM_CY)).should('not.exist');

cy.get(buildDataCy(SAVE_KEYWORDS_BUTTON_CY))
cy.get(buildDataCy(ADD_KEYWORD_BUTTON_CY))
.should('be.visible')
.should('not.be.disabled')
.click()
.should('be.disabled');
cy.get(buildDataCy(KEYWORD_LIST_ITEM_CY)).should('exist');

cy.get(buildDataCy(DELETE_KEYWORD_BUTTON_CY)).should('be.visible').click();
cy.get(buildDataCy(KEYWORD_LIST_ITEM_CY)).should('not.exist');

cy.get(buildDataCy(SAVE_KEYWORDS_BUTTON_CY)).should('not.be.disabled');
});

it.only('does not use chatbot (by default)', () => {
it('does not use chatbot (by default)', () => {
cy.get(buildDataCy(USE_CHATBOT_DATA_CY)).should('not.be.checked');
cy.get(buildDataCy(CHATBOT_CONTAINER_CY)).should('not.exist');
});
});

Expand All @@ -109,7 +113,7 @@ describe('Load Settings', () => {
cy.setUpApi({
database: {
appData: [],
appSettings: MOCK_APP_SETTINGS,
appSettings: MOCK_APP_SETTINGS_USING_CHATBOT,
},
appContext: {
context: Context.Builder,
Expand Down
20 changes: 10 additions & 10 deletions cypress/fixtures/appData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const MOCK_APP_DATA: AppData[] = [
member: CURRENT_MEMBER,
creator: CURRENT_MEMBER,
item: MOCK_SERVER_ITEM,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
type: APP_DATA_TYPES.BOT_COMMENT,
visibility: AppDataVisibility.Member,
},
Expand All @@ -31,8 +31,8 @@ export const MOCK_APP_DATA: AppData[] = [
member: CURRENT_MEMBER,
creator: CURRENT_MEMBER,
item: MOCK_SERVER_ITEM,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
type: APP_DATA_TYPES.STUDENT_COMMENT,
visibility: AppDataVisibility.Member,
},
Expand All @@ -45,8 +45,8 @@ export const MOCK_APP_DATA: AppData[] = [
member: CURRENT_MEMBER,
creator: CURRENT_MEMBER,
item: MOCK_SERVER_ITEM,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
type: APP_DATA_TYPES.BOT_COMMENT,
visibility: AppDataVisibility.Member,
},
Expand All @@ -59,8 +59,8 @@ export const MOCK_APP_DATA: AppData[] = [
member: CURRENT_MEMBER,
creator: CURRENT_MEMBER,
item: MOCK_SERVER_ITEM,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
type: APP_DATA_TYPES.STUDENT_COMMENT,
visibility: AppDataVisibility.Member,
},
Expand All @@ -73,8 +73,8 @@ export const MOCK_APP_DATA: AppData[] = [
member: CURRENT_MEMBER,
creator: CURRENT_MEMBER,
item: MOCK_SERVER_ITEM,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
type: APP_DATA_TYPES.BOT_COMMENT,
visibility: AppDataVisibility.Member,
},
Expand Down
24 changes: 12 additions & 12 deletions cypress/fixtures/appSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import {
INITIAL_CHATBOT_PROMPT_SETTING_KEY,
INITIAL_PROMPT_SETTING_KEY,
KEYWORDS_SETTING_KEY,
Keyword,
TEXT_RESOURCE_SETTING_KEY,
USE_CHATBOT_SETTING_KEY,
keyword,
} from '../../src/config/appSettingTypes';
import { CURRENT_MEMBER, MOCK_SERVER_ITEM } from '../../src/data/db';

export const MOCK_TEXT_RESOURCE =
'Lorem ipsum dolor sit amet. Ut optio laborum qui ducimus rerum eum illum possimus non quidem facere. A neque quia et placeat exercitationem vel necessitatibus Quis ea quod necessitatibus sit voluptas culpa ut laborum quia ad nobis numquam. Quo quibusdam maiores et numquam molestiae ut mollitia quaerat et voluptates autem qui expedita delectus aut aliquam expedita et odit incidunt. Id quia nulla est voluptate repellat non internos voluptatem sed cumque omnis et consequatur placeat qui illum aperiam eos consequatur suscipit.';

export const MOCK_KEYWORDS: keyword[] = [
export const MOCK_KEYWORDS: Keyword[] = [
{ word: 'lorem', def: 'definition of lorem is blablabla' },
{ word: 'ispum', def: 'ipsum is blablabla' },
{ word: 'et', def: 'et means blablabla' },
Expand All @@ -28,8 +28,8 @@ export const MOCK_TEXT_RESOURCE_SETTING: AppSetting = {
data: { text: MOCK_TEXT_RESOURCE },
item: MOCK_SERVER_ITEM,
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};

export const MOCK_KEYWORDS_SETTING: AppSetting = {
Expand All @@ -38,8 +38,8 @@ export const MOCK_KEYWORDS_SETTING: AppSetting = {
data: { keywords: MOCK_KEYWORDS },
item: MOCK_SERVER_ITEM,
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};

export const MOCK_INITIAL_PROMPT_SETTING: AppSetting = {
Expand All @@ -50,8 +50,8 @@ export const MOCK_INITIAL_PROMPT_SETTING: AppSetting = {
},
item: MOCK_SERVER_ITEM,
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};

export const MOCK_INITIAL_CHATBOT_PROMPT_SETTING: AppSetting = {
Expand All @@ -62,8 +62,8 @@ export const MOCK_INITIAL_CHATBOT_PROMPT_SETTING: AppSetting = {
},
item: MOCK_SERVER_ITEM,
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};

export const MOCK_USE_CHATBOT_SETTING: AppSetting = {
Expand All @@ -74,8 +74,8 @@ export const MOCK_USE_CHATBOT_SETTING: AppSetting = {
},
item: MOCK_SERVER_ITEM,
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};

export const MOCK_APP_SETTINGS = [
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/chat/ChatbotWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CloseIcon from '@mui/icons-material/Close';
import DeleteIcon from '@mui/icons-material/Delete';
import { Box, IconButton, Tooltip, Typography } from '@mui/material';

import { keyword } from '../../../config/appSettingTypes';
import { Keyword } from '../../../config/appSettingTypes';
import { CHAT_WINDOW_CY, DICTIONNARY_MODE_CY } from '../../../config/selectors';
import {
DEFAULT_BORDER_RADIUS,
Expand All @@ -16,7 +16,7 @@ import ChatBox from './ChatBox';

type Prop = {
closeChatbot: () => void;
focusWord: keyword;
focusWord: Keyword;
useChatbot: boolean;
isOpen: boolean;
onDelete: () => void;
Expand Down
8 changes: 4 additions & 4 deletions src/components/common/display/Highlighted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import ReactMarkdown from 'react-markdown';

import { styled } from '@mui/material';

import { keyword } from '../../../config/appSettingTypes';
import { Keyword } from '../../../config/appSettingTypes';
import { DEFAULT_KEYWORD } from '../../../config/appSettings';
import KeywordButton from './KeywordButton';

type Prop = {
text: string;
words: keyword[];
words: Keyword[];
highlight: boolean;
openChatbot: (word: keyword) => void;
openChatbot: (word: Keyword) => void;
};

const StyledReactMarkdown = styled(ReactMarkdown)(({ theme }) => ({
Expand Down Expand Up @@ -43,7 +43,7 @@ const Highlighted: FC<Prop> = ({ text, words, highlight, openChatbot }) => {
const wordsLowerCase = words.map((word) => word.word.toLocaleLowerCase());
const expr = wordsLowerCase.join('|');
const parts = text.split(new RegExp(`(${expr})`, 'gi'));
const findKeyword = (part: string): keyword =>
const findKeyword = (part: string): Keyword =>
words.find((w) => w.word === part) || DEFAULT_KEYWORD;
const snippet = parts
.map((part) =>
Expand Down
6 changes: 3 additions & 3 deletions src/components/common/display/KeywordButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { FC } from 'react';

import { Button } from '@mui/material';

import { keyword } from '../../../config/appSettingTypes';
import { Keyword } from '../../../config/appSettingTypes';
import { keywordDataCy } from '../../../config/selectors';

type Prop = {
word: {
label: string;
value: keyword;
value: Keyword;
};
onClick: (word: keyword) => void;
onClick: (word: Keyword) => void;
};

const KeywordButton: FC<Prop> = ({ word, onClick }) => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/common/display/TextDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC } from 'react';

import { Box } from '@mui/material';

import { keyword } from '../../../config/appSettingTypes';
import { Keyword } from '../../../config/appSettingTypes';
import { TEXT_DISPLAY_FIELD_CY } from '../../../config/selectors';
import {
DEFAULT_BORDER_RADIUS,
Expand All @@ -14,8 +14,8 @@ import Highlighted from './Highlighted';
type Prop = {
text: string;
highlight: boolean;
openChatbot: (word: keyword) => void;
keywords: keyword[];
openChatbot: (word: Keyword) => void;
keywords: Keyword[];
width?: string;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC } from 'react';

import { Button } from '@mui/material';
import { Button, SxProps } from '@mui/material';

import { FULL_WIDTH, GRAASP_VIOLET } from '../../../config/stylingConstants';

Expand All @@ -11,15 +11,19 @@ type Prop = {
fullWidth?: boolean;
marginRight?: string;
minHeight?: string;
text: string;
sx?: SxProps;
};

const SaveButton: FC<Prop> = ({
const GraaspButton: FC<Prop> = ({
buttonDataCy,
handleOnClick,
disabled,
fullWidth = false,
marginRight,
minHeight,
text,
sx,
}) => (
<Button
data-cy={buttonDataCy}
Expand All @@ -29,12 +33,13 @@ const SaveButton: FC<Prop> = ({
minHeight,
marginRight,
...(fullWidth && { width: FULL_WIDTH }),
...sx,
}}
onClick={handleOnClick}
disabled={disabled}
>
Save
{text}
</Button>
);

export default SaveButton;
export default GraaspButton;
Loading

0 comments on commit 0a4be78

Please sign in to comment.