Skip to content

Commit 6235703

Browse files
committed
feat: moved sleuth import functionality to import studies UI and added tests
1 parent 509b776 commit 6235703

File tree

60 files changed

+1186
-1928
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1186
-1928
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/// <reference types="cypress" />
2+
3+
describe('ImportManualCreateDialog', () => {
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('Manually create a new study', () => {
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('Manually create a new study').click();
19+
cy.contains('button', 'next').click();
20+
});
21+
22+
it('should show the create new study page', () => {
23+
cy.contains('label', 'Study Name *').should('be.visible');
24+
cy.contains('label', 'Authors').should('be.visible');
25+
cy.contains('label', 'DOI').should('be.visible');
26+
cy.contains('label', 'Journal').should('be.visible');
27+
cy.contains('label', 'PubMed ID').should('be.visible');
28+
cy.contains('label', 'PubMed Central ID').should('be.visible');
29+
cy.contains('label', 'Article Year').should('be.visible');
30+
cy.contains('label', 'article link').should('be.visible');
31+
cy.contains('label', 'Keywords').should('be.visible');
32+
cy.contains('label', 'select study data source *').should('be.visible');
33+
});
34+
35+
it('should be disabled initially', () => {
36+
cy.contains('button', 'next').should('be.disabled');
37+
});
38+
39+
it('should be enabled when name and source are entered', () => {
40+
cy.get('input[placeholder="My study name"]').click().type('new study');
41+
cy.get('input[role="combobox"]').click();
42+
cy.contains('li', 'Neurostore').click();
43+
cy.contains('button', 'next').should('not.be.disabled');
44+
});
45+
46+
it('should import studies', () => {
47+
cy.get('input[placeholder="My study name"]').click().type('new study');
48+
cy.get('input[role="combobox"]').click();
49+
cy.contains('li', 'Neurostore').click();
50+
cy.contains('button', 'next').click();
51+
cy.get('input').type('my new import{enter}');
52+
cy.contains('button', 'next').click().url().should('include', '/projects/abc123/curation');
53+
});
54+
});
55+
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/// <reference types="cypress" />
2+
3+
describe('ImportStudiesDialog', () => {
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('Search Neurostore', () => {
14+
beforeEach(() => {
15+
cy.login('mocked').visit('/projects/abc123/curation');
16+
cy.intercept('GET', '**/api/base-studies/**', {
17+
fixture: 'baseStudies/baseStudiesWithResults',
18+
}).as('baseStudiesFixture');
19+
cy.intercept('PUT', '**/api/projects/abc123').as('updateProjectFixture');
20+
cy.visit('/projects/abc123/curation').wait('@projectFixture').wait('@studysetFixture');
21+
cy.contains('button', 'import studies').click();
22+
cy.contains('button', 'next').click();
23+
});
24+
25+
it('should show the neurostore search page', () => {
26+
// we can target the table as the neurostore search is the only table HTML that appears in this workflow
27+
cy.get('.MuiTableContainer-root').should('be.visible');
28+
});
29+
30+
it('should be disabled initially', () => {
31+
cy.wait('@baseStudiesFixture').then((baseStudiesResponse) => {
32+
cy.contains(
33+
'button',
34+
`Import ${baseStudiesResponse.response?.body?.results?.length} studies from neurostore`
35+
).should('be.disabled');
36+
});
37+
});
38+
39+
it('should import studies', () => {
40+
cy.get('input[type="text"]').type('neuron');
41+
cy.get('button').contains('Search').click();
42+
cy.wait('@baseStudiesFixture').then((baseStudiesResponse) => {
43+
cy.contains(
44+
'button',
45+
`Import ${baseStudiesResponse.response?.body?.results?.length} studies from neurostore`
46+
).click();
47+
});
48+
cy.get('input').type('my new import{enter}');
49+
cy.contains('button', 'next').click().url().should('include', '/projects/abc123/curation');
50+
});
51+
});
52+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/// <reference types="cypress" />
2+
3+
describe('ImportPubmedDialog', () => {
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 Pubmed IDs', () => {
14+
beforeEach(() => {
15+
cy.login('mocked').visit('/projects/abc123/curation').wait('@projectFixture').wait('@studysetFixture');
16+
cy.intercept('PUT', '**/api/projects/abc123').as('updateProjectFixture');
17+
// not going to mock this for now as cypress does not seem to support XML fixtures
18+
// cy.intercept('POST', 'https://eutils.ncbi.nlm.nih.gov/**', {
19+
// fixture: 'NIHPMIDResponse',
20+
// }).as('NIHPMIDFixture.xml');
21+
cy.contains('button', 'import studies').click();
22+
cy.contains(/PMID/).click();
23+
cy.contains('button', 'next').click();
24+
});
25+
26+
it('should show the pmid input page', () => {
27+
cy.get('textarea[placeholder="Enter list of pubmed IDs separated by a newline"]').should('be.visible');
28+
});
29+
30+
it('should be disabled initially', () => {
31+
cy.contains('button', 'next').should('be.disabled');
32+
});
33+
34+
it('should be enabled when an input is entered', () => {
35+
cy.get('textarea[placeholder="Enter list of pubmed IDs separated by a newline"]')
36+
.click()
37+
.type('123{enter}456{enter}789');
38+
cy.contains('button', 'next').should('not.be.disabled');
39+
});
40+
41+
it('should show invalid for invalid input', () => {
42+
cy.get('textarea[placeholder="Enter list of pubmed IDs separated by a newline"]')
43+
.click()
44+
.type('123{enter}456{enter}789A');
45+
cy.contains(/format is incorrect/);
46+
cy.contains('button', 'next').should('be.disabled');
47+
});
48+
49+
it('should import studies', () => {
50+
cy.get('textarea[placeholder="Enter list of pubmed IDs separated by a newline"]')
51+
.click()
52+
.type('123{enter}456{enter}789');
53+
cy.contains('button', 'next').click();
54+
cy.get('input').type('my new import{enter}');
55+
cy.contains('button', 'next').click().url().should('include', '/projects/abc123/curation');
56+
});
57+
58+
it('should import studies via a file', () => {
59+
cy.get('label[role="button"]').selectFile('cypress/fixtures/pmids.txt');
60+
cy.contains('button', 'next').should('not.be.disabled');
61+
});
62+
});
63+
});

0 commit comments

Comments
 (0)