Skip to content

Commit 5775036

Browse files
committed
Add Link to Open Original Image
1 parent 4f1dc2b commit 5775036

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

templates/report.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@
101101
sans-serif;
102102
}
103103

104+
.lightbox-link {
105+
color: rgb(255 255 255 / 0.7);
106+
font:
107+
0.75rem/1 system-ui,
108+
sans-serif;
109+
text-decoration: none;
110+
padding: 0.25rem 0.75rem;
111+
border: 1px solid rgb(255 255 255 / 0.3);
112+
border-radius: 4px;
113+
transition:
114+
color 0.15s,
115+
border-color 0.15s;
116+
117+
&:hover,
118+
&:focus-visible {
119+
color: white;
120+
border-color: white;
121+
}
122+
}
123+
104124
.lightbox-btn {
105125
appearance: none;
106126
border: none;
@@ -259,6 +279,7 @@ <h2>Missing or New Files</h2>
259279
<img class="lightbox-image" src="" alt="" />
260280
<p class="lightbox-caption"></p>
261281
<span class="lightbox-counter"></span>
282+
<a class="lightbox-link" href="" target="_blank" rel="noopener">Open image</a>
262283
</div>
263284
</dialog>
264285

@@ -268,6 +289,7 @@ <h2>Missing or New Files</h2>
268289
const image = lightbox.querySelector('.lightbox-image');
269290
const caption = lightbox.querySelector('.lightbox-caption');
270291
const counter = lightbox.querySelector('.lightbox-counter');
292+
const link = lightbox.querySelector('.lightbox-link');
271293
const prevBtn = lightbox.querySelector('.lightbox-prev');
272294
const nextBtn = lightbox.querySelector('.lightbox-next');
273295

@@ -292,6 +314,7 @@ <h2>Missing or New Files</h2>
292314
image.alt = img.alt;
293315
caption.textContent = img.alt;
294316
counter.textContent = `${col + 1}\u2009/\u2009${grid[row].length}`;
317+
link.href = img.src;
295318
};
296319

297320
const open = (r, c) => {

test/report-generator.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,15 @@ describe('report-generator', () => {
158158
expect(html).toContain('aria-label="Next image"');
159159
});
160160

161-
it('should include lightbox panel with image, caption, and counter', () => {
161+
it('should include lightbox panel with image, caption, counter, and open link', () => {
162162
const pair = testDir.createPngFilePair('a.png', 'red', 'blue');
163163
const html = generateAndRead([{ pair, hasDifference: true, diffPercentage: 10 }]);
164164

165165
expect(html).toContain('class="lightbox-panel"');
166166
expect(html).toContain('class="lightbox-image"');
167167
expect(html).toContain('class="lightbox-caption"');
168168
expect(html).toContain('class="lightbox-counter"');
169+
expect(html).toContain('class="lightbox-link"');
169170
});
170171

171172
it('should wrap images in button triggers instead of anchor tags', () => {
@@ -235,6 +236,32 @@ describe('report-generator', () => {
235236
expect(html).toContain('ArrowDown');
236237
});
237238

239+
it('should render the open image link that opens in a new tab', () => {
240+
const pair = testDir.createPngFilePair('a.png', 'red', 'blue');
241+
const html = generateAndRead([{ pair, hasDifference: true, diffPercentage: 10 }]);
242+
243+
expect(html).toContain('<a class="lightbox-link"');
244+
expect(html).toContain('target="_blank"');
245+
expect(html).toContain('rel="noopener"');
246+
expect(html).toContain('>Open image</a>');
247+
});
248+
249+
it('should include script logic to update the open image link href', () => {
250+
const pair = testDir.createPngFilePair('a.png', 'red', 'blue');
251+
const html = generateAndRead([{ pair, hasDifference: true, diffPercentage: 10 }]);
252+
253+
expect(html).toContain('.lightbox-link');
254+
expect(html).toContain('link.href = img.src');
255+
});
256+
257+
it('should include CSS styles for the open image link', () => {
258+
const pair = testDir.createPngFilePair('a.png', 'red', 'blue');
259+
const html = generateAndRead([{ pair, hasDifference: true, diffPercentage: 10 }]);
260+
261+
expect(html).toContain('.lightbox-link');
262+
expect(html).toContain('text-decoration: none');
263+
});
264+
238265
it('should include lightbox CSS with zoom-in cursor and dialog styles', () => {
239266
const pair = testDir.createPngFilePair('a.png', 'red', 'blue');
240267
const html = generateAndRead([{ pair, hasDifference: true, diffPercentage: 10 }]);

0 commit comments

Comments
 (0)