test(badges): pass attendee workflow test (edit → print → return)

- Add data-testid to badge edit/save/cancel/print buttons and professional title input
- Fix API mock routes (badge GET uses /v3/crud/event_badge/{id}, not nested)
- Add badge_template mock so badge view renders
- Add event_badge_id_random and id_random fields to all mock responses
- Split workflow test into its own test() instead of being inline in beforeEach
- Use data-testid selectors throughout for stability
This commit is contained in:
Scott Idem
2026-02-26 17:28:08 -05:00
parent 657a7122b8
commit d1ded2d45e
2 changed files with 173 additions and 112 deletions

View File

@@ -473,6 +473,53 @@
update_status = 'idle';
update_complete = true;
}
let print_status = $state('idle'); // 'idle' | 'loading' | 'done' | 'error'
async function handle_print_badge() {
if (!$lq__event_badge_obj?.event_badge_id) {
console.error('Cannot print badge: event_badge_id is missing.');
return;
}
print_status = 'loading';
const now = new Date().toISOString();
const current_print_count = $lq__event_badge_obj.print_count ?? 0;
const is_first_print = current_print_count === 0;
const data_to_update: key_val = {
print_count: current_print_count + 1,
print_last_datetime: now
};
if (is_first_print) {
data_to_update.print_first_datetime = now;
}
try {
await events_func.update_ae_obj__event_badge({
api_cfg: $ae_api,
event_id: event_id,
event_badge_id: $lq__event_badge_obj.event_badge_id,
data_kv: data_to_update,
log_lvl: log_lvl
});
print_status = 'done';
console.log(`Badge printed. Count: ${data_to_update.print_count}`);
// Reset status after 2 seconds
setTimeout(() => {
print_status = 'idle';
}, 2000);
} catch (error) {
console.error('Error printing badge:', error);
print_status = 'error';
setTimeout(() => {
print_status = 'idle';
}, 3000);
}
}
</script>
<!--
@@ -565,6 +612,7 @@ onkeypress={() => {
"
onclick={handle_save_changes}
title="Save Changes"
data-testid="badge-save-btn"
>
<span class="fas fa-save m-1"></span>
<span
@@ -586,6 +634,7 @@ onkeypress={() => {
"
onclick={handle_cancel_changes}
title="Cancel Editing"
data-testid="badge-cancel-btn"
>
<span class="fas fa-times m-1"></span>
<span
@@ -611,6 +660,7 @@ onkeypress={() => {
$ae_loc.edit_mode = true;
}}
title="Edit Badge Information"
data-testid="badge-edit-btn"
>
<span class="fas fa-edit m-1"></span>
<span
@@ -625,6 +675,51 @@ onkeypress={() => {
</button>
{/if}
<!-- Print Button -->
<button
type="button"
class="
btn btn-sm text-xs
preset-outlined-primary-100-900 hover:preset-filled-primary-500
transition-all group
"
class:preset-tonal-primary={print_status === 'loading'}
class:preset-filled-success-500={print_status === 'done'}
class:preset-filled-error-500={print_status === 'error'}
onclick={handle_print_badge}
disabled={print_status === 'loading'}
title="Print Badge (Increment Count)"
data-testid="badge-print-btn"
>
{#if print_status === 'loading'}
<span class="fas fa-spinner fa-spin m-1"></span>
{:else if print_status === 'done'}
<span class="fas fa-check m-1"></span>
{:else if print_status === 'error'}
<span class="fas fa-exclamation-triangle m-1"></span>
{:else}
<span class="fas fa-print m-1"></span>
{/if}
<span
class="
hidden
group-hover:inline-block
text-xs
"
>
{#if print_status === 'done'}
Printed!
{:else if print_status === 'error'}
Error
{:else}
Print Badge
{#if $lq__event_badge_obj?.print_count}
({$lq__event_badge_obj.print_count})
{/if}
{/if}
</span>
</button>
<div
class="w-md max-w-lg m-1 p-1"
class:hidden={!edit_mode_active}
@@ -744,6 +839,7 @@ onkeypress={() => {
editable_professional_title_override
}
class="input w-full text-center"
data-testid="badge-professional-title-input"
/>
{:else}
{@html editable_professional_title_override}