From d5b5c81e8ec4fa34aa8f3d7105cfb7ba582d7f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Wed, 28 Oct 2020 12:08:17 +0000 Subject: [PATCH] fix(tests): fix issues reported by react-app/jest eslint rules --- ui/src/App.test.tsx | 2 +- ui/src/Components/Grid/AlertGrid/Grid.tsx | 2 +- .../Labels/FilterInputLabel/index.test.tsx | 2 - .../ManagedSilence/SilenceComment.test.tsx | 2 +- .../SilenceComment.test.tsx.snap | 118 +++++++++--------- .../Components/ManagedSilence/index.test.tsx | 2 +- .../SilenceModal/Browser/index.test.tsx | 2 +- .../DateTimeSelect/index.test.tsx | 4 +- ui/src/__mocks__/lodash.debounce.ts | 2 +- ui/src/__mocks__/lodash.throttle.ts | 2 +- 10 files changed, 68 insertions(+), 70 deletions(-) diff --git a/ui/src/App.test.tsx b/ui/src/App.test.tsx index 2090074ba..6f3ae0a2a 100644 --- a/ui/src/App.test.tsx +++ b/ui/src/App.test.tsx @@ -345,7 +345,7 @@ describe(" 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); diff --git a/ui/src/Components/Grid/AlertGrid/Grid.tsx b/ui/src/Components/Grid/AlertGrid/Grid.tsx index c889c66a4..1d5bf9f9e 100644 --- a/ui/src/Components/Grid/AlertGrid/Grid.tsx +++ b/ui/src/Components/Grid/AlertGrid/Grid.tsx @@ -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(50); diff --git a/ui/src/Components/Labels/FilterInputLabel/index.test.tsx b/ui/src/Components/Labels/FilterInputLabel/index.test.tsx index 83f3c2e2e..5546c7939 100644 --- a/ui/src/Components/Labels/FilterInputLabel/index.test.tsx +++ b/ui/src/Components/Labels/FilterInputLabel/index.test.tsx @@ -168,9 +168,7 @@ describe(" onChange", () => { NewUnappliedFilter("bar=baz") ); }); -}); -describe(" onChange", () => { it("clicking on the X button removes filters from alertStore", () => { alertStore.filters.setFilterValues([ NewUnappliedFilter("foo=bar"), diff --git a/ui/src/Components/ManagedSilence/SilenceComment.test.tsx b/ui/src/Components/ManagedSilence/SilenceComment.test.tsx index e214b6049..c769536f9 100644 --- a/ui/src/Components/ManagedSilence/SilenceComment.test.tsx +++ b/ui/src/Components/ManagedSilence/SilenceComment.test.tsx @@ -103,7 +103,7 @@ describe("", () => { 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(); diff --git a/ui/src/Components/ManagedSilence/__snapshots__/SilenceComment.test.tsx.snap b/ui/src/Components/ManagedSilence/__snapshots__/SilenceComment.test.tsx.snap index b3620d218..6c286ecab 100644 --- a/ui/src/Components/ManagedSilence/__snapshots__/SilenceComment.test.tsx.snap +++ b/ui/src/Components/ManagedSilence/__snapshots__/SilenceComment.test.tsx.snap @@ -147,65 +147,6 @@ exports[` Matches snapshot when collapsed and multiple cluster " `; -exports[` Matches snapshot when collapsed and multiple clusters are present 2`] = ` -" -
-
- - - - -
-
-
- Mocked Silence -
-
- - — me@example.com - -
-
-
-
-
- - 123 - -
- - - - - - -
-
-
-" -`; - exports[` Matches snapshot when expanded 1`] = ` "
@@ -264,3 +205,62 @@ exports[` Matches snapshot when expanded 1`] = `
" `; + +exports[` Matches snapshot when expanded and multiple clusters are present 1`] = ` +" +
+
+ + + + +
+
+
+ Mocked Silence +
+
+ + — me@example.com + +
+
+
+
+
+ + 123 + +
+ + + + + + +
+
+
+" +`; diff --git a/ui/src/Components/ManagedSilence/index.test.tsx b/ui/src/Components/ManagedSilence/index.test.tsx index 13691fbd0..ffea0bf1e 100644 --- a/ui/src/Components/ManagedSilence/index.test.tsx +++ b/ui/src/Components/ManagedSilence/index.test.tsx @@ -179,7 +179,7 @@ describe("", () => { 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"); diff --git a/ui/src/Components/SilenceModal/Browser/index.test.tsx b/ui/src/Components/SilenceModal/Browser/index.test.tsx index 0efd31653..9f5baf585 100644 --- a/ui/src/Components/SilenceModal/Browser/index.test.tsx +++ b/ui/src/Components/SilenceModal/Browser/index.test.tsx @@ -185,7 +185,7 @@ describe("", () => { 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, diff --git a/ui/src/Components/SilenceModal/DateTimeSelect/index.test.tsx b/ui/src/Components/SilenceModal/DateTimeSelect/index.test.tsx index 2a3dfb34d..46858c211 100644 --- a/ui/src/Components/SilenceModal/DateTimeSelect/index.test.tsx +++ b/ui/src/Components/SilenceModal/DateTimeSelect/index.test.tsx @@ -280,7 +280,7 @@ describe("", () => { 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("", () => { 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, diff --git a/ui/src/__mocks__/lodash.debounce.ts b/ui/src/__mocks__/lodash.debounce.ts index 3a59d2b4b..a21eea57d 100644 --- a/ui/src/__mocks__/lodash.debounce.ts +++ b/ui/src/__mocks__/lodash.debounce.ts @@ -1,4 +1,4 @@ -export default function (wrapped: any) { +export default function debounce(wrapped: any) { wrapped.cancel = jest.fn(); return wrapped; } diff --git a/ui/src/__mocks__/lodash.throttle.ts b/ui/src/__mocks__/lodash.throttle.ts index 5b021225c..1b164dbba 100644 --- a/ui/src/__mocks__/lodash.throttle.ts +++ b/ui/src/__mocks__/lodash.throttle.ts @@ -1,3 +1,3 @@ -export default function (wrapped: any) { +export default function throttle(wrapped: any) { return wrapped; }