Notes
Notes - notes.io |
let importedFiles;
let parsedData;
let mockFileValidatorMain;
let mockFileValidator;
let mockDataValidators;
beforeEach(() => {
importedFiles = [{ name: 'test.csv', size: 500 }];
parsedData = {
meta: { fields: ['Gizmo MPN', 'Band MPN', 'Assorted'] },
data: [
{ 'Gizmo MPN': 'G123$', 'Band MPN': 'B123$', 'Assorted': '•' },
{ 'Gizmo MPN': 'G456$', 'Band MPN': 'B456$', 'Assorted': '' }
],
};
mockFileValidatorMain = jest.fn().mockResolvedValue(importedFiles);
mockFileValidator = jest.fn().mockResolvedValue({});
mockDataValidators = {
parseRawText: jest.fn().mockResolvedValue(parsedData),
convertToRowObjects: jest.fn().mockResolvedValue({ importRows: [], csvParseErrors: [] }),
validateColumns: jest.fn().mockResolvedValue([]),
};
});
it('validates the file and sets the import rows', async () => {
titleValidate.validateFile(importedFiles, mockFileValidatorMain, mockFileValidator, mockDataValidators);
await act(async () => {
expect(titleValidate.isProcessing).toBeTruthy();
});
expect(titleValidate.state.importRows).toHaveLength(1);
expect(titleValidate.configureForm.validationErrors).toHaveLength(0);
expect(titleValidate.isProcessing).toBeFalsy();
});
it('handles errors during file validation', async () => {
mockFileValidatorMain = jest.fn().mockRejectedValue(new Error('Error validating files'));
titleValidate.validateFile(importedFiles, mockFileValidatorMain, mockFileValidator, mockDataValidators);
await act(async () => {
expect(titleValidate.isProcessing).toBeTruthy();
});
expect(titleValidate.processingException).toBeTruthy();
expect(titleValidate.isProcessing).toBeFalsy();
});
it('handles parsing errors', async () => {
mockDataValidators.parseRawText = jest.fn().mockRejectedValue(new Error('Error parsing raw text'));
titleValidate.validateFile(importedFiles, mockFileValidatorMain, mockFileValidator, mockDataValidators);
await act(async () => {
expect(titleValidate.isProcessing).toBeTruthy();
});
expect(titleValidate.processingException).toBeTruthy();
expect(titleValidate.isProcessing).toBeFalsy();
});
it('handles CSV conversion errors', async () => {
mockDataValidators.convertToRowObjects = jest.fn().mockRejectedValue(new Error('Error converting CSV rows'));
titleValidate.validateFile(importedFiles, mockFileValidatorMain, mockFileValidator, mockDataValidators);
await act(async () => {
expect(titleValidate.isProcessing).toBeTruthy();
});
expect(titleValidate.processingException).toBeTruthy();
expect(titleValidate.isProcessing).toBeFalsy();
});
it('handles column validation errors', async () => {
mockDataValidators.validateColumns = jest.fn().mockRejectedValue(new Error('Error validating columns'));
titleValidate.validateFile(importedFiles, mockFileValidatorMain, mockFileValidator, mockDataValidators);
await act(async () => {
expect(titleValidate.isProcessing).toBeTruthy();
});
expect(titleValidate.processingException).toBeTruthy();
expect(titleValidate.isProcessing).toBeFalsy();
});
});
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team