Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Dec 11, 2024
1 parent f3f253c commit 3d3f485
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
30 changes: 30 additions & 0 deletions cypress/e2e/map/map.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// /map is used by the mobile application to display the map and have access to its feature
import { MAP_ITEMS_PATH } from '@/config/paths';
import {
CREATE_ITEM_FOLDER_ID,
FOLDER_FORM_DESCRIPTION_ID,
buildMapViewId,
} from '@/config/selectors';

describe('Map', () => {
it('open create folder modal on Home', () => {
cy.setUpApi();
cy.visit(MAP_ITEMS_PATH);

// home id
cy.get(`#${buildMapViewId(undefined)}`).should('be.visible');

// select a country
cy.get(`#${buildMapViewId(undefined)} input`).click();
cy.get(`#${buildMapViewId(undefined)} [role="presentation"]`).click();

// open location button
cy.get(`#${buildMapViewId(undefined)}`).click();
cy.get(`#${buildMapViewId(undefined)} img[role="button"]`).click();
cy.get(`[data-testid="AddLocationAltIcon"]`).click();

// open folder form
cy.get(`#${CREATE_ITEM_FOLDER_ID}`).click();
cy.get(`#${FOLDER_FORM_DESCRIPTION_ID}`).should('be.visible');
});
});
4 changes: 3 additions & 1 deletion cypress/support/createUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@graasp/sdk';

import {
ADD_FOLDER_BUTTON_CY,
CREATE_ITEM_APP_ID,
CREATE_ITEM_BUTTON_ID,
CREATE_ITEM_CLOSE_BUTTON_ID,
Expand All @@ -16,6 +17,7 @@ import {
DASHBOARD_UPLOADER_ID,
H5P_DASHBOARD_UPLOADER_ID,
ZIP_DASHBOARD_UPLOADER_ID,
buildDataCyWrapper,
} from '../../src/config/selectors';
import { InternalItemType } from '../../src/config/types';
import { ZIPInternalItem } from '../fixtures/files';
Expand Down Expand Up @@ -43,7 +45,7 @@ export const createFolder = (
payload: { name?: string; description?: string },
options?: { confirm?: boolean },
): void => {
cy.get(`#${CREATE_ITEM_BUTTON_ID}`).click({ force: true });
cy.get(buildDataCyWrapper(ADD_FOLDER_BUTTON_CY)).click({ force: true });
cy.fillFolderModal(payload, options);
};

Expand Down
4 changes: 3 additions & 1 deletion src/components/item/form/folder/NewFolderButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FolderPlus } from 'lucide-react';

import useModalStatus from '@/components/hooks/useModalStatus';
import { useBuilderTranslation } from '@/config/i18n';
import { ADD_FOLDER_BUTTON_CY } from '@/config/selectors';
import { BUILDER } from '@/langs/constants';

import { FolderCreateForm } from './FolderCreateForm';
Expand Down Expand Up @@ -50,9 +51,10 @@ export const NewFolderButton = ({
</IconButton>
) : (
<Button
dataCy={ADD_FOLDER_BUTTON_CY}
onClick={handleClickOpen}
color="primary"
aria-label="add"
aria-label="add-folder"
startIcon={<FolderPlus />}
size={size}
data-umami-event="new-folder-button"
Expand Down
3 changes: 2 additions & 1 deletion src/config/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const buildFileItemId = (id: string): string => `file-${id}`;
export const ITEM_PANEL_ID = 'itemPanelMetadata';
export const ITEM_PANEL_NAME_ID = 'itemPanelName';
export const ITEM_PANEL_TABLE_ID = 'itemPanelTable';
export const CREATE_ITEM_FOLDER_ID = 'createItemSpace';
export const CREATE_ITEM_FOLDER_ID = 'createItemFolder';
export const CREATE_ITEM_LINK_ID = 'createItemLink';
export const CREATE_ITEM_FILE_ID = 'createItemFile';
export const ITEM_FORM_LINK_INPUT_ID = 'itemFormLinkInput';
Expand Down Expand Up @@ -451,3 +451,4 @@ export const MEMBERSHIP_REQUEST_REJECT_BUTTON_SELECTOR =
export const ENROLL_BUTTON_SELECTOR = 'enrollButton';
export const VISIBILITY_HIDDEN_ALERT_ID = 'visibilityHiddenAlert';
export const SHARE_ITEM_CANCEL_BUTTON_CY = 'shareItemCancelButton';
export const ADD_FOLDER_BUTTON_CY = 'addFolder';

0 comments on commit 3d3f485

Please sign in to comment.