| 1 | import { imgSnapshotTest, urlSnapshotTest } from '../../helpers/util.ts'; |
| 2 | |
| 3 | describe('Configuration and directives - nodes should be light blue', () => { |
| 4 | it('No config - use default', () => { |
| 5 | imgSnapshotTest( |
| 6 | ` |
| 7 | graph TD |
| 8 | A(Default) --> B[/Another/] |
| 9 | A --> C[End] |
| 10 | subgraph section |
| 11 | B |
| 12 | C |
| 13 | end |
| 14 | `, |
| 15 | {} |
| 16 | ); |
| 17 | }); |
| 18 | it('Settings from initialize - nodes should be green', () => { |
| 19 | imgSnapshotTest( |
| 20 | ` |
| 21 | graph TD |
| 22 | A(Forest) --> B[/Another/] |
| 23 | A --> C[End] |
| 24 | subgraph section |
| 25 | B |
| 26 | C |
| 27 | end `, |
| 28 | { theme: 'forest' } |
| 29 | ); |
| 30 | }); |
| 31 | it('Settings from initialize overriding themeVariable - nodes should be red', () => { |
| 32 | imgSnapshotTest( |
| 33 | ` |
| 34 | |
| 35 | |
| 36 | %%{init: { 'theme': 'base', 'themeVariables':{ 'primaryColor': '#ff0000'}}}%% |
| 37 | graph TD |
| 38 | A(Start) --> B[/Another/] |
| 39 | A[/Another/] --> C[End] |
| 40 | subgraph section |
| 41 | B |
| 42 | C |
| 43 | end |
| 44 | `, |
| 45 | { theme: 'base', themeVariables: { primaryColor: '#ff0000' }, logLevel: 0 } |
| 46 | ); |
| 47 | }); |
| 48 | it('Settings from directive - nodes should be grey', () => { |
| 49 | imgSnapshotTest( |
| 50 | ` |
| 51 | %%{init: { 'logLevel': 0, 'theme': 'neutral'} }%% |
| 52 | graph TD |
| 53 | A(Start) --> B[/Another/] |
| 54 | A[/Another/] --> C[End] |
| 55 | subgraph section |
| 56 | B |
| 57 | C |
| 58 | end |
| 59 | `, |
| 60 | {} |
| 61 | ); |
| 62 | }); |
| 63 | it('Settings from frontmatter - nodes should be grey', () => { |
| 64 | imgSnapshotTest( |
| 65 | ` |
| 66 | --- |
| 67 | config: |
| 68 | theme: neutral |
| 69 | --- |
| 70 | graph TD |
| 71 | A(Start) --> B[/Another/] |
| 72 | A[/Another/] --> C[End] |
| 73 | subgraph section |
| 74 | B |
| 75 | C |
| 76 | end |
| 77 | `, |
| 78 | {} |
| 79 | ); |
| 80 | }); |
| 81 | |
| 82 | it('Settings from directive overriding theme variable - nodes should be red', () => { |
| 83 | imgSnapshotTest( |
| 84 | ` |
| 85 | %%{init: {'theme': 'base', 'themeVariables':{ 'primaryColor': '#ff0000'}}}%% |
| 86 | graph TD |
| 87 | A(Start) --> B[/Another/] |
| 88 | A[/Another/] --> C[End] |
| 89 | subgraph section |
| 90 | B |
| 91 | C |
| 92 | end |
| 93 | `, |
| 94 | {} |
| 95 | ); |
| 96 | }); |
| 97 | it('Settings from initialize and directive - nodes should be grey', () => { |
| 98 | imgSnapshotTest( |
| 99 | ` |
| 100 | %%{init: { 'logLevel': 0, 'theme': 'neutral'} }%% |
| 101 | graph TD |
| 102 | A(Start) --> B[/Another/] |
| 103 | A[/Another/] --> C[End] |
| 104 | subgraph section |
| 105 | B |
| 106 | C |
| 107 | end |
| 108 | `, |
| 109 | { theme: 'forest' } |
| 110 | ); |
| 111 | }); |
| 112 | it('Theme from initialize, directive overriding theme variable - nodes should be red', () => { |
| 113 | imgSnapshotTest( |
| 114 | ` |
| 115 | %%{init: {'theme': 'base', 'themeVariables':{ 'primaryColor': '#ff0000'}}}%% |
| 116 | graph TD |
| 117 | A(Start) --> B[/Another/] |
| 118 | A[/Another/] --> C[End] |
| 119 | subgraph section |
| 120 | B |
| 121 | C |
| 122 | end |
| 123 | `, |
| 124 | { theme: 'base' } |
| 125 | ); |
| 126 | }); |
| 127 | it('Theme from initialize, frontmatter overriding theme variable - nodes should be red', () => { |
| 128 | imgSnapshotTest( |
| 129 | ` |
| 130 | --- |
| 131 | config: |
| 132 | theme: base |
| 133 | themeVariables: |
| 134 | primaryColor: '#ff0000' |
| 135 | --- |
| 136 | graph TD |
| 137 | A(Start) --> B[/Another/] |
| 138 | A[/Another/] --> C[End] |
| 139 | subgraph section |
| 140 | B |
| 141 | C |
| 142 | end |
| 143 | `, |
| 144 | { theme: 'forest' } |
| 145 | ); |
| 146 | }); |
| 147 | it('Theme from initialize, frontmatter overriding theme variable, directive overriding primaryColor - nodes should be red', () => { |
| 148 | imgSnapshotTest( |
| 149 | ` |
| 150 | --- |
| 151 | config: |
| 152 | theme: base |
| 153 | themeVariables: |
| 154 | primaryColor: '#00ff00' |
| 155 | --- |
| 156 | %%{init: {'theme': 'base', 'themeVariables':{ 'primaryColor': '#ff0000'}}}%% |
| 157 | graph TD |
| 158 | A(Start) --> B[/Another/] |
| 159 | A[/Another/] --> C[End] |
| 160 | subgraph section |
| 161 | B |
| 162 | C |
| 163 | end |
| 164 | `, |
| 165 | { theme: 'forest' } |
| 166 | ); |
| 167 | }); |
| 168 | |
| 169 | it('should render if values are not quoted properly', () => { |
| 170 | // #ff0000 is not quoted properly, and will evaluate to null. |
| 171 | // This test ensures that the rendering still works. |
| 172 | imgSnapshotTest( |
| 173 | `--- |
| 174 | config: |
| 175 | theme: base |
| 176 | themeVariables: |
| 177 | primaryColor: #ff0000 |
| 178 | --- |
| 179 | graph TD |
| 180 | A(Start) --> B[/Another/] |
| 181 | A[/Another/] --> C[End] |
| 182 | subgraph section |
| 183 | B |
| 184 | C |
| 185 | end |
| 186 | `, |
| 187 | { theme: 'forest' } |
| 188 | ); |
| 189 | }); |
| 190 | |
| 191 | it('Theme variable from initialize, theme from directive - nodes should be red', () => { |
| 192 | imgSnapshotTest( |
| 193 | ` |
| 194 | %%{init: { 'logLevel': 0, 'theme': 'base'} }%% |
| 195 | graph TD |
| 196 | A(Start) --> B[/Another/] |
| 197 | A[/Another/] --> C[End] |
| 198 | subgraph section |
| 199 | B |
| 200 | C |
| 201 | end |
| 202 | `, |
| 203 | { themeVariables: { primaryColor: '#ff0000' } } |
| 204 | ); |
| 205 | }); |
| 206 | describe('when rendering several diagrams', () => { |
| 207 | it('diagrams should not taint later diagrams', () => { |
| 208 | const url = '/theme-directives.html'; |
| 209 | urlSnapshotTest(url, {}); |
| 210 | }); |
| 211 | }); |
| 212 | }); |
| 213 | |