Repository: mermaid-js/mermaid
File: cypress/integration/rendering/iconShape.spec.ts (TypeScript)

Code before:
/* MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE */
import { imgSnapshotTest } from '../../helpers/util';

const looks = ['classic', 'handDrawn'] as const;
const directions = [
  'TB',
  //'BT',
  'LR',
  //  'RL'
] as const;
const forms = [undefined, 'square', 'circle', 'rounded'] as const;
const labelPos = [undefined, 't', 'b'] as const;

looks.forEach((look) => {
  directions.forEach((direction) => {
    forms.forEach((form) => {
      labelPos.forEach((pos) => {
        describe(`Test iconShape in ${form ? `${form} form,` : ''} ${look} look and dir ${direction} with label position ${pos ? pos : 'not defined'}`, () => {
          it(`without label`, () => {
            let flowchartCode = `flowchart ${direction}\n`;
            flowchartCode += `  nA --> nAA@{ icon: 'fa:bell'`;
            if (form) {
              flowchartCode += `, form: '${form}'`;
            }
            flowchartCode += ` }\n`;
            imgSnapshotTest(flowchartCode, { look });

Review comment (refactor):
:+1: Could we move this to right before the SVG is actually defined in https://github.com/mermaid-js/mermaid/blob/a98290a6e2e4fb4e382ae0f3a495c80a1d47639c/cypress/platform/viewer.js#L70 ?



Code after:
import { imgSnapshotTest } from '../../helpers/util';

const looks = ['classic', 'handDrawn'] as const;
const directions = [
  'TB',
  //'BT',
  'LR',
  //  'RL'
] as const;
const forms = [undefined, 'square', 'circle', 'rounded'] as const;
const labelPos = [undefined, 't', 'b'] as const;

looks.forEach((look) => {
  directions.forEach((direction) => {
    forms.forEach((form) => {
      labelPos.forEach((pos) => {
        describe(`Test iconShape in ${form ? `${form} form,` : ''} ${look} look and dir ${direction} with label position ${pos ? pos : 'not defined'}`, () => {
          it(`without label`, () => {
            let flowchartCode = `flowchart ${direction}\n`;
            flowchartCode += `  nA --> nAA@{ icon: 'fa:bell'`;
            if (form) {
              flowchartCode += `, form: '${form}'`;
            }
            flowchartCode += ` }\n`;
            imgSnapshotTest(flowchartCode, { look });
          });

          it(`with label`, () => {
            let flowchartCode = `flowchart ${direction}\n`;
            flowchartCode += `  nA --> nAA@{ icon: 'fa:bell', label: 'This is a label for icon shape'`;
            if (form) {
              flowchartCode += `, form: '${form}'`;
            }
            if (pos) {
              flowchartCode += `, pos: '${pos}'`;
            }
            flowchartCode += ` }\n`;
            imgSnapshotTest(flowchartCode, { look });
          });

          it(`with very long label`, () => {
            let flowchartCode = `flowchart ${direction}\n`;
            flowchartCode += `  nA --> nAA@{ icon: 'fa:bell', label: 'This is a very very very very very long long long label for icon shape'`;
            if (form) {
              flowchartCode += `, form: '${form}'`;
            }