Skip to content

Commit

Permalink
updated test
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai committed Oct 29, 2024
1 parent bd48461 commit 72492eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
8 changes: 0 additions & 8 deletions events/scripts/content-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,6 @@ export async function updateRSVPButtonState(rsvpBtn, miloLibs) {
await registeredState();
} else if (rsvpData.registrationStatus === 'waitlisted') {
await waitlistedState();
} else if (!rsvpData.ok) {
if (rsvpData.error?.message === 'Request to ESP failed: Event is full') {
if (allowWaitlisting) {
await waitlistState();
} else {
await closedState();
}
}
}
}

Expand Down
21 changes: 19 additions & 2 deletions test/unit/scripts/content-update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Content Update Script', () => {

const buttonOriginalText = document.querySelector('a[href$="#rsvp-form-1"]').textContent;
autoUpdateContent(document, miloDeps);
BlockMediator.set('rsvpData', { ok: true, data: { status: { registered: false } } });
BlockMediator.set('rsvpData', null);

expect(document.querySelector('a[href$="#rsvp-form-1"]').textContent).to.be.equal(buttonOriginalText);
});
Expand Down Expand Up @@ -131,14 +131,31 @@ describe('updateRSVPButtonState', () => {
await updateRSVPButtonState(rsvpBtn, LIBS);
expect(rsvpBtn.el.textContent).to.equal('RSVP');

BlockMediator.set('rsvpData', { ok: false, error: { message: 'Request to ESP failed: Event is full' } });
BlockMediator.set('eventData', { isFull: true, allowWaitlisting: false });
await updateRSVPButtonState(rsvpBtn, LIBS);
expect(rsvpBtn.el.classList.contains('disabled')).to.be.true;

BlockMediator.set('eventData', { isFull: true, allowWaitlisting: true });
await updateRSVPButtonState(rsvpBtn, LIBS);
expect(rsvpBtn.el.classList.contains('disabled')).to.be.false;

BlockMediator.set('rsvpData', { registrationStatus: 'registered' });
BlockMediator.set('eventData', { isFull: true, allowWaitlisting: false });
await updateRSVPButtonState(rsvpBtn, LIBS);
expect(rsvpBtn.el.classList.contains('disabled')).to.be.false;

BlockMediator.set('eventData', { isFull: true, allowWaitlisting: true });
await updateRSVPButtonState(rsvpBtn, LIBS);
expect(rsvpBtn.el.classList.contains('disabled')).to.be.false;

BlockMediator.set('rsvpData', { registrationStatus: 'waitlisted' });
BlockMediator.set('eventData', { isFull: true, allowWaitlisting: false });
await updateRSVPButtonState(rsvpBtn, LIBS);
expect(rsvpBtn.el.classList.contains('disabled')).to.be.false;

BlockMediator.set('eventData', { isFull: true, allowWaitlisting: true });
await updateRSVPButtonState(rsvpBtn, LIBS);
expect(rsvpBtn.el.classList.contains('disabled')).to.be.false;
});
});

Expand Down

0 comments on commit 72492eb

Please sign in to comment.