| 1 | import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts'; |
| 2 | |
| 3 | const testOptions = [ |
| 4 | { description: '', options: { logLevel: 1 } }, |
| 5 | { description: 'ELK: ', options: { logLevel: 1, layout: 'elk' } }, |
| 6 | { description: 'HD: ', options: { logLevel: 1, look: 'handDrawn' } }, |
| 7 | ]; |
| 8 | |
| 9 | describe('Requirement Diagram Unified', () => { |
| 10 | testOptions.forEach(({ description, options }) => { |
| 11 | it(`${description}should render a simple Requirement diagram`, () => { |
| 12 | imgSnapshotTest( |
| 13 | ` |
| 14 | requirementDiagram |
| 15 | requirement test_req { |
| 16 | id: 1 |
| 17 | text: the test text. |
| 18 | risk: high |
| 19 | verifymethod: test |
| 20 | } |
| 21 | |
| 22 | element test_entity { |
| 23 | type: simulation |
| 24 | } |
| 25 | |
| 26 | test_entity - satisfies -> test_req |
| 27 | `, |
| 28 | options |
| 29 | ); |
| 30 | }); |
| 31 | |
| 32 | it(`${description}should render a simple Requirement diagram without htmlLabels`, () => { |
| 33 | imgSnapshotTest( |
| 34 | ` |
| 35 | requirementDiagram |
| 36 | requirement test_req { |
| 37 | id: 1 |
| 38 | text: the test text. |
| 39 | risk: high |
| 40 | verifymethod: test |
| 41 | } |
| 42 | |
| 43 | element test_entity { |
| 44 | type: simulation |
| 45 | } |
| 46 | |
| 47 | test_entity - satisfies -> test_req |
| 48 | `, |
| 49 | { ...options, htmlLabels: false } |
| 50 | ); |
| 51 | }); |
| 52 | |
| 53 | it(`${description}should render a not-so-simple Requirement diagram`, () => { |
| 54 | imgSnapshotTest( |
| 55 | ` |
| 56 | requirementDiagram |
| 57 | |
| 58 | requirement test_req { |
| 59 | id: 1 |
| 60 | text: the test text. |
| 61 | risk: high |
| 62 | verifymethod: test |
| 63 | } |
| 64 | |
| 65 | functionalRequirement test_req2 { |
| 66 | id: 1.1 |
| 67 | text: the second test text. |
| 68 | risk: low |
| 69 | verifymethod: inspection |
| 70 | } |
| 71 | |
| 72 | performanceRequirement test_req3 { |
| 73 | id: 1.2 |
| 74 | text: the third test text. |
| 75 | risk: medium |
| 76 | verifymethod: demonstration |
| 77 | } |
| 78 | |
| 79 | interfaceRequirement test_req4 { |
| 80 | id: 1.2.1 |
| 81 | text: the fourth test text. |
| 82 | risk: medium |
| 83 | verifymethod: analysis |
| 84 | } |
| 85 | |
| 86 | physicalRequirement test_req5 { |
| 87 | id: 1.2.2 |
| 88 | text: the fifth test text. |
| 89 | risk: medium |
| 90 | verifymethod: analysis |
| 91 | } |
| 92 | |
| 93 | designConstraint test_req6 { |
| 94 | id: 1.2.3 |
| 95 | text: the sixth test text. |
| 96 | risk: medium |
| 97 | verifymethod: analysis |
| 98 | } |
| 99 | |
| 100 | element test_entity { |
| 101 | type: simulation |
| 102 | } |
| 103 | |
| 104 | element test_entity2 { |
| 105 | type: word doc |
| 106 | docRef: reqs/test_entity |
| 107 | } |
| 108 | |
| 109 | element test_entity3 { |
| 110 | type: "test suite" |
| 111 | docRef: github.com/all_the_tests |
| 112 | } |
| 113 | |
| 114 | |
| 115 | test_entity - satisfies -> test_req2 |
| 116 | test_req - traces -> test_req2 |
| 117 | test_req - contains -> test_req3 |
| 118 | test_req3 - contains -> test_req4 |
| 119 | test_req4 - derives -> test_req5 |
| 120 | test_req5 - refines -> test_req6 |
| 121 | test_entity3 - verifies -> test_req5 |
| 122 | test_req <- copies - test_entity2 |
| 123 | `, |
| 124 | options |
| 125 | ); |
| 126 | }); |
| 127 | |
| 128 | it(`${description}should render a not-so-simple Requirement diagram without htmlLabels`, () => { |
| 129 | imgSnapshotTest( |
| 130 | ` |
| 131 | requirementDiagram |
| 132 | |
| 133 | requirement test_req { |
| 134 | id: 1 |
| 135 | text: the test text. |
| 136 | risk: high |
| 137 | verifymethod: test |
| 138 | } |
| 139 | |
| 140 | functionalRequirement test_req2 { |
| 141 | id: 1.1 |
| 142 | text: the second test text. |
| 143 | risk: low |
| 144 | verifymethod: inspection |
| 145 | } |
| 146 | |
| 147 | performanceRequirement test_req3 { |
| 148 | id: 1.2 |
| 149 | text: the third test text. |
| 150 | risk: medium |
| 151 | verifymethod: demonstration |
| 152 | } |
| 153 | |
| 154 | interfaceRequirement test_req4 { |
| 155 | id: 1.2.1 |
| 156 | text: the fourth test text. |
| 157 | risk: medium |
| 158 | verifymethod: analysis |
| 159 | } |
| 160 | |
| 161 | physicalRequirement test_req5 { |
| 162 | id: 1.2.2 |
| 163 | text: the fifth test text. |
| 164 | risk: medium |
| 165 | verifymethod: analysis |
| 166 | } |
| 167 | |
| 168 | designConstraint test_req6 { |
| 169 | id: 1.2.3 |
| 170 | text: the sixth test text. |
| 171 | risk: medium |
| 172 | verifymethod: analysis |
| 173 | } |
| 174 | |
| 175 | element test_entity { |
| 176 | type: simulation |
| 177 | } |
| 178 | |
| 179 | element test_entity2 { |
| 180 | type: word doc |
| 181 | docRef: reqs/test_entity |
| 182 | } |
| 183 | |
| 184 | element test_entity3 { |
| 185 | type: "test suite" |
| 186 | docRef: github.com/all_the_tests |
| 187 | } |
| 188 | |
| 189 | |
| 190 | test_entity - satisfies -> test_req2 |
| 191 | test_req - traces -> test_req2 |
| 192 | test_req - contains -> test_req3 |
| 193 | test_req3 - contains -> test_req4 |
| 194 | test_req4 - derives -> test_req5 |
| 195 | test_req5 - refines -> test_req6 |
| 196 | test_entity3 - verifies -> test_req5 |
| 197 | test_req <- copies - test_entity2 |
| 198 | `, |
| 199 | { ...options, htmlLabels: false } |
| 200 | ); |
| 201 | }); |
| 202 | |
| 203 | it(`${description}should render multiple Requirement diagrams`, () => { |
| 204 | imgSnapshotTest( |
| 205 | [ |
| 206 | ` |
| 207 | requirementDiagram |
| 208 | |
| 209 | requirement test_req { |
| 210 | id: 1 |
| 211 | text: the test text. |
| 212 | risk: high |
| 213 | verifymethod: test |
| 214 | } |
| 215 | |
| 216 | element test_entity { |
| 217 | type: simulation |
| 218 | } |
| 219 | |
| 220 | test_entity - satisfies -> test_req |
| 221 | `, |
| 222 | ` |
| 223 | requirementDiagram |
| 224 | |
| 225 | requirement test_req { |
| 226 | id: 1 |
| 227 | text: the test text. |
| 228 | risk: high |
| 229 | verifymethod: test |
| 230 | } |
| 231 | |
| 232 | element test_entity { |
| 233 | type: simulation |
| 234 | } |
| 235 | |
| 236 | test_entity - satisfies -> test_req |
| 237 | `, |
| 238 | ], |
| 239 | options |
| 240 | ); |
| 241 | }); |
| 242 | |
| 243 | it(`${description}should render a Requirement diagram with empty information`, () => { |
| 244 | imgSnapshotTest( |
| 245 | ` |
| 246 | requirementDiagram |
| 247 | requirement test_req { |
| 248 | } |
| 249 | element test_entity { |
| 250 | } |
| 251 | `, |
| 252 | options |
| 253 | ); |
| 254 | }); |
| 255 | |
| 256 | it(`${description}should render requirements and elements with and without information`, () => { |
| 257 | renderGraph( |
| 258 | ` |
| 259 | requirementDiagram |
| 260 | requirement test_req { |
| 261 | id: 1 |
| 262 | text: the test text. |
| 263 | risk: high |
| 264 | verifymethod: test |
| 265 | } |
| 266 | element test_entity { |
| 267 | } |
| 268 | `, |
| 269 | options |
| 270 | ); |
| 271 | }); |
| 272 | |
| 273 | it(`${description}should render requirements and elements with long and short text`, () => { |
| 274 | renderGraph( |
| 275 | ` |
| 276 | requirementDiagram |
| 277 | requirement test_req { |
| 278 | id: 1 |
| 279 | text: the test text that is long and takes up a lot of space. |
| 280 | risk: high |
| 281 | verifymethod: test |
| 282 | } |
| 283 | element test_entity_name_that_is_extra_long { |
| 284 | } |
| 285 | `, |
| 286 | options |
| 287 | ); |
| 288 | }); |
| 289 | |
| 290 | it(`${description}should render requirements and elements with long and short text without htmlLabels`, () => { |
| 291 | renderGraph( |
| 292 | ` |
| 293 | requirementDiagram |
| 294 | requirement test_req { |
| 295 | id: 1 |
| 296 | text: the test text that is long and takes up a lot of space. |
| 297 | risk: high |
| 298 | verifymethod: test |
| 299 | } |
| 300 | element test_entity_name_that_is_extra_long { |
| 301 | } |
| 302 | `, |
| 303 | { ...options, htmlLabels: false } |
| 304 | ); |
| 305 | }); |
| 306 | |
| 307 | it(`${description}should render requirements and elements with quoted text for spaces`, () => { |
| 308 | renderGraph( |
| 309 | ` |
| 310 | requirementDiagram |
| 311 | requirement "test req name with spaces" { |
| 312 | id: 1 |
| 313 | text: the test text that is long and takes up a lot of space. |
| 314 | risk: high |
| 315 | verifymethod: test |
| 316 | } |
| 317 | element "test entity name that is extra long with spaces" { |
| 318 | } |
| 319 | `, |
| 320 | options |
| 321 | ); |
| 322 | }); |
| 323 | |
| 324 | it(`${description}should render requirements and elements with markdown text`, () => { |
| 325 | renderGraph( |
| 326 | ` |
| 327 | requirementDiagram |
| 328 | requirement "__my bolded name__" { |
| 329 | id: 1 |
| 330 | text: "**Bolded text** _italicized text_" |
| 331 | risk: high |
| 332 | verifymethod: test |
| 333 | } |
| 334 | element "*my italicized name*" { |
| 335 | type: "**Bolded type** _italicized type_" |
| 336 | docref: "*Italicized* __Bolded__" |
| 337 | } |
| 338 | `, |
| 339 | options |
| 340 | ); |
| 341 | }); |
| 342 | |
| 343 | it(`${description}should render requirements and elements with markdown text without htmlLabels`, () => { |
| 344 | renderGraph( |
| 345 | ` |
| 346 | requirementDiagram |
| 347 | requirement "__my bolded name__" { |
| 348 | id: 1 |
| 349 | text: "**Bolded text** _italicized text_" |
| 350 | risk: high |
| 351 | verifymethod: test |
| 352 | } |
| 353 | element "*my italicized name*" { |
| 354 | type: "**Bolded type** _italicized type_" |
| 355 | docref: "*Italicized* __Bolded__" |
| 356 | } |
| 357 | `, |
| 358 | { ...options, htmlLabels: false } |
| 359 | ); |
| 360 | }); |
| 361 | |
| 362 | it(`${description}should render a simple Requirement diagram with a title`, () => { |
| 363 | imgSnapshotTest( |
| 364 | `--- |
| 365 | title: simple Requirement diagram |
| 366 | --- |
| 367 | requirementDiagram |
| 368 | |
| 369 | requirement test_req { |
| 370 | id: 1 |
| 371 | text: the test text. |
| 372 | risk: high |
| 373 | verifymethod: test |
| 374 | } |
| 375 | |
| 376 | element test_entity { |
| 377 | type: simulation |
| 378 | } |
| 379 | |
| 380 | test_entity - satisfies -> test_req |
| 381 | `, |
| 382 | options |
| 383 | ); |
| 384 | }); |
| 385 | |
| 386 | it(`${description}should render a Requirement diagram with TB direction`, () => { |
| 387 | imgSnapshotTest( |
| 388 | ` |
| 389 | requirementDiagram |
| 390 | direction TB |
| 391 | |
| 392 | requirement test_req { |
| 393 | id: 1 |
| 394 | text: the test text. |
| 395 | risk: high |
| 396 | verifymethod: test |
| 397 | } |
| 398 | |
| 399 | element test_entity { |
| 400 | type: simulation |
| 401 | } |
| 402 | |
| 403 | test_entity - satisfies -> test_req |
| 404 | `, |
| 405 | options |
| 406 | ); |
| 407 | }); |
| 408 | |
| 409 | it(`${description}should render a Requirement diagram with BT direction`, () => { |
| 410 | imgSnapshotTest( |
| 411 | ` |
| 412 | requirementDiagram |
| 413 | direction BT |
| 414 | |
| 415 | requirement test_req { |
| 416 | id: 1 |
| 417 | text: the test text. |
| 418 | risk: high |
| 419 | verifymethod: test |
| 420 | } |
| 421 | |
| 422 | element test_entity { |
| 423 | type: simulation |
| 424 | } |
| 425 | |
| 426 | test_entity - satisfies -> test_req |
| 427 | `, |
| 428 | options |
| 429 | ); |
| 430 | }); |
| 431 | |
| 432 | it(`${description}should render a Requirement diagram with LR direction`, () => { |
| 433 | imgSnapshotTest( |
| 434 | ` |
| 435 | requirementDiagram |
| 436 | direction LR |
| 437 | |
| 438 | requirement test_req { |
| 439 | id: 1 |
| 440 | text: the test text. |
| 441 | risk: high |
| 442 | verifymethod: test |
| 443 | } |
| 444 | |
| 445 | element test_entity { |
| 446 | type: simulation |
| 447 | } |
| 448 | |
| 449 | test_entity - satisfies -> test_req |
| 450 | `, |
| 451 | options |
| 452 | ); |
| 453 | }); |
| 454 | |
| 455 | it(`${description}should render a Requirement diagram with RL direction`, () => { |
| 456 | imgSnapshotTest( |
| 457 | ` |
| 458 | requirementDiagram |
| 459 | direction RL |
| 460 | |
| 461 | requirement test_req { |
| 462 | id: 1 |
| 463 | text: the test text. |
| 464 | risk: high |
| 465 | verifymethod: test |
| 466 | } |
| 467 | |
| 468 | element test_entity { |
| 469 | type: simulation |
| 470 | } |
| 471 | |
| 472 | test_entity - satisfies -> test_req |
| 473 | `, |
| 474 | options |
| 475 | ); |
| 476 | }); |
| 477 | |
| 478 | it(`${description}should render requirements and elements with styles applied from style statement`, () => { |
| 479 | imgSnapshotTest( |
| 480 | ` |
| 481 | requirementDiagram |
| 482 | |
| 483 | requirement test_req { |
| 484 | id: 1 |
| 485 | text: the test text. |
| 486 | risk: high |
| 487 | verifymethod: test |
| 488 | } |
| 489 | |
| 490 | element test_entity { |
| 491 | type: simulation |
| 492 | } |
| 493 | |
| 494 | test_entity - satisfies -> test_req |
| 495 | |
| 496 | style test_req,test_entity fill:#f9f,stroke:blue, color:grey, font-weight:bold |
| 497 | `, |
| 498 | options |
| 499 | ); |
| 500 | }); |
| 501 | |
| 502 | it(`${description}should render requirements and elements with styles applied from style statement without htmlLabels`, () => { |
| 503 | imgSnapshotTest( |
| 504 | ` |
| 505 | requirementDiagram |
| 506 | |
| 507 | requirement test_req { |
| 508 | id: 1 |
| 509 | text: the test text. |
| 510 | risk: high |
| 511 | verifymethod: test |
| 512 | } |
| 513 | |
| 514 | element test_entity { |
| 515 | type: simulation |
| 516 | } |
| 517 | |
| 518 | test_entity - satisfies -> test_req |
| 519 | |
| 520 | style test_req,test_entity fill:#f9f,stroke:blue, color:grey, font-weight:bold |
| 521 | `, |
| 522 | { ...options, htmlLabels: false } |
| 523 | ); |
| 524 | }); |
| 525 | |
| 526 | it(`${description}should render requirements and elements with styles applied from class statement`, () => { |
| 527 | imgSnapshotTest( |
| 528 | ` |
| 529 | requirementDiagram |
| 530 | |
| 531 | requirement test_req { |
| 532 | id: 1 |
| 533 | text: the test text. |
| 534 | risk: high |
| 535 | verifymethod: test |
| 536 | } |
| 537 | |
| 538 | element test_entity { |
| 539 | type: simulation |
| 540 | } |
| 541 | |
| 542 | test_entity - satisfies -> test_req |
| 543 | classDef bold font-weight: bold |
| 544 | classDef blue stroke:lightblue, color: #0000FF |
| 545 | class test_entity bold |
| 546 | class test_req blue, bold |
| 547 | `, |
| 548 | options |
| 549 | ); |
| 550 | }); |
| 551 | |
| 552 | it(`${description}should render requirements and elements with styles applied from class statement without htmlLabels`, () => { |
| 553 | imgSnapshotTest( |
| 554 | ` |
| 555 | requirementDiagram |
| 556 | |
| 557 | requirement test_req { |
| 558 | id: 1 |
| 559 | text: the test text. |
| 560 | risk: high |
| 561 | verifymethod: test |
| 562 | } |
| 563 | |
| 564 | element test_entity { |
| 565 | type: simulation |
| 566 | } |
| 567 | |
| 568 | test_entity - satisfies -> test_req |
| 569 | classDef bold font-weight: bold |
| 570 | classDef blue stroke:lightblue, color: #0000FF |
| 571 | class test_entity bold |
| 572 | class test_req blue, bold |
| 573 | `, |
| 574 | { ...options, htmlLabels: false } |
| 575 | ); |
| 576 | }); |
| 577 | |
| 578 | it(`${description}should render requirements and elements with styles applied from classes with shorthand syntax`, () => { |
| 579 | imgSnapshotTest( |
| 580 | ` |
| 581 | requirementDiagram |
| 582 | |
| 583 | requirement test_req:::blue { |
| 584 | id: 1 |
| 585 | text: the test text. |
| 586 | risk: high |
| 587 | verifymethod: test |
| 588 | } |
| 589 | |
| 590 | element test_entity { |
| 591 | type: simulation |
| 592 | } |
| 593 | |
| 594 | test_entity - satisfies -> test_req |
| 595 | classDef bold font-weight: bold |
| 596 | classDef blue stroke:lightblue, color: #0000FF |
| 597 | test_entity:::bold |
| 598 | `, |
| 599 | options |
| 600 | ); |
| 601 | }); |
| 602 | |
| 603 | it(`${description}should render requirements and elements with styles applied from classes with shorthand syntax without htmlLabels`, () => { |
| 604 | imgSnapshotTest( |
| 605 | ` |
| 606 | requirementDiagram |
| 607 | |
| 608 | requirement test_req:::blue { |
| 609 | id: 1 |
| 610 | text: the test text. |
| 611 | risk: high |
| 612 | verifymethod: test |
| 613 | } |
| 614 | |
| 615 | element test_entity { |
| 616 | type: simulation |
| 617 | } |
| 618 | |
| 619 | test_entity - satisfies -> test_req |
| 620 | classDef bold font-weight: bold |
| 621 | classDef blue stroke:lightblue, color: #0000FF |
| 622 | test_entity:::bold |
| 623 | `, |
| 624 | { ...options, htmlLabels: false } |
| 625 | ); |
| 626 | }); |
| 627 | |
| 628 | it(`${description}should render requirements and elements with styles applied from the default class and other styles`, () => { |
| 629 | imgSnapshotTest( |
| 630 | ` |
| 631 | requirementDiagram |
| 632 | |
| 633 | requirement test_req:::blue { |
| 634 | id: 1 |
| 635 | text: the test text. |
| 636 | risk: high |
| 637 | verifymethod: test |
| 638 | } |
| 639 | |
| 640 | element test_entity { |
| 641 | type: simulation |
| 642 | } |
| 643 | |
| 644 | test_entity - satisfies -> test_req |
| 645 | classDef blue stroke:lightblue, color:blue |
| 646 | classDef default fill:pink |
| 647 | style test_entity color:green |
| 648 | `, |
| 649 | options |
| 650 | ); |
| 651 | }); |
| 652 | |
| 653 | it(`${description}should render requirements and elements with styles applied from the default class and other styles without htmlLabels`, () => { |
| 654 | imgSnapshotTest( |
| 655 | ` |
| 656 | requirementDiagram |
| 657 | |
| 658 | requirement test_req:::blue { |
| 659 | id: 1 |
| 660 | text: the test text. |
| 661 | risk: high |
| 662 | verifymethod: test |
| 663 | } |
| 664 | |
| 665 | element test_entity { |
| 666 | type: simulation |
| 667 | } |
| 668 | |
| 669 | test_entity - satisfies -> test_req |
| 670 | classDef blue stroke:lightblue, color:blue |
| 671 | classDef default fill:pink |
| 672 | style test_entity color:green |
| 673 | `, |
| 674 | { ...options, htmlLabels: false } |
| 675 | ); |
| 676 | }); |
| 677 | |
| 678 | it(`${description}should render a Requirement diagram with a theme`, () => { |
| 679 | imgSnapshotTest( |
| 680 | ` |
| 681 | --- |
| 682 | theme: forest |
| 683 | --- |
| 684 | requirementDiagram |
| 685 | |
| 686 | requirement test_req:::blue { |
| 687 | id: 1 |
| 688 | text: the test text. |
| 689 | risk: high |
| 690 | verifymethod: test |
| 691 | } |
| 692 | |
| 693 | element test_entity { |
| 694 | type: simulation |
| 695 | } |
| 696 | |
| 697 | test_entity - satisfies -> test_req |
| 698 | `, |
| 699 | options |
| 700 | ); |
| 701 | }); |
| 702 | |
| 703 | it(`${description}should render edge labels correctly when flowchart htmlLabels is false`, () => { |
| 704 | imgSnapshotTest( |
| 705 | ` |
| 706 | requirementDiagram |
| 707 | requirement test_req { |
| 708 | id: 1 |
| 709 | text: the test text. |
| 710 | risk: high |
| 711 | verifymethod: test |
| 712 | } |
| 713 | |
| 714 | functionalRequirement test_req2 { |
| 715 | id: 1.1 |
| 716 | text: the second test text. |
| 717 | risk: low |
| 718 | verifymethod: inspection |
| 719 | } |
| 720 | |
| 721 | element test_entity { |
| 722 | type: simulation |
| 723 | } |
| 724 | |
| 725 | element test_entity2 { |
| 726 | type: word doc |
| 727 | docRef: reqs/test_entity |
| 728 | } |
| 729 | |
| 730 | test_entity - satisfies -> test_req2 |
| 731 | test_req - traces -> test_req2 |
| 732 | test_req - contains -> test_req2 |
| 733 | test_entity2 - verifies -> test_req |
| 734 | test_req <- copies - test_entity2 |
| 735 | `, |
| 736 | { ...options, flowchart: { htmlLabels: false } } |
| 737 | ); |
| 738 | }); |
| 739 | }); |
| 740 | }); |
| 741 | |