11/**
2- * Copyright (C) 2020 The Software Heritage developers
2+ * Copyright (C) 2020-2025 The Software Heritage developers
33 * See the AUTHORS file at the top-level directory of this distribution
44 * License: GNU Affero General Public License version 3, or any later version
55 * See top-level LICENSE file for more information
@@ -395,31 +395,62 @@ describe('Author order change', function() {
395395 } ) ;
396396 } ) ;
397397
398+ it ( 'moves roles with person' , function ( ) {
399+ cy . get ( '#name' ) . type ( 'My Test Software' ) ;
400+
401+ cy . get ( '#author_add' ) . click ( ) ;
402+ cy . get ( '#author_1_givenName' ) . type ( 'Jane' ) ;
403+
404+ cy . get ( '#author_add' ) . click ( ) ;
405+ cy . get ( '#author_2_givenName' ) . type ( 'John' ) ;
406+
407+ cy . get ( '#author_1_role_add' ) . click ( ) ;
408+ cy . get ( '#author_1_roleName_0' ) . type ( 'Developer' ) ;
409+ cy . get ( '#author_1_roleName_0' ) . should ( 'have.value' , 'Developer' ) ;
410+
411+ // Move author 1 to the right (swap with author 2)
412+ cy . get ( '#author_1_moveToRight' ) . click ( ) ;
413+
414+ // After the swap, Jane (and her role) should be at author_2
415+ cy . get ( '#author_2_givenName' ) . should ( 'have.value' , 'Jane' ) ;
416+ cy . get ( '#author_2_roleName_0' ) . should ( 'have.value' , 'Developer' ) ;
417+
418+ // John should now be at author_1 and should not have the role
419+ cy . get ( '#author_1_givenName' ) . should ( 'have.value' , 'John' ) ;
420+ cy . get ( '#author_1_roleName_0' ) . should ( 'not.exist' ) ;
421+ } ) ;
422+
398423 it ( 'wraps around to the right' , function ( ) {
399424 cy . get ( '#name' ) . type ( 'My Test Software' ) ;
400425
401426 cy . get ( '#author_add' ) . click ( ) ;
402427 cy . get ( '#author_add' ) . click ( ) ;
403428 cy . get ( '#author_add' ) . click ( ) ;
404- cy . get ( '#author_1_givenName' ) . type ( 'Jane' ) ;
429+ cy . get ( '#author_add' ) . click ( ) ;
430+ cy . get ( '#author_1_givenName' ) . type ( 'One' ) ;
405431 cy . get ( '#author_1_affiliation' ) . type ( 'Example Org' ) ;
406- cy . get ( '#author_2_givenName' ) . type ( 'John' ) ;
407- cy . get ( '#author_2_familyName' ) . type ( 'Doe' ) ;
408- cy . get ( '#author_3_givenName' ) . type ( 'Alex' ) ;
432+ cy . get ( '#author_2_givenName' ) . type ( 'Two' ) ;
433+ cy . get ( '#author_2_familyName' ) . type ( 'Too' ) ;
434+ cy . get ( '#author_3_givenName' ) . type ( 'Three' ) ;
435+ cy . get ( '#author_4_givenName' ) . type ( 'Four' ) ;
409436
410437 cy . get ( '#author_1_moveToLeft' ) . click ( )
411438
412- cy . get ( '#author_1_givenName' ) . should ( 'have.value' , 'Alex ' ) ;
413- cy . get ( '#author_1_familyName' ) . should ( 'have.value' , '' ) ;
439+ cy . get ( '#author_1_givenName' ) . should ( 'have.value' , 'Two ' ) ;
440+ cy . get ( '#author_1_familyName' ) . should ( 'have.value' , 'Too ' ) ;
414441 cy . get ( '#author_1_affiliation' ) . should ( 'have.value' , '' ) ;
415442
416- cy . get ( '#author_2_givenName' ) . should ( 'have.value' , 'John ' ) ;
417- cy . get ( '#author_2_familyName' ) . should ( 'have.value' , 'Doe ' ) ;
443+ cy . get ( '#author_2_givenName' ) . should ( 'have.value' , 'Three ' ) ;
444+ cy . get ( '#author_2_familyName' ) . should ( 'have.value' , '' ) ;
418445 cy . get ( '#author_2_affiliation' ) . should ( 'have.value' , '' ) ;
419446
420- cy . get ( '#author_3_givenName' ) . should ( 'have.value' , 'Jane ' ) ;
447+ cy . get ( '#author_3_givenName' ) . should ( 'have.value' , 'Four ' ) ;
421448 cy . get ( '#author_3_familyName' ) . should ( 'have.value' , '' ) ;
422- cy . get ( '#author_3_affiliation' ) . should ( 'have.value' , 'Example Org' ) ;
449+ cy . get ( '#author_3_affiliation' ) . should ( 'have.value' , '' ) ;
450+
451+ cy . get ( '#author_4_givenName' ) . should ( 'have.value' , 'One' ) ;
452+ cy . get ( '#author_4_familyName' ) . should ( 'have.value' , '' ) ;
453+ cy . get ( '#author_4_affiliation' ) . should ( 'have.value' , 'Example Org' ) ;
423454 } ) ;
424455
425456 it ( 'wraps around to the left' , function ( ) {
@@ -428,25 +459,31 @@ describe('Author order change', function() {
428459 cy . get ( '#author_add' ) . click ( ) ;
429460 cy . get ( '#author_add' ) . click ( ) ;
430461 cy . get ( '#author_add' ) . click ( ) ;
431- cy . get ( '#author_1_givenName' ) . type ( 'Jane' ) ;
462+ cy . get ( '#author_add' ) . click ( ) ;
463+ cy . get ( '#author_1_givenName' ) . type ( 'One' ) ;
432464 cy . get ( '#author_1_affiliation' ) . type ( 'Example Org' ) ;
433- cy . get ( '#author_2_givenName' ) . type ( 'John' ) ;
434- cy . get ( '#author_2_familyName' ) . type ( 'Doe' ) ;
435- cy . get ( '#author_3_givenName' ) . type ( 'Alex' ) ;
465+ cy . get ( '#author_2_givenName' ) . type ( 'Two' ) ;
466+ cy . get ( '#author_2_familyName' ) . type ( 'Too' ) ;
467+ cy . get ( '#author_3_givenName' ) . type ( 'Three' ) ;
468+ cy . get ( '#author_4_givenName' ) . type ( 'Four' ) ;
436469
437- cy . get ( '#author_3_moveToRight ' ) . click ( )
470+ cy . get ( '#author_4_moveToRight ' ) . click ( )
438471
439- cy . get ( '#author_1_givenName' ) . should ( 'have.value' , 'Alex ' ) ;
472+ cy . get ( '#author_1_givenName' ) . should ( 'have.value' , 'Four ' ) ;
440473 cy . get ( '#author_1_familyName' ) . should ( 'have.value' , '' ) ;
441474 cy . get ( '#author_1_affiliation' ) . should ( 'have.value' , '' ) ;
442475
443- cy . get ( '#author_2_givenName' ) . should ( 'have.value' , 'John ' ) ;
444- cy . get ( '#author_2_familyName' ) . should ( 'have.value' , 'Doe ' ) ;
445- cy . get ( '#author_2_affiliation' ) . should ( 'have.value' , '' ) ;
476+ cy . get ( '#author_2_givenName' ) . should ( 'have.value' , 'One ' ) ;
477+ cy . get ( '#author_2_familyName' ) . should ( 'have.value' , '' ) ;
478+ cy . get ( '#author_2_affiliation' ) . should ( 'have.value' , 'Example Org ' ) ;
446479
447- cy . get ( '#author_3_givenName' ) . should ( 'have.value' , 'Jane' ) ;
448- cy . get ( '#author_3_familyName' ) . should ( 'have.value' , '' ) ;
449- cy . get ( '#author_3_affiliation' ) . should ( 'have.value' , 'Example Org' ) ;
480+ cy . get ( '#author_3_givenName' ) . should ( 'have.value' , 'Two' ) ;
481+ cy . get ( '#author_3_familyName' ) . should ( 'have.value' , 'Too' ) ;
482+ cy . get ( '#author_3_affiliation' ) . should ( 'have.value' , '' ) ;
483+
484+ cy . get ( '#author_4_givenName' ) . should ( 'have.value' , 'Three' ) ;
485+ cy . get ( '#author_4_familyName' ) . should ( 'have.value' , '' ) ;
486+ cy . get ( '#author_4_affiliation' ) . should ( 'have.value' , '' ) ;
450487 } ) ;
451488} ) ;
452489
@@ -889,6 +926,78 @@ describe('Multiple authors', function () {
889926 cy . get ( '#author_1_endDate_0' ) . should ( 'have.value' , '2024-04-03' ) ;
890927 cy . get ( '#author_2_givenName' ) . should ( 'have.value' , 'Joe' ) ;
891928 } ) ;
929+
930+ it ( 'can remove the first one and reindexes remaining ones' , function ( ) {
931+ cy . get ( '#name' ) . type ( 'My Test Software' ) ;
932+
933+ cy . get ( '#author_add' ) . click ( ) ;
934+ cy . get ( '#author_add' ) . click ( ) ;
935+ cy . get ( '#author_nb' ) . should ( 'have.value' , '2' ) ;
936+
937+ cy . get ( '#author_1_givenName' ) . type ( 'Alice' ) ;
938+ cy . get ( '#author_2_givenName' ) . type ( 'Bob' ) ;
939+
940+ cy . get ( '#author_1_remove' ) . click ( ) ;
941+
942+ cy . get ( '#author_nb' ) . should ( 'have.value' , '1' ) ;
943+ cy . get ( '#author_1_givenName' ) . should ( 'have.value' , 'Bob' ) ;
944+
945+ cy . get ( '#generateCodemetaV2' ) . click ( ) ;
946+ cy . get ( '#codemetaText' ) . then ( ( elem ) => JSON . parse ( elem . text ( ) ) )
947+ . should ( 'deep.equal' , {
948+ "@context" : "https://doi.org/10.5063/schema/codemeta-2.0" ,
949+ "type" : "SoftwareSourceCode" ,
950+ "name" : "My Test Software" ,
951+ "author" : [
952+ {
953+ "id" : "_:author_1" ,
954+ "type" : "Person" ,
955+ "givenName" : "Bob"
956+ }
957+ ] ,
958+ } ) ;
959+ } ) ;
960+
961+ it ( 'can remove a middle one and reindexes remaining ones' , function ( ) {
962+ cy . get ( '#name' ) . type ( 'My Test Software' ) ;
963+
964+ cy . get ( '#author_add' ) . click ( ) ;
965+ cy . get ( '#author_add' ) . click ( ) ;
966+ cy . get ( '#author_add' ) . click ( ) ;
967+ cy . get ( '#author_nb' ) . should ( 'have.value' , '3' ) ;
968+
969+ cy . get ( '#author_1_givenName' ) . type ( 'Alice' ) ;
970+ cy . get ( '#author_2_givenName' ) . type ( 'Bob' ) ;
971+ cy . get ( '#author_3_givenName' ) . type ( 'Carol' ) ;
972+
973+ cy . get ( '#author_2_remove' ) . click ( ) ;
974+
975+ cy . get ( '#author_nb' ) . should ( 'have.value' , '2' ) ;
976+ cy . get ( '#author_1_givenName' ) . should ( 'have.value' , 'Alice' ) ;
977+ cy . get ( '#author_2_givenName' ) . should ( 'have.value' , 'Carol' ) ;
978+
979+ cy . get ( '#generateCodemetaV2' ) . click ( ) ;
980+ cy . get ( '#codemetaText' ) . then ( ( elem ) => JSON . parse ( elem . text ( ) ) )
981+ . should ( 'deep.equal' , {
982+ "@context" : "https://doi.org/10.5063/schema/codemeta-2.0" ,
983+ "type" : "SoftwareSourceCode" ,
984+ "name" : "My Test Software" ,
985+ "author" : [
986+ {
987+ "id" : "_:author_1" ,
988+ "type" : "Person" ,
989+ "givenName" : "Alice"
990+ } ,
991+ {
992+ "id" : "_:author_2" ,
993+ "type" : "Person" ,
994+ "givenName" : "Carol"
995+ }
996+ ] ,
997+ } ) ;
998+ } ) ;
999+
1000+
8921001} ) ;
8931002
8941003describe ( 'Contributors' , function ( ) {
0 commit comments