mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
committed by
Łukasz Mierzwa
parent
8cfbd741a8
commit
3e7dc8ffc3
@@ -1,6 +1,7 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import { autorun } from "mobx";
|
||||
import { useObserver } from "mobx-react";
|
||||
|
||||
import Favico from "favico.js";
|
||||
@@ -18,13 +19,17 @@ const FaviconBadge = ({ alertStore }) => {
|
||||
})
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (alertStore.status.error !== null) {
|
||||
favico.badge("?");
|
||||
} else {
|
||||
favico.badge(alertStore.info.totalAlerts);
|
||||
}
|
||||
});
|
||||
useEffect(
|
||||
() =>
|
||||
autorun(() => {
|
||||
if (alertStore.status.error !== null) {
|
||||
favico.badge("?");
|
||||
} else {
|
||||
favico.badge(alertStore.info.totalAlerts);
|
||||
}
|
||||
}),
|
||||
[] // eslint-disable-line react-hooks/exhaustive-deps
|
||||
);
|
||||
|
||||
return useObserver(() => (
|
||||
<span
|
||||
|
||||
@@ -14,22 +14,29 @@ beforeEach(() => {
|
||||
Favico.badge.mockClear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
const MountedFaviconBadge = () => {
|
||||
return mount(<FaviconBadge alertStore={alertStore} />);
|
||||
};
|
||||
|
||||
describe("<FaviconBadge />", () => {
|
||||
it("badge is updated when alertStore.info.totalAlerts changes", () => {
|
||||
it("badge is updated on mount", () => {
|
||||
alertStore.info.totalAlerts = 99;
|
||||
const tree = MountedFaviconBadge();
|
||||
MountedFaviconBadge();
|
||||
expect(Favico.badge).toHaveBeenCalledTimes(1);
|
||||
expect(Favico.badge).toHaveBeenCalledWith(99);
|
||||
});
|
||||
|
||||
it("badge is updated when alertStore.info.totalAlerts changes", () => {
|
||||
alertStore.info.totalAlerts = 99;
|
||||
MountedFaviconBadge();
|
||||
expect(Favico.badge).toHaveBeenCalledTimes(1);
|
||||
expect(Favico.badge).toHaveBeenCalledWith(99);
|
||||
|
||||
alertStore.info.totalAlerts = 100;
|
||||
expect(Favico.badge).toHaveBeenCalledTimes(2);
|
||||
expect(Favico.badge).toHaveBeenLastCalledWith(100);
|
||||
});
|
||||
|
||||
it("badge is updated when alertStore.status.error changes", () => {
|
||||
alertStore.status.error = "foo";
|
||||
MountedFaviconBadge();
|
||||
|
||||
Reference in New Issue
Block a user