11const API_URL = Cypress . config ( "apiUrl" ) ;
22console . log ( API_URL ) ;
33
4- let consoleSpy ; // keeps track of every time an error is written to the console
5- Cypress . on ( "window:before:load" , ( win ) => {
6- consoleSpy = cy . spy ( win . console , "error" ) ;
7- } ) ;
8-
9- let sample_ids = [
4+ let item_ids = [
105 "12345678910" ,
116 "test1" ,
127 "test2" ,
@@ -34,15 +29,17 @@ let sample_ids = [
3429let collection_ids = [ "test_collection" ] ;
3530
3631before ( ( ) => {
37- cy . visit ( "/" ) ;
38- cy . removeAllTestSamples ( sample_ids , true ) ;
39- cy . removeAllTestCollections ( collection_ids , true ) ;
32+ cy . cleanTestEnvironment ( {
33+ itemIds : item_ids ,
34+ collectionIds : collection_ids ,
35+ } ) ;
4036} ) ;
4137
4238after ( ( ) => {
43- cy . visit ( "/" ) ;
44- cy . removeAllTestSamples ( sample_ids , true ) ;
45- cy . removeAllTestCollections ( collection_ids , true ) ;
39+ cy . cleanTestEnvironment ( {
40+ itemIds : item_ids ,
41+ collectionIds : collection_ids ,
42+ } ) ;
4643} ) ;
4744
4845describe ( "Sample table page" , ( ) => {
@@ -53,11 +50,11 @@ describe("Sample table page", () => {
5350 it ( "Loads the main page without any errors" , ( ) => {
5451 cy . findByText ( "About" ) . should ( "exist" ) ;
5552 cy . findByText ( "Samples" ) . should ( "exist" ) ;
56- cy . findByText ( "Add an item") . should ( "exist" ) ;
53+ cy . findByTestId ( "add- item-button ") . should ( "exist" ) ;
5754 cy . findByText ( "# of blocks" ) . should ( "exist" ) ;
5855
5956 cy . contains ( "Server Error. Sample list could not be retreived." ) . should ( "not.exist" ) ;
60- expect ( consoleSpy ) . not . to . be . called ;
57+ cy . get ( "@ consoleSpy" ) . should ( " not.be.called" ) ;
6158 } ) ;
6259
6360 it ( "Adds a valid sample" , ( ) => {
@@ -77,7 +74,7 @@ describe("Sample table page", () => {
7774 } ) ;
7875
7976 it ( "Attempts to add an item with the same name" , ( ) => {
80- cy . findByText ( "Add an item" ) . click ( ) ;
77+ cy . openAndWaitForModal ( "[data-testid=add- item-button]" ) ;
8178 cy . get ( '[data-testid="create-item-form"]' ) . within ( ( ) => {
8279 cy . findByLabelText ( "ID:" ) . type ( "12345678910" ) ;
8380 cy . contains ( "already in use" ) . should ( "exist" ) ;
@@ -195,11 +192,10 @@ describe.only("Advanced sample creation features", () => {
195192 } ) ;
196193
197194 it ( "Adds a third sample copied from the first" , ( ) => {
198- cy . findByText ( "Add an item" ) . click ( ) ;
195+ cy . openAndWaitForModal ( "[data-testid=add- item-button]" ) ;
199196 cy . get ( '[data-testid="create-item-form"]' ) . within ( ( ) => {
200197 cy . findByLabelText ( "ID:" ) . type ( "testAcopy" ) ;
201- cy . findByLabelText ( "(Optional) Copy from existing sample:" ) . type ( "testA" ) ;
202- cy . get ( ".vs__dropdown-menu" ) . contains ( ".badge" , "testA" ) . click ( ) ;
198+ cy . selectVsOption ( "copy-from-select" , "testA" , { dataTestId : true } ) ;
203199 cy . findByDisplayValue ( "COPY OF the first test sample" ) . clear ( ) . type ( "a copied sample" ) ;
204200 cy . findByText ( "Submit" ) . click ( ) ;
205201 } ) ;
@@ -226,14 +222,12 @@ describe.only("Advanced sample creation features", () => {
226222
227223 cy . get ( ".datablock-content div" ) . first ( ) . type ( "a comment is added here." ) ;
228224 cy . expandIfCollapsed ( "[data-testid=synthesis-block]" ) ;
229- cy . get ( "#synthesis-information .vs__search" ) . first ( ) . type ( "component3" ) ;
230- cy . get ( ".vs__dropdown-menu" ) . contains ( ".badge" , "component3" ) . click ( ) ;
225+ cy . selectVsOption ( "synthesis-table" , "component3" , { dataTestId : true } ) ;
231226
232227 cy . get ( "#synthesis-information tbody tr:nth-of-type(1) input" ) . eq ( 0 ) . type ( "30" ) ;
233228
234229 cy . get ( "svg.add-row-button" ) . click ( ) ;
235- cy . get ( "#synthesis-information .vs__search" ) . first ( ) . type ( "component4" ) ;
236- cy . get ( ".vs__dropdown-menu" ) . contains ( ".badge" , "component4" ) . click ( ) ;
230+ cy . selectVsOption ( "synthesis-table" , "component4" , { dataTestId : true } ) ;
237231
238232 cy . get ( "#synthesis-information tbody tr:nth-of-type(2) input" ) . eq ( 0 ) . type ( "100" ) ; // eq(1) gets the second element that matches
239233
@@ -244,11 +238,10 @@ describe.only("Advanced sample creation features", () => {
244238 } ) ;
245239
246240 it ( "copies the second sample" , ( ) => {
247- cy . findByText ( "Add an item" ) . click ( ) ;
241+ cy . openAndWaitForModal ( "[data-testid=add- item-button]" ) ;
248242 cy . get ( '[data-testid="create-item-form"]' ) . within ( ( ) => {
249243 cy . findByLabelText ( "ID:" ) . type ( "testBcopy" ) ;
250- cy . findByLabelText ( "(Optional) Copy from existing sample:" ) . type ( "testB" ) ;
251- cy . get ( ".vs__dropdown-menu" ) . contains ( ".badge" , "testB" ) . click ( ) ;
244+ cy . selectVsOption ( "copy-from-select" , "testB" , { dataTestId : true } ) ;
252245 cy . findByText ( "Submit" ) . click ( ) ;
253246 } ) ;
254247 cy . verifySample ( "testBcopy" , "COPY OF the second test sample" ) ;
@@ -269,23 +262,13 @@ describe.only("Advanced sample creation features", () => {
269262 } ) ;
270263
271264 it ( "copies the copied sample, this time with additional components" , ( ) => {
272- cy . findByText ( "Add an item" ) . click ( ) ;
265+ cy . openAndWaitForModal ( "[data-testid=add- item-button]" ) ;
273266 cy . get ( '[data-testid="create-item-form"]' ) . within ( ( ) => {
274267 cy . findByLabelText ( "ID:" ) . type ( "testBcopy_copy" ) ;
275- cy . findByLabelText ( "(Optional) Copy from existing sample:" ) . type ( "testBcopy" ) ;
276- cy . findByLabelText ( "(Optional) Copy from existing sample:" )
277- . contains ( ".vs__dropdown-menu .badge" , "testBcopy" )
278- . click ( ) ;
279268
280- cy . findByLabelText ( "(Optional) Start with constituents:" ) . type ( "component2" ) ;
281- cy . findByLabelText ( "(Optional) Start with constituents:" )
282- . contains ( ".vs__dropdown-menu .badge" , "component2" )
283- . click ( ) ;
284-
285- cy . findByLabelText ( "(Optional) Start with constituents:" ) . type ( "component3" ) ;
286- cy . findByLabelText ( "(Optional) Start with constituents:" )
287- . contains ( ".vs__dropdown-menu .badge" , "component3" )
288- . click ( ) ;
269+ cy . selectVsOption ( "copy-from-select" , "testBcopy" , { dataTestId : true } ) ;
270+ cy . selectVsOption ( "start-with-constituents" , "component2" , { dataTestId : true } ) ;
271+ cy . selectVsOption ( "start-with-constituents" , "component3" , { dataTestId : true } ) ;
289272
290273 cy . findByText ( "Submit" ) . click ( ) ;
291274 } ) ;
@@ -312,6 +295,9 @@ describe.only("Advanced sample creation features", () => {
312295 cy . selectItemCheckbox ( "sample" , test_id ) ;
313296 cy . get ( '[data-testid="selected-dropdown"]' ) . click ( ) ;
314297 cy . get ( '[data-testid="add-to-collection-button"]' ) . click ( ) ;
298+
299+ cy . waitForModal ( ) ;
300+
315301 cy . findByLabelText ( "Insert into collection:" ) . type ( "test_collection" ) ;
316302 cy . findByText ( 'Create new collection: "test_collection"' ) . click ( ) ;
317303 cy . get ( 'form[data-testid="add-to-collection-form"]' ) . within ( ( ) => {
0 commit comments