Skip to content
Merged
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
5 changes: 1 addition & 4 deletions app/components/countdown_alert_component.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# frozen_string_literal: true

class CountdownAlertComponent < BaseComponent
attr_reader :show_at_remaining, :alert_options, :countdown_options, :redirect_url, :tag_options
attr_reader :show_at_remaining, :alert_options, :countdown_options, :tag_options

def initialize(
show_at_remaining: nil,
alert_options: {},
countdown_options: {},
redirect_url: nil,
**tag_options
)
@show_at_remaining = show_at_remaining
@alert_options = alert_options
@countdown_options = countdown_options
@tag_options = tag_options
@redirect_url = redirect_url
end

def call
Expand All @@ -24,7 +22,6 @@ def call
**tag_options,
class: css_class,
'show-at-remaining': show_at_remaining&.in_milliseconds,
'redirect-url': redirect_url,
)
end

Expand Down
18 changes: 2 additions & 16 deletions app/javascript/packages/countdown/countdown-alert-element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import './countdown-element';
describe('CountdownAlertElement', () => {
const sandbox = useSandbox({ useFakeTimers: true });

function createElement({
showAtRemaining,
redirectURL,
}: { showAtRemaining?: number; redirectURL?: string } = {}) {
function createElement({ showAtRemaining }: { showAtRemaining?: number } = {}) {
document.body.innerHTML = `
<lg-countdown-alert
${showAtRemaining ? `show-at-remaining="${showAtRemaining}"` : ''}
${redirectURL ? `redirect-url="${redirectURL}"` : ''}>
<lg-countdown-alert ${showAtRemaining ? `show-at-remaining="${showAtRemaining}"` : ''}>
<div class="usa-alert usa-alert--info margin-bottom-4 usa-alert--info-time" role="status">
<div class="usa-alert__body">
<p class="usa-alert__text">
Expand Down Expand Up @@ -46,13 +41,4 @@ describe('CountdownAlertElement', () => {
expect(element.show).to.have.been.called();
});
});

it('redirects when time has expired', () => {
createElement({ redirectURL: '#teapot' });

sandbox.clock.tick(91000);
expect(window.location.hash).to.equal('');
sandbox.clock.tick(1000);
expect(window.location.hash).to.equal('#teapot');
});
});
21 changes: 0 additions & 21 deletions app/javascript/packages/countdown/countdown-alert-element.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import { trackEvent } from '@18f/identity-analytics';
import type { CountdownElement } from './countdown-element';

export class CountdownAlertElement extends HTMLElement {
connectedCallback() {
if (this.showAtRemaining) {
this.addEventListener('lg:countdown:tick', this.handleShowAtRemainingTick);
}

if (this.redirectURL) {
this.addEventListener('lg:countdown:tick', this.handleRedirectTick);
}
}

get showAtRemaining(): number | null {
return Number(this.getAttribute('show-at-remaining')) || null;
}

get redirectURL(): string | null {
return this.getAttribute('redirect-url') || null;
}

get countdown(): CountdownElement {
return this.querySelector('lg-countdown')!;
}
Expand All @@ -31,18 +22,6 @@ export class CountdownAlertElement extends HTMLElement {
}
};

handleRedirectTick = () => {
if (this.countdown.timeRemaining <= 0) {
trackEvent('Countdown timeout redirect', {
path: this.redirectURL,
expiration: this.countdown.expiration,
timeRemaining: this.countdown.timeRemaining,
});
window.location.href = this.redirectURL!;
this.removeEventListener('lg:countdown:tick', this.handleRedirectTick);
}
};

show() {
this.classList.remove('display-none');
}
Expand Down