|
1 | 1 | import { describe, it, expect } from 'vitest' |
2 | 2 | import { renderCards, parseVolume } from '../src/cards' |
3 | | -import type { ServiceInfo } from '../src/services' |
| 3 | +import type { ServiceInfo, NetworkInfo } from '../src/services' |
| 4 | + |
| 5 | +function net(name: string, opts?: { aliases?: string[]; ipv4Address?: string }): NetworkInfo { |
| 6 | + return { name, aliases: opts?.aliases ?? [], ipv4Address: opts?.ipv4Address ?? '' } |
| 7 | +} |
4 | 8 |
|
5 | 9 | function makeService(overrides: Partial<ServiceInfo> & { name: string }): ServiceInfo { |
6 | 10 | return { |
@@ -142,6 +146,65 @@ describe('renderCards', () => { |
142 | 146 | expect(volLabel).toBeDefined() |
143 | 147 | expect(volLabel!.nextElementSibling!.className).toBe('vol-grid') |
144 | 148 | }) |
| 149 | + |
| 150 | + it('renders network names in card', () => { |
| 151 | + const services = [makeService({ |
| 152 | + name: 'app', |
| 153 | + image: 'nginx', |
| 154 | + networks: [net('frontend'), net('backend')], |
| 155 | + })] |
| 156 | + const container = renderCards(services) |
| 157 | + const labels = container.querySelectorAll('.card-label') |
| 158 | + const netLabel = Array.from(labels).find(l => l.textContent === 'Networks') |
| 159 | + expect(netLabel).toBeDefined() |
| 160 | + const netSection = netLabel!.parentElement! |
| 161 | + expect(netSection.textContent).toContain('frontend') |
| 162 | + expect(netSection.textContent).toContain('backend') |
| 163 | + }) |
| 164 | + |
| 165 | + it('renders network aliases in card', () => { |
| 166 | + const services = [makeService({ |
| 167 | + name: 'plex', |
| 168 | + image: 'plex', |
| 169 | + networks: [net('media', { aliases: ['plex-media', 'media-server'] })], |
| 170 | + })] |
| 171 | + const container = renderCards(services) |
| 172 | + const labels = container.querySelectorAll('.card-label') |
| 173 | + const netLabel = Array.from(labels).find(l => l.textContent === 'Networks') |
| 174 | + expect(netLabel).toBeDefined() |
| 175 | + const netSection = netLabel!.parentElement! |
| 176 | + expect(netSection.textContent).toContain('media') |
| 177 | + expect(netSection.textContent).toContain('plex-media') |
| 178 | + expect(netSection.textContent).toContain('media-server') |
| 179 | + }) |
| 180 | + |
| 181 | + it('renders network ipv4 address in card', () => { |
| 182 | + const services = [makeService({ |
| 183 | + name: 'app', |
| 184 | + image: 'nginx', |
| 185 | + networks: [net('backend', { ipv4Address: '172.20.0.10' })], |
| 186 | + })] |
| 187 | + const container = renderCards(services) |
| 188 | + const labels = container.querySelectorAll('.card-label') |
| 189 | + const netLabel = Array.from(labels).find(l => l.textContent === 'Networks') |
| 190 | + const netSection = netLabel!.parentElement! |
| 191 | + expect(netSection.textContent).toContain('172.20.0.10') |
| 192 | + }) |
| 193 | + |
| 194 | + it('renders network with both aliases and ip', () => { |
| 195 | + const services = [makeService({ |
| 196 | + name: 'app', |
| 197 | + image: 'nginx', |
| 198 | + networks: [net('media', { aliases: ['plex-alias'], ipv4Address: '172.20.0.5' })], |
| 199 | + })] |
| 200 | + const container = renderCards(services) |
| 201 | + const labels = container.querySelectorAll('.card-label') |
| 202 | + const netLabel = Array.from(labels).find(l => l.textContent === 'Networks') |
| 203 | + const netSection = netLabel!.parentElement! |
| 204 | + expect(netSection.textContent).toContain('media') |
| 205 | + expect(netSection.textContent).toContain('plex-alias') |
| 206 | + expect(netSection.textContent).toContain('172.20.0.5') |
| 207 | + }) |
145 | 208 | }) |
146 | 209 |
|
147 | 210 | describe('parseVolume', () => { |
|
0 commit comments