Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/layout/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,46 @@ span.xpassed,
}
}

.col-testId {
position: relative;

.copy-btn {
margin-left: 8px;
padding: 3px 5px;
border: 1px solid #ccc;
border-radius: 3px;
background-color: transparent;
cursor: pointer;
font-size: 0;
line-height: 1;
vertical-align: middle;
transition: all 0.15s ease;
color: #999;

svg {
display: block;
width: 12px;
height: 12px;
}

&:hover {
background-color: #f6f6f6;
border-color: #999;
color: #666;
}

&:active {
background-color: #e6e6e6;
}

&.copied {
background-color: #4caf4faa;
border-color: #4caf4faa;
color: white;
}
}
}

/*------------------
* 2. Extra
*------------------*/
Expand Down
18 changes: 17 additions & 1 deletion src/pytest_html/basereport.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,23 @@ def _process_report(self, report, duration, processed_extras):
]
cells = [
f'<td class="col-result">{outcome}</td>',
f'<td class="col-testId">{test_id}</td>',
f"""<td class="col-testId">{test_id}
<button class="copy-btn"
data-test-id="{test_id}"
title="Copy test ID"
aria-label="Copy test ID">
<svg xmlns="http://www.w3.org/2000/svg"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how feasible is it to use U+1F4CB instead of the svg - i'd much prefer the character - but i have no idea how well supported that is

width="12" height="12"
fill="currentColor"
viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0
0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5
0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5
1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0z"/>
</svg>
</button>
</td>""",
f'<td class="col-duration">{formatted_duration}</td>',
f'<td class="col-links">{_process_links(links)}</td>',
]
Expand Down
19 changes: 19 additions & 0 deletions src/pytest_html/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const renderContent = (tests) => {
find('.logexpander', row).addEventListener('click',
(evt) => evt.target.parentNode.classList.toggle('expanded'),
)
const copyBtn = find('.copy-btn', row)
if (copyBtn) {
copyBtn.addEventListener('click', handleCopyTestId)
}
newTable.appendChild(row)
}
})
Expand All @@ -86,6 +90,21 @@ const renderDerived = () => {
})
}

const handleCopyTestId = (evt) => {
evt.stopPropagation()
const button = evt.currentTarget
const testId = button.dataset.testId

navigator.clipboard.writeText(testId).then(() => {
button.classList.add('copied')
setTimeout(() => {
button.classList.remove('copied')
}, 500)
}).catch(() => {
// Silently fail if clipboard API unavailable
})
}

const bindEvents = () => {
const filterColumn = (evt) => {
const { target: element } = evt
Expand Down