@@ -26,25 +26,42 @@ describe('open-and-download-diagram', function () {
2626 expect ( decodedEdits ) . to . deep . equal ( FlightDiagram . edits ) ;
2727 } ) ;
2828
29- it ( 'should return the correct diagram name' , function ( ) {
30- const existingNames = [ 'Flights' , 'Berlin Public Transport' ] ;
31-
32- expect (
33- getDiagramName ( existingNames , 'Airbnb' ) ,
34- 'should return the expected name when it does not exist'
35- ) . to . equal ( 'Airbnb' ) ;
36-
37- expect (
38- getDiagramName ( existingNames , 'Flights' ) ,
39- 'should return the next expected name when it exists'
40- ) . to . equal ( 'Flights (1)' ) ;
41-
42- existingNames . push ( 'Flights (1)' ) ;
29+ context ( 'getDiagramName' , function ( ) {
30+ const usecases = [
31+ {
32+ existingNames : [ ] ,
33+ name : 'Airbnb' ,
34+ expectedName : 'Airbnb' ,
35+ message : 'should return the expected name when it does not exist' ,
36+ } ,
37+ {
38+ existingNames : [ 'Airbnb' ] ,
39+ name : 'Airbnb' ,
40+ expectedName : 'Airbnb (1)' ,
41+ message : 'should return the next expected name when it exists' ,
42+ } ,
43+ {
44+ existingNames : [ 'Airbnb (1)' ] ,
45+ name : 'Airbnb (1)' ,
46+ expectedName : 'Airbnb (2)' ,
47+ message :
48+ 'should return the next expected name when name with (number) exists' ,
49+ } ,
50+ {
51+ existingNames : [ 'Airbnb' , 'Airbnb (1)' , 'Airbnb (2)' ] ,
52+ name : 'Airbnb (1)' ,
53+ expectedName : 'Airbnb (3)' ,
54+ message :
55+ 'should return the next expected name when multiple versions exist' ,
56+ } ,
57+ ] ;
4358
44- expect (
45- getDiagramName ( existingNames , 'Flights' ) ,
46- 'should return the next expected name when multiple versions exist'
47- ) . to . equal ( 'Flights (2)' ) ;
59+ for ( const { existingNames, name, expectedName, message } of usecases ) {
60+ it ( message , function ( ) {
61+ const result = getDiagramName ( existingNames , name ) ;
62+ expect ( result ) . to . equal ( expectedName ) ;
63+ } ) ;
64+ }
4865 } ) ;
4966
5067 context ( 'getDiagramContentsFromFile' , function ( ) {
0 commit comments