|
| 1 | +/// <reference types="cypress" /> |
| 2 | + |
| 3 | +describe('ImportFileFormatDialog', () => { |
| 4 | + beforeEach(() => { |
| 5 | + cy.clearLocalStorage(); |
| 6 | + cy.intercept('GET', 'https://api.appzi.io/**', { fixture: 'appzi' }).as('appziFixture'); |
| 7 | + cy.intercept('GET', `**/api/projects/*`, { |
| 8 | + fixture: 'projects/projectExtractionStep', |
| 9 | + }).as('projectFixture'); |
| 10 | + cy.intercept('GET', `**/api/studysets/*`, { fixture: 'studyset' }).as('studysetFixture'); |
| 11 | + }); |
| 12 | + |
| 13 | + describe('Import via File Format', () => { |
| 14 | + beforeEach(() => { |
| 15 | + cy.login('mocked').visit('/projects/abc123/curation').wait('@projectFixture').wait('@studysetFixture'); |
| 16 | + cy.intercept('PUT', '**/api/projects/abc123').as('updateProjectFixture'); |
| 17 | + cy.contains('button', 'import studies').click(); |
| 18 | + cy.contains('Import via File Format').click(); |
| 19 | + cy.contains('button', 'next').click(); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should show the standard file import page', () => { |
| 23 | + cy.contains(/enter data source/).should('be.visible'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should disable the next button initially', () => { |
| 27 | + cy.contains('button', 'next').should('be.disabled'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should set the source and show the input', () => { |
| 31 | + cy.get('input[role="combobox"]').click(); |
| 32 | + cy.contains('li', 'Scopus').click(); |
| 33 | + cy.get('textarea').should('be.visible'); |
| 34 | + cy.contains(/Input is empty/).should('be.visible'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should set the sources and enable the next button', () => { |
| 38 | + cy.get('input[role="combobox"]').click(); |
| 39 | + cy.contains('li', 'Scopus').click(); |
| 40 | + cy.get('textarea[placeholder="paste in valid endnote, bibtex, or RIS syntax"]') |
| 41 | + .click() |
| 42 | + .type( |
| 43 | + `%0 Journal Article\n%T Role of the anterior insula in task-level control and focal attention\n%A Nelson, Steven M\n%A Dosenbach, Nico UF\n%A Cohen, Alexander L\n%A Wheeler, Mark E\n%A Schlaggar, Bradley L\n%A Petersen, Steven E\n%J Brain structure and function\n%V 214\n%669-680\n%@ 1863-2653\n%D 2010\n%I Springer-Verlag\n`, |
| 44 | + { |
| 45 | + delay: 1, |
| 46 | + } |
| 47 | + ); |
| 48 | + |
| 49 | + cy.contains('button', 'next').should('not.be.disabled'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should show an error message', () => { |
| 53 | + cy.get('input[role="combobox"]').click(); |
| 54 | + cy.contains('li', 'Scopus').click(); |
| 55 | + cy.get('textarea[placeholder="paste in valid endnote, bibtex, or RIS syntax"]').type('INVALID FORMAT'); |
| 56 | + cy.contains(/Format is incorrect/).should('be.visible'); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should import studies', () => { |
| 60 | + cy.get('input[role="combobox"]').click(); |
| 61 | + cy.contains('li', 'Scopus').click(); |
| 62 | + cy.get('textarea[placeholder="paste in valid endnote, bibtex, or RIS syntax"]') |
| 63 | + .click() |
| 64 | + .type( |
| 65 | + `%0 Journal Article\n%T Role of the anterior insula in task-level control and focal attention\n%A Nelson, Steven M\n%A Dosenbach, Nico UF\n%A Cohen, Alexander L\n%A Wheeler, Mark E\n%A Schlaggar, Bradley L\n%A Petersen, Steven E\n%J Brain structure and function\n%V 214\n%669-680\n%@ 1863-2653\n%D 2010\n%I Springer-Verlag\n`, |
| 66 | + { |
| 67 | + delay: 1, |
| 68 | + } |
| 69 | + ); |
| 70 | + |
| 71 | + cy.contains('button', 'next').click(); |
| 72 | + cy.get('input').type('my new import{enter}'); |
| 73 | + cy.contains('button', 'next').click().url().should('include', '/projects/abc123/curation'); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should upload a onenote (ENW) file', () => { |
| 77 | + cy.get('input[role="combobox"]').click(); |
| 78 | + cy.contains('li', 'Scopus').click(); |
| 79 | + cy.get('label[role="button"]').selectFile('cypress/fixtures/standardFiles/onenoteStudies.txt'); |
| 80 | + cy.contains('button', 'next').should('be.visible'); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should upload a .RIS file and import successfully', () => { |
| 84 | + cy.get('input[role="combobox"]').click(); |
| 85 | + cy.contains('li', 'Scopus').click(); |
| 86 | + cy.get('label[role="button"]').selectFile('cypress/fixtures/standardFiles/ris.ris'); |
| 87 | + cy.contains('button', 'next').should('be.visible').and('not.be.disabled'); |
| 88 | + cy.contains('button', 'next').click(); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should handle the duplicates in an import file', () => { |
| 92 | + cy.get('input[role="combobox"]').click(); |
| 93 | + cy.contains('li', 'Scopus').click(); |
| 94 | + cy.get('label[role="button"]').selectFile('cypress/fixtures/standardFiles/duplicates.ris'); |
| 95 | + cy.contains('button', 'next').should('be.visible').and('not.be.disabled'); |
| 96 | + cy.contains('button', 'next').click(); |
| 97 | + cy.contains('Click to view 1 imported studies').click(); |
| 98 | + cy.contains('(2023). Manifold Learning for fMRI time-varying FC').should( |
| 99 | + // doing this to enforce strict equals |
| 100 | + ($el: JQuery<HTMLElement> | undefined) => { |
| 101 | + if (!$el) throw new Error('Could not find element'); |
| 102 | + expect($el.text()).to.equal('(2023). Manifold Learning for fMRI time-varying FC'); |
| 103 | + } |
| 104 | + ); |
| 105 | + cy.contains(/^\bbioRxiv\b/).should('exist'); // \b is a word boundary which means there shouldnt be any other letters/words before and after |
| 106 | + }); |
| 107 | + |
| 108 | + // TODO : create a test for importing bibtex file |
| 109 | + // it('should import studies via a file', () => {}) |
| 110 | + }); |
| 111 | +}); |
0 commit comments