2022-05-14 02:09:05 -04:00
|
|
|
import Cookies from '~/lib/utils/cookies';
|
2022-05-13 08:08:49 -04:00
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2020-04-28 08:09:44 -04:00
|
|
|
import initBroadcastNotifications from '~/broadcast_notification';
|
|
|
|
|
|
|
|
describe('broadcast message on dismiss', () => {
|
|
|
|
const dismiss = () => {
|
|
|
|
const button = document.querySelector('.js-dismiss-current-broadcast-notification');
|
|
|
|
button.click();
|
|
|
|
};
|
|
|
|
const endsAt = '2020-01-01T00:00:00Z';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-05-13 08:08:49 -04:00
|
|
|
setHTMLFixture(`
|
2020-04-28 08:09:44 -04:00
|
|
|
<div class="js-broadcast-notification-1">
|
|
|
|
<button class="js-dismiss-current-broadcast-notification" data-id="1" data-expire-date="${endsAt}"></button>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
initBroadcastNotifications();
|
|
|
|
});
|
|
|
|
|
2022-05-13 08:08:49 -04:00
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2020-04-28 08:09:44 -04:00
|
|
|
it('removes broadcast message', () => {
|
|
|
|
dismiss();
|
|
|
|
|
|
|
|
expect(document.querySelector('.js-broadcast-notification-1')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls Cookies.set', () => {
|
|
|
|
jest.spyOn(Cookies, 'set');
|
|
|
|
dismiss();
|
|
|
|
|
|
|
|
expect(Cookies.set).toHaveBeenCalledWith('hide_broadcast_message_1', true, {
|
|
|
|
expires: new Date(endsAt),
|
2022-02-01 16:12:02 -05:00
|
|
|
secure: false,
|
2020-04-28 08:09:44 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|