Skip to content

Commit

Permalink
refactor: some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Nov 15, 2024
1 parent e45e21b commit 0c8c37e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 24 deletions.
20 changes: 0 additions & 20 deletions src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,26 +453,6 @@ describe('<CourseUnit />', () => {
window.open = open;
});

it('updates iframe height when dropdown menu is toggled', async () => {
const { getByTitle } = render(<RootWrapper />);

const ACTION_DROPDOWN_HEIGHT = 300;

await waitFor(() => {
const iframe = getByTitle(xblockContainerIframeMessages.xblockIframeTitle.defaultMessage);
expect(iframe.getAttribute('style')).toContain('height: 0px;');
});

simulatePostMessageEvent(messageTypes.toggleDropdownMenu, {
subMenuHeight: ACTION_DROPDOWN_HEIGHT,
});

await waitFor(() => {
const iframe = getByTitle(xblockContainerIframeMessages.xblockIframeTitle.defaultMessage);
expect(iframe.getAttribute('style')).toContain(`height: ${ACTION_DROPDOWN_HEIGHT}px;`);
});
});

it('checks courseUnit title changing when edit query is successfully', async () => {
const {
findByText,
Expand Down
1 change: 0 additions & 1 deletion src/course-unit/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ export const messageTypes = {
duplicateXBlock: 'duplicateXBlock',
refreshPositions: 'refreshPositions',
newXBlockEditor: 'newXBlockEditor',
toggleDropdownMenu: 'toggleDropdownMenu',
};
4 changes: 1 addition & 3 deletions src/course-unit/xblock-container-iframe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const XBlockContainerIframe: FC<XBlockContainerIframeProps> = ({
const [deleteXblockId, setDeleteXblockId] = useState<string | null>(null);
const [isDeleteModalOpen, openDeleteModal, closeDeleteModal] = useToggle(false);
const [isConfigureModalOpen, openConfigureModal, closeConfigureModal] = useToggle(false);
const [dropdownHeight, setDropdownHeight] = useState(0);
const { setIframeRef, sendMessageToIframe } = useIframe();
const [editXblockId, setEditXblockId] = useState<string | null>(null);
const [currentXblockData, setCurrentXblockData] = useState<any>({});
Expand Down Expand Up @@ -140,7 +139,6 @@ const XBlockContainerIframe: FC<XBlockContainerIframeProps> = ({
[messageTypes.duplicateXBlock]: (payload) => handleDuplicateXBlock(payload.id),
[messageTypes.refreshPositions]: handleRefreshXBlocks,
[messageTypes.newXBlockEditor]: (payload) => navigateToNewXBlockEditor(payload.url),
[messageTypes.toggleDropdownMenu]: ({ subMenuHeight }) => setDropdownHeight(subMenuHeight),
};

const handleMessage = (event: MessageEvent) => {
Expand Down Expand Up @@ -212,7 +210,7 @@ const XBlockContainerIframe: FC<XBlockContainerIframeProps> = ({
loading="lazy"
style={{
width: '100%',
height: iframeHeight + dropdownHeight,
height: iframeHeight,
}}
scrolling="no"
referrerPolicy="origin"
Expand Down

0 comments on commit 0c8c37e

Please sign in to comment.