fix(tests): fix issues reported by react-app/jest eslint rules

This commit is contained in:
Łukasz Mierzwa
2020-10-28 12:26:51 +00:00
committed by Łukasz Mierzwa
parent 367c05e1fa
commit d5b5c81e8e
10 changed files with 68 additions and 70 deletions
+1 -1
View File
@@ -345,7 +345,7 @@ describe("<App /> theme", () => {
},
];
for (const testCase of testCases) {
it(testCase.name, () => {
it(`${testCase.name}`, () => {
window.matchMedia = mockMatchMedia(testCase.matchMedia);
const tree = getApp(testCase.settings);
expect(tree.find(testCase.theme)).toHaveLength(1);
+1 -1
View File
@@ -43,7 +43,7 @@ const Grid: FC<{
}) => {
const context = React.useContext(ThemeContext);
const { ref, repack } = useGrid(gridSizesConfig);
const debouncedRepack = useCallback(debounce(repack, 10), [repack]);
const debouncedRepack = useCallback(() => debounce(repack, 10), [repack]);
const [groupsToRender, setGroupsToRender] = useState<number>(50);
@@ -168,9 +168,7 @@ describe("<FilterInputLabel /> onChange", () => {
NewUnappliedFilter("bar=baz")
);
});
});
describe("<FilterInputLabel /> onChange", () => {
it("clicking on the X button removes filters from alertStore", () => {
alertStore.filters.setFilterValues([
NewUnappliedFilter("foo=bar"),
@@ -103,7 +103,7 @@ describe("<SilenceComment />", () => {
expect(toDiffableHtml(tree.html())).toMatchSnapshot();
});
it("Matches snapshot when collapsed and multiple clusters are present", () => {
it("Matches snapshot when expanded and multiple clusters are present", () => {
MockMultipleClusters();
const tree = MountedSilenceComment(false, "ha");
expect(toDiffableHtml(tree.html())).toMatchSnapshot();
@@ -147,65 +147,6 @@ exports[`<SilenceComment /> Matches snapshot when collapsed and multiple cluster
"
`;
exports[`<SilenceComment /> Matches snapshot when collapsed and multiple clusters are present 2`] = `
"
<div class=\\"d-flex flex-row\\">
<div class=\\"flex-shrink-0 flex-grow-0\\">
<svg aria-hidden=\\"true\\"
focusable=\\"false\\"
data-prefix=\\"fas\\"
data-icon=\\"bell-slash\\"
class=\\"svg-inline--fa fa-bell-slash fa-w-20 components-managed-silence-icon text-muted\\"
role=\\"img\\"
xmlns=\\"http://www.w3.org/2000/svg\\"
viewbox=\\"0 0 640 512\\"
>
<path fill=\\"currentColor\\"
d=\\"M633.82 458.1l-90.62-70.05c.19-1.38.8-2.66.8-4.06.05-7.55-2.61-15.27-8.61-21.71-19.32-20.76-55.47-51.99-55.47-154.29 0-77.7-54.48-139.9-127.94-155.16V32c0-17.67-14.32-32-31.98-32s-31.98 14.33-31.98 32v20.84c-40.33 8.38-74.66 31.07-97.59 62.57L45.47 3.37C38.49-2.05 28.43-.8 23.01 6.18L3.37 31.45C-2.05 38.42-.8 48.47 6.18 53.9l588.35 454.73c6.98 5.43 17.03 4.17 22.46-2.81l19.64-25.27c5.42-6.97 4.17-17.02-2.81-22.45zM157.23 251.54c-8.61 67.96-36.41 93.33-52.62 110.75-6 6.45-8.66 14.16-8.61 21.71.11 16.4 12.98 32 32.1 32h241.92L157.23 251.54zM320 512c35.32 0 63.97-28.65 63.97-64H256.03c0 35.35 28.65 64 63.97 64z\\"
>
</path>
</svg>
</div>
<div class=\\"mx-2 flex-shrink-1 flex-grow-1 mw-1p\\">
<div class=\\"font-italic components-managed-silence-comment \\">
Mocked Silence
</div>
<div class=\\"components-managed-silence-cite mt-1\\">
<span class=\\"text-muted mr-2 font-italic\\">
— me@example.com
</span>
</div>
</div>
<div class=\\"flex-shrink-0 flex-grow-0\\">
<div class=\\"d-flex flex-column flex-sm-row justify-content-between align-items-center\\">
<div class=\\" tooltip-trigger\\">
<span class=\\"badge-primary badge-pill components-label-with-hover components-label badge\\">
123
</span>
</div>
<span class=\\"badge components-label with-click\\">
<svg aria-hidden=\\"true\\"
focusable=\\"false\\"
data-prefix=\\"fas\\"
data-icon=\\"chevron-down\\"
class=\\"svg-inline--fa fa-chevron-down fa-w-14 components-managed-silence-icon m-auto text-muted cursor-pointer\\"
role=\\"img\\"
xmlns=\\"http://www.w3.org/2000/svg\\"
viewbox=\\"0 0 448 512\\"
style=\\"transition: transform 0.25s ease-in-out;\\"
>
<path fill=\\"currentColor\\"
d=\\"M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z\\"
>
</path>
</svg>
</span>
</div>
</div>
</div>
"
`;
exports[`<SilenceComment /> Matches snapshot when expanded 1`] = `
"
<div class=\\"d-flex flex-row\\">
@@ -264,3 +205,62 @@ exports[`<SilenceComment /> Matches snapshot when expanded 1`] = `
</div>
"
`;
exports[`<SilenceComment /> Matches snapshot when expanded and multiple clusters are present 1`] = `
"
<div class=\\"d-flex flex-row\\">
<div class=\\"flex-shrink-0 flex-grow-0\\">
<svg aria-hidden=\\"true\\"
focusable=\\"false\\"
data-prefix=\\"fas\\"
data-icon=\\"bell-slash\\"
class=\\"svg-inline--fa fa-bell-slash fa-w-20 components-managed-silence-icon text-muted\\"
role=\\"img\\"
xmlns=\\"http://www.w3.org/2000/svg\\"
viewbox=\\"0 0 640 512\\"
>
<path fill=\\"currentColor\\"
d=\\"M633.82 458.1l-90.62-70.05c.19-1.38.8-2.66.8-4.06.05-7.55-2.61-15.27-8.61-21.71-19.32-20.76-55.47-51.99-55.47-154.29 0-77.7-54.48-139.9-127.94-155.16V32c0-17.67-14.32-32-31.98-32s-31.98 14.33-31.98 32v20.84c-40.33 8.38-74.66 31.07-97.59 62.57L45.47 3.37C38.49-2.05 28.43-.8 23.01 6.18L3.37 31.45C-2.05 38.42-.8 48.47 6.18 53.9l588.35 454.73c6.98 5.43 17.03 4.17 22.46-2.81l19.64-25.27c5.42-6.97 4.17-17.02-2.81-22.45zM157.23 251.54c-8.61 67.96-36.41 93.33-52.62 110.75-6 6.45-8.66 14.16-8.61 21.71.11 16.4 12.98 32 32.1 32h241.92L157.23 251.54zM320 512c35.32 0 63.97-28.65 63.97-64H256.03c0 35.35 28.65 64 63.97 64z\\"
>
</path>
</svg>
</div>
<div class=\\"mx-2 flex-shrink-1 flex-grow-1 mw-1p\\">
<div class=\\"font-italic components-managed-silence-comment \\">
Mocked Silence
</div>
<div class=\\"components-managed-silence-cite mt-1\\">
<span class=\\"text-muted mr-2 font-italic\\">
— me@example.com
</span>
</div>
</div>
<div class=\\"flex-shrink-0 flex-grow-0\\">
<div class=\\"d-flex flex-column flex-sm-row justify-content-between align-items-center\\">
<div class=\\" tooltip-trigger\\">
<span class=\\"badge-primary badge-pill components-label-with-hover components-label badge\\">
123
</span>
</div>
<span class=\\"badge components-label with-click\\">
<svg aria-hidden=\\"true\\"
focusable=\\"false\\"
data-prefix=\\"fas\\"
data-icon=\\"chevron-down\\"
class=\\"svg-inline--fa fa-chevron-down fa-w-14 components-managed-silence-icon m-auto text-muted cursor-pointer\\"
role=\\"img\\"
xmlns=\\"http://www.w3.org/2000/svg\\"
viewbox=\\"0 0 448 512\\"
style=\\"transition: transform 0.25s ease-in-out;\\"
>
<path fill=\\"currentColor\\"
d=\\"M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z\\"
>
</path>
</svg>
</span>
</div>
</div>
</div>
"
`;
@@ -179,7 +179,7 @@ describe("<ManagedSilence />", () => {
expect(button.text()).toBe("Recreate");
});
it("clicking on Edit calls ", () => {
it("clicking on Edit calls", () => {
const tree = MountedManagedSilence();
tree.find("svg.text-muted.cursor-pointer").simulate("click");
@@ -185,7 +185,7 @@ describe("<Browser />", () => {
expect(toDiffableHtml(tree.html())).toMatch(/fa-spinner/);
});
it("renders loading placeholder before fetch finishes", () => {
it("loading placeholder has text-danger class when retrying fetches", () => {
useFetchGetMock.fetch.setMockedData({
response: null,
error: null,
@@ -280,7 +280,7 @@ describe("<TabContentStart />", () => {
ValidateTimeButton(tree, "startsAt", 3, /angle-down/, -1 * 60 * 1000);
});
it("scrolling down on the minute button subtracts 1m from startsAt", () => {
it("scrolling down by deltaY=2 on the minute button subtracts 1m from startsAt", () => {
const tree = MountedTabContentStart();
ValidateTimeWheel(
tree,
@@ -296,7 +296,7 @@ describe("<TabContentStart />", () => {
ValidateTimeWheel(tree, "startsAt", "td.components-minute", -50, 60 * 1000);
});
it("scrolling down on the minute subtracts 1m from startsAt", () => {
it("scrolling down by deltaY=1 on the minute subtracts 1m from startsAt", () => {
const tree = MountedTabContentStart();
ValidateTimeWheel(
tree,
+1 -1
View File
@@ -1,4 +1,4 @@
export default function (wrapped: any) {
export default function debounce(wrapped: any) {
wrapped.cancel = jest.fn();
return wrapped;
}
+1 -1
View File
@@ -1,3 +1,3 @@
export default function (wrapped: any) {
export default function throttle(wrapped: any) {
return wrapped;
}