Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 2 additions & 57 deletions cypress/support/createUtils.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import type { AppItem, DocumentItem, PackedItem } from '@/openapi/client';
import type { AppItem, DocumentItem } from '@/openapi/client';

import {
ADD_FOLDER_BUTTON_CY,
CREATE_ITEM_APP_ID,
CREATE_ITEM_BUTTON_ID,
CREATE_ITEM_CLOSE_BUTTON_ID,
CREATE_ITEM_DOCUMENT_ID,
CREATE_ITEM_FILE_ID,
CREATE_ITEM_H5P_ID,
CREATE_ITEM_ZIP_ID,
DASHBOARD_UPLOADER_ID,
H5P_DASHBOARD_UPLOADER_ID,
ZIP_DASHBOARD_UPLOADER_ID,
buildDataCyWrapper,
} from '../../src/config/selectors';
import { InternalItemType } from '../../src/modules/builder/types';
import { ZIPInternalItem } from '../e2e/builder/fixtures/files';
import { FileItemForTest } from './types';

export const createApp = (
payload: AppItem,
Expand Down Expand Up @@ -44,56 +40,14 @@ export const createFolder = (
cy.fillFolderModal(payload, options);
};

export const createFile = (
payload: FileItemForTest,
options?: { confirm?: boolean },
): void => {
cy.get(`#${CREATE_ITEM_BUTTON_ID}`).click();
const { confirm = true } = options ?? {};
cy.get(`#${CREATE_ITEM_FILE_ID}`).click();

// drag-drop a file in the uploader
cy.attachFile(
cy.get(`#${DASHBOARD_UPLOADER_ID} .uppy-Dashboard-input`).first(),
payload?.createFilepath,
{
action: 'drag-drop',
force: true,
},
);
if (confirm) {
cy.get(`#${CREATE_ITEM_CLOSE_BUTTON_ID}`).click();
}
};

// todo: question: only used by import zip ??
export const createItem = (
payload: PackedItem | ZIPInternalItem | { type: 'h5p'; filepath: string },
payload: ZIPInternalItem | { type: 'h5p'; filepath: string },
options?: { confirm?: boolean },
): void => {
cy.get(`#${CREATE_ITEM_BUTTON_ID}`).click();

switch (payload.type) {
case 'file': {
const { confirm = true } = options;
cy.get(`#${CREATE_ITEM_FILE_ID}`).click();

// drag-drop a file in the uploader
cy.attachFile(
cy.get(`#${DASHBOARD_UPLOADER_ID} .uppy-Dashboard-input`).first(),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
payload?.createFilepath,
{
action: 'drag-drop',
force: true,
},
);
if (confirm) {
cy.get(`#${CREATE_ITEM_CLOSE_BUTTON_ID}`).click();
}
break;
}
case InternalItemType.ZIP: {
cy.get(`#${CREATE_ITEM_ZIP_ID}`).click();

Expand All @@ -111,15 +65,6 @@ export const createItem = (
);
break;
}
case 'document':
cy.get(`#${CREATE_ITEM_DOCUMENT_ID}`).click();
cy.fillDocumentModal(payload, options);
break;
case 'app':
cy.get(`#${CREATE_ITEM_APP_ID}`).click();
cy.fillAppModal(payload, options);
break;
case 'folder':
default:
cy.fillFolderModal(payload, options);
break;
Expand Down