Skip to content

Commit d5e80bd

Browse files
authored
refactored attachment test functions to work with images #1338 (#1347)
* 1st draft at adding obj-store-api to github actions #1088 * add OS api to CI #1088 * Updated cypress support functions to handle object storage api #1088 * updated cypress command to point to correct database #1088 * added CRUD functions and tests for attachments TODO: add download test #1338 * added tests for download functionality #1338 * fix linting * refactored attachment test functions to work with images #1338 * fix failing tests #1338 * move attachments test into items suite #1338 * change config for quick testing on CI: Revert later #1338 * diagnose * REVERT LATER: Delete other cypress tests #1338 * diagnose * attempted fix to minio * attempted fix * Revert "REVERT LATER: Delete other cypress tests #1338" This reverts commit eebb68b. * Revert "change config for quick testing on CI: Revert later #1338" This reverts commit ac2193c. * Moved attachments into catalogue items tests suite #1338 * finish moving to catalogue items #1338 * finish moving Attachments to catalogue items #1338 * update images button access #1338
1 parent 37acd25 commit d5e80bd

File tree

3 files changed

+101
-38
lines changed

3 files changed

+101
-38
lines changed

.github/workflows/ci-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ jobs:
146146
mv -v inventory-management-system/* .
147147
cd object-storage-api/
148148
149+
149150
- name: Start MongoDB and MinIO (For object-storage-api)
150151
working-directory: ../object-storage-api
151152
run: |

cypress/e2e/with_api/catalogueItems/catalogueItems.cy.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import {
55
import { addManufacturer } from '../manufacturers/functions';
66
import { addUnits } from '../units/functions';
77
import {
8-
addAttachment,
98
addCatalogueItem,
9+
addFile,
1010
copyToCatalogueItems,
11-
deleteAttachment,
12-
downloadAttachment,
11+
deleteFile,
12+
downloadFile,
1313
duplicateCatalogueItem,
14-
editAttachment,
1514
editCatalogueItem,
15+
editFile,
1616
moveToCatalogueItems,
1717
obsoleteCatalogueItem,
1818
} from './functions';
@@ -25,6 +25,7 @@ describe('catalogue items', () => {
2525
'manufacturers',
2626
'units',
2727
'attachments',
28+
'images',
2829
]);
2930
// Prepare relevant data for catalogue items
3031
cy.visit('/manufacturers');
@@ -43,32 +44,57 @@ describe('catalogue items', () => {
4344
'manufacturers',
4445
'units',
4546
'attachments',
47+
'images',
4648
]);
4749
});
4850

49-
it('CRUD for catalogue items and attachments', () => {
51+
it('CRUD for catalogue items, images and attachments', () => {
5052
addCatalogueItem();
5153
cy.findAllByText('Plano-Convex Lens').first().click();
52-
addAttachment(
54+
addFile(
5355
{
5456
files: [
5557
'cypress/fixtures/documents/test1.txt',
5658
'cypress/fixtures/documents/test2.txt',
5759
],
5860
},
61+
'attachment',
5962
true
6063
);
61-
editAttachment(
64+
editFile(
6265
{
6366
originalFileName: 'test1.txt',
6467
newFileName: 'test file',
6568
title: 'test title',
6669
description: 'test description',
6770
},
71+
'attachment',
6872
true
6973
);
70-
downloadAttachment('test file.txt');
71-
deleteAttachment(['test2.txt', 'test file.txt']);
74+
downloadFile('test file.txt', 'attachment');
75+
deleteFile(['test2.txt', 'test file.txt'], 'attachment');
76+
addFile(
77+
{
78+
files: [
79+
'cypress/fixtures/images/logo1.png',
80+
'cypress/fixtures/images/logo2.png',
81+
],
82+
},
83+
'image',
84+
true
85+
);
86+
editFile(
87+
{
88+
originalFileName: 'logo1.png',
89+
newFileName: 'badge',
90+
title: 'test title',
91+
description: 'test description',
92+
},
93+
'image',
94+
true
95+
);
96+
downloadFile('logo2.png', 'image');
97+
deleteFile(['badge.png', 'logo2.png'], 'image');
7298
cy.findByText('Spherical Lenses').click();
7399
editCatalogueItem();
74100
duplicateCatalogueItem('Plano-Convex Lens 2');

cypress/e2e/with_api/catalogueItems/functions.ts

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -346,25 +346,35 @@ export const editCatalogueItem = () => {
346346
});
347347
};
348348

349-
export const addAttachment = (
349+
export const addFile = (
350350
values: {
351351
files: string[];
352352
},
353+
type: 'image' | 'attachment',
353354
ignoreChecks?: boolean
354355
) => {
355-
cy.findByText('Attachments').click();
356+
const tabValue = type === 'image' ? 'Gallery' : 'Attachments';
357+
const uploadButton =
358+
type === 'image' ? 'Upload Images' : 'Upload Attachments';
359+
cy.findByText(tabValue).click();
356360
cy.findByRole('button', {
357-
name: 'Upload Attachments',
361+
name: uploadButton,
358362
}).click();
359363

360364
cy.findAllByText('Files cannot be larger than', { exact: false }).should(
361365
'exist'
362366
);
363367
cy.get('.uppy-Dashboard-input').as('fileInput');
364368

365-
cy.get('@fileInput').first().selectFile(values.files, { force: true });
369+
if (type === 'image') {
370+
cy.get('@fileInput').last().selectFile(values.files, { force: true });
371+
} else {
372+
cy.get('@fileInput').first().selectFile(values.files, { force: true });
373+
}
366374

367-
cy.findByText('Upload 2 files').click({ force: true });
375+
cy.findByText(
376+
`Upload ${values.files.length} file${values.files.length > 1 ? 's' : ''}`
377+
).click({ force: true });
368378

369379
cy.findByText('Uploading').should('not.exist');
370380

@@ -379,7 +389,7 @@ export const addAttachment = (
379389
});
380390

381391
if (!ignoreChecks) {
382-
cy.findByText('Attachments').click();
392+
cy.findByText(tabValue).click();
383393
for (let i = 0; i++; i < values.files.length) {
384394
const fileName = values.files[i].slice(
385395
values.files[i].lastIndexOf('/') + 1
@@ -389,33 +399,40 @@ export const addAttachment = (
389399
}
390400
};
391401

392-
export const editAttachment = (
402+
export const editFile = (
393403
values: {
394404
originalFileName: string;
395405
newFileName?: string;
396406
description?: string;
397407
title?: string;
398408
},
409+
type: 'image' | 'attachment',
399410
ignoreChecks: boolean
400411
) => {
401-
cy.findByText('Attachments').click();
412+
const tabValue = type === 'image' ? 'Gallery' : 'Attachments';
413+
cy.findByText(tabValue).click();
402414
cy.findAllByText(`${values.originalFileName}`).last().scrollIntoView();
403415

404416
cy.findAllByText(`${values.originalFileName}`).last().should('exist');
405417

406-
cy.findByRole('row', { name: `${values.originalFileName} row` }).within(
407-
() => {
408-
cy.findByLabelText('Row Actions').click();
409-
}
410-
);
411-
cy.findByLabelText(`Edit ${values.originalFileName} attachment`).click();
418+
if (type === 'image') {
419+
cy.findAllByLabelText('Card Actions').first().click();
420+
cy.findAllByText('Edit').last().click();
421+
} else {
422+
cy.findByRole('row', { name: `${values.originalFileName} row` }).within(
423+
() => {
424+
cy.findByLabelText('Row Actions').click();
425+
}
426+
);
427+
cy.findByLabelText(`Edit ${values.originalFileName} attachment`).click();
428+
}
412429

413430
cy.findByRole('dialog')
414431
.should('be.visible')
415432
.within(() => {
416433
if (values.newFileName) {
417434
cy.findByLabelText('File Name *').clear();
418-
cy.findByText('.txt').should('exist');
435+
cy.findByText(type === 'attachment' ? '.txt' : '.png').should('exist');
419436
cy.findByLabelText('File Name *').type(values.newFileName);
420437
}
421438

@@ -433,7 +450,7 @@ export const editAttachment = (
433450
cy.findByRole('dialog').should('not.exist');
434451

435452
if (!ignoreChecks) {
436-
cy.findByText('Attachments').click();
453+
cy.findByText(type).click();
437454
cy.findByText(values.newFileName ?? values.originalFileName).should(
438455
'exist'
439456
);
@@ -446,29 +463,48 @@ export const editAttachment = (
446463
}
447464
};
448465

449-
export const downloadAttachment = (fileName: string) => {
450-
cy.findByText('Attachments').click();
451-
cy.findByLabelText(`${fileName} row`).within(() => {
452-
cy.findByLabelText('Row Actions').click();
453-
});
454-
cy.findByLabelText(`Download ${fileName} attachment`).click();
466+
export const downloadFile = (
467+
fileName: string,
468+
type: 'image' | 'attachment'
469+
) => {
470+
const tabValue = type === 'image' ? 'Gallery' : 'Attachments';
471+
cy.findByText(tabValue).click();
472+
if (type === 'image') {
473+
cy.findAllByLabelText('Card Actions').first().click();
474+
cy.findAllByText('Download').last().click();
475+
} else {
476+
cy.findByLabelText(`${fileName} row`).within(() => {
477+
cy.findByLabelText('Row Actions').click();
478+
});
479+
cy.findByLabelText(`Download ${fileName} attachment`).click();
480+
}
481+
455482
cy.findByRole('dialog').should('be.visible');
456483

457484
cy.findByRole('button', { name: 'Continue' }).click();
458485
};
459486

460-
export const deleteAttachment = (fileNames: string[]) => {
461-
cy.findByText('Attachments').click();
487+
export const deleteFile = (
488+
fileNames: string[],
489+
type: 'image' | 'attachment'
490+
) => {
491+
const tabValue = type === 'image' ? 'Gallery' : 'Attachments';
492+
cy.findByText(tabValue).click();
462493
fileNames.forEach((fileName) => {
463-
cy.findByLabelText(`${fileName} row`).within(() => {
464-
cy.findByLabelText('Row Actions').click();
465-
});
494+
if (type === 'image') {
495+
cy.findAllByLabelText('Card Actions').first().click();
496+
cy.findAllByText('Delete').last().click();
497+
} else {
498+
cy.findByLabelText(`${fileName} row`).within(() => {
499+
cy.findByLabelText('Row Actions').click();
500+
});
501+
cy.findByLabelText(`Delete attachment ${fileName}`).click();
502+
}
466503

467-
cy.findByLabelText(`Delete attachment ${fileName}`).click();
468504
cy.findByRole('dialog').should('be.visible');
469505

470506
cy.findByRole('button', { name: 'Continue' }).click();
471507

472-
cy.findByRole('dialog').should('not.exist', { timeout: 4000 });
508+
cy.findByRole('dialog').should('not.exist');
473509
});
474510
};

0 commit comments

Comments
 (0)