diff --git a/frontends/main/src/page-components/LearningResourceExpanded/AiChatSyllabusSlideDown.tsx b/frontends/main/src/page-components/LearningResourceExpanded/AiChatSyllabusSlideDown.tsx index 9300e183f3..0817f4df0d 100644 --- a/frontends/main/src/page-components/LearningResourceExpanded/AiChatSyllabusSlideDown.tsx +++ b/frontends/main/src/page-components/LearningResourceExpanded/AiChatSyllabusSlideDown.tsx @@ -34,6 +34,7 @@ const SlideDown = styled.div<{ })) const Opener = styled.div(({ theme }) => ({ + position: "relative", ":after": { content: "''", width: "100%", @@ -41,9 +42,10 @@ const Opener = styled.div(({ theme }) => ({ background: theme.custom.colors.white, display: "block", position: "absolute", - top: 0, + top: "-24px", borderBottom: `1px solid ${theme.custom.colors.lightGray2}`, zIndex: 1, + paddingTop: "24px", }, })) @@ -89,7 +91,7 @@ const StyledAiChat = styled(AiChat)<{ topPosition: number }>(({ topPosition }) => ({ ".MitAiChat--root": { - minHeight: `calc(100vh - ${topPosition + 43}px)`, + minHeight: `calc(100vh - ${topPosition}px)`, }, ".MitAiChat--entryScreenContainer": { top: topPosition, diff --git a/frontends/main/src/page-components/LearningResourceExpanded/LearningResourceExpanded.test.tsx b/frontends/main/src/page-components/LearningResourceExpanded/LearningResourceExpanded.test.tsx index 785b6189f4..72ddd6af2c 100644 --- a/frontends/main/src/page-components/LearningResourceExpanded/LearningResourceExpanded.test.tsx +++ b/frontends/main/src/page-components/LearningResourceExpanded/LearningResourceExpanded.test.tsx @@ -393,9 +393,7 @@ describe.each([true, false])( resource: course1, chatExpanded: true, }) - await user.click( - screen.getByRole("button", { name: "Ask TIM about this course" }), - ) + await user.click(screen.getByRole("button", { name: "Close" })) const dataTestId = "ai-chat-entry-screen" expect(screen.getByTestId(dataTestId)).toBeInTheDocument() @@ -407,27 +405,36 @@ describe.each([true, false])( }) }) - test.each([ - { chatExpanded: false, expectChat: false }, - { chatExpanded: true, expectChat: true }, - ])( - "When `chatExpanded=true`, chat button is pressed and interactive", - ({ chatExpanded, expectChat }) => { - if (!enabled) return - const resource = factories.learningResources.resource({ - resource_type: ResourceTypeEnum.Course, - }) - setup({ resource, chatExpanded }) + test("When `chatExpanded=false`, chat button is not pressed and chat is inert", () => { + if (!enabled) return + const resource = factories.learningResources.resource({ + resource_type: ResourceTypeEnum.Course, + }) + setup({ resource, chatExpanded: false }) - screen.getByRole("button", { - name: /Ask\sTIM/, - pressed: chatExpanded, - }) + screen.getByRole("button", { + name: /Ask\sTIM/, + pressed: false, + }) - // AiChat is always in the dom, but it's hidden and inert when not expanded. - const aiChat = screen.getByTestId("ai-chat-entry-screen") - expect(!!aiChat.closest("[inert]")).toBe(!expectChat) - }, - ) + // AiChat is always in the dom, but it's hidden and inert when not expanded. + const aiChat = screen.getByTestId("ai-chat-entry-screen") + expect(!!aiChat.closest("[inert]")).toBe(true) + }) + + test("When `chatExpanded=true`, chat is not inert until closed", async () => { + if (!enabled) return + const resource = factories.learningResources.resource({ + resource_type: ResourceTypeEnum.Course, + }) + setup({ resource, chatExpanded: true }) + + const aiChat = screen.getByTestId("ai-chat-entry-screen") + expect(!!aiChat.closest("[inert]")).toBe(false) + + await user.click(screen.getByRole("button", { name: "Close" })) + + expect(!!aiChat.closest("[inert]")).toBe(true) + }) }, ) diff --git a/frontends/main/src/page-components/LearningResourceExpanded/LearningResourceExpanded.tsx b/frontends/main/src/page-components/LearningResourceExpanded/LearningResourceExpanded.tsx index 1f0e5652d0..3abf192fb2 100644 --- a/frontends/main/src/page-components/LearningResourceExpanded/LearningResourceExpanded.tsx +++ b/frontends/main/src/page-components/LearningResourceExpanded/LearningResourceExpanded.tsx @@ -37,14 +37,6 @@ const ContentSection = styled.div<{ position: "relative", })) -const StyledAiChatSyllabusOpener = styled(AiChatSyllabusOpener)<{ - top: number -}>(({ top }) => ({ - position: "sticky", - top, - zIndex: 2, -})) - const TopContainer = styled.div<{ chatEnabled: boolean }>( ({ theme, chatEnabled }) => ({ display: "flex", @@ -238,15 +230,20 @@ const LearningResourceExpanded: React.FC = ({ ref={titleSectionRef} titleId={titleId} resource={resource} - onClickClose={closeDrawer} + onClickClose={ + chatTransitionState === ChatTransitionState.Open + ? () => onChatOpenerToggle(false) + : closeDrawer + } /> {chatEnabled ? ( <> - + {chatTransitionState !== ChatTransitionState.Open ? ( + + ) : null} ({ + position: "fixed", + right: "28px", + [theme.breakpoints.down("md")]: { + right: "16px", + }, "&&&": { flexShrink: 0, backgroundColor: theme.custom.colors.lightGray2,