@khanacademy/wonder-blocks-clickable 2.4.1 → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @khanacademy/wonder-blocks-clickable
2
2
 
3
+ ## 2.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - @khanacademy/wonder-blocks-core@4.6.1
8
+
9
+ ## 2.4.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [b561425a]
14
+ - Updated dependencies [a566e232]
15
+ - Updated dependencies [d2b21a6e]
16
+ - @khanacademy/wonder-blocks-core@4.6.0
17
+
3
18
  ## 2.4.1
4
19
 
5
20
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-clickable",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "design": "v1",
5
5
  "description": "Clickable component for Wonder-Blocks.",
6
6
  "main": "dist/index.js",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
- "@khanacademy/wonder-blocks-core": "^4.5.0"
19
+ "@khanacademy/wonder-blocks-core": "^4.6.1"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "aphrodite": "^1.2.5",
@@ -26,6 +26,6 @@
26
26
  "react-router-dom": "5.3.0"
27
27
  },
28
28
  "devDependencies": {
29
- "wb-dev-build-settings": "^0.4.0"
29
+ "wb-dev-build-settings": "^0.6.0"
30
30
  }
31
31
  }
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable max-lines */
3
3
  // @flow
4
4
  import * as React from "react";
5
- import {render, screen, fireEvent} from "@testing-library/react";
5
+ import {render, screen, fireEvent, waitFor} from "@testing-library/react";
6
6
  import {MemoryRouter, Switch, Route} from "react-router-dom";
7
7
  import userEvent from "@testing-library/user-event";
8
8
 
@@ -16,12 +16,6 @@ const keyCodes = {
16
16
  space: 32,
17
17
  };
18
18
 
19
- const wait = (delay: number = 0) =>
20
- new Promise((resolve, reject) => {
21
- // eslint-disable-next-line no-restricted-syntax
22
- return setTimeout(resolve, delay);
23
- });
24
-
25
19
  const labelForState = (state: ClickableState): string => {
26
20
  const labels = [];
27
21
  if (state.hovered) {
@@ -608,10 +602,11 @@ describe("ClickableBehavior", () => {
608
602
  // Act
609
603
  const link = screen.getByRole("link");
610
604
  userEvent.click(link);
611
- await wait(0);
612
605
 
613
606
  // Assert
614
- expect(window.location.assign).toHaveBeenCalledTimes(1);
607
+ await waitFor(() => {
608
+ expect(window.location.assign).toHaveBeenCalledTimes(1);
609
+ });
615
610
  });
616
611
 
617
612
  it("should show waiting UI before safeWithNav resolves", async () => {
@@ -923,10 +918,13 @@ describe("ClickableBehavior", () => {
923
918
 
924
919
  // Act
925
920
  userEvent.click(screen.getByRole("button"));
926
- await wait(0);
927
921
 
928
922
  // Assert
929
- expect(screen.getByText("Hello, world!")).toBeInTheDocument();
923
+ await waitFor(() => {
924
+ expect(
925
+ screen.getByText("Hello, world!"),
926
+ ).toBeInTheDocument();
927
+ });
930
928
  });
931
929
 
932
930
  it("shows waiting state before navigating", async () => {
@@ -1002,7 +1000,6 @@ describe("ClickableBehavior", () => {
1002
1000
 
1003
1001
  // Act
1004
1002
  userEvent.click(screen.getByRole("button"));
1005
- await wait(0);
1006
1003
 
1007
1004
  // Assert
1008
1005
  expect(
@@ -1047,10 +1044,11 @@ describe("ClickableBehavior", () => {
1047
1044
 
1048
1045
  // Act
1049
1046
  userEvent.click(screen.getByRole("button"));
1050
- await wait(0);
1051
1047
 
1052
1048
  // Assert
1053
- expect(safeWithNavMock).toHaveBeenCalled();
1049
+ await waitFor(() => {
1050
+ expect(safeWithNavMock).toHaveBeenCalled();
1051
+ });
1054
1052
  });
1055
1053
  });
1056
1054
 
@@ -1,18 +1,12 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
3
  import {MemoryRouter, Route, Switch} from "react-router-dom";
4
- import {render, screen, fireEvent} from "@testing-library/react";
4
+ import {render, screen, fireEvent, waitFor} from "@testing-library/react";
5
5
  import userEvent from "@testing-library/user-event";
6
6
 
7
7
  import {View} from "@khanacademy/wonder-blocks-core";
8
8
  import Clickable from "../clickable.js";
9
9
 
10
- const wait = (delay: number = 0) =>
11
- new Promise((resolve, reject) => {
12
- // eslint-disable-next-line no-restricted-syntax
13
- return setTimeout(resolve, delay);
14
- });
15
-
16
10
  describe("Clickable", () => {
17
11
  beforeEach(() => {
18
12
  delete window.location;
@@ -170,7 +164,6 @@ describe("Clickable", () => {
170
164
 
171
165
  // Act
172
166
  userEvent.click(screen.getByTestId("button"));
173
- await wait(0);
174
167
 
175
168
  // Assert
176
169
  expect(screen.queryByText("Hello, world!")).not.toBeInTheDocument();
@@ -201,7 +194,6 @@ describe("Clickable", () => {
201
194
 
202
195
  // Act
203
196
  userEvent.click(screen.getByTestId("button"));
204
- await wait(0);
205
197
 
206
198
  // Assert
207
199
  expect(safeWithNavMock).not.toHaveBeenCalled();
@@ -230,10 +222,11 @@ describe("Clickable", () => {
230
222
 
231
223
  // Act
232
224
  userEvent.click(screen.getByTestId("button"));
233
- await wait(0);
234
225
 
235
226
  // Assert
236
- expect(screen.getByText("Hello, world!")).toBeInTheDocument();
227
+ await waitFor(() => {
228
+ expect(screen.getByText("Hello, world!")).toBeInTheDocument();
229
+ });
237
230
  });
238
231
 
239
232
  test("beforeNav resolution results in safeWithNav being called", async () => {
@@ -261,10 +254,11 @@ describe("Clickable", () => {
261
254
 
262
255
  // Act
263
256
  userEvent.click(screen.getByTestId("button"));
264
- await wait(0);
265
257
 
266
258
  // Assert
267
- expect(safeWithNavMock).toHaveBeenCalled();
259
+ await waitFor(() => {
260
+ expect(safeWithNavMock).toHaveBeenCalled();
261
+ });
268
262
  });
269
263
 
270
264
  test("safeWithNav with skipClientNav=true waits for promise resolution", async () => {
@@ -291,10 +285,11 @@ describe("Clickable", () => {
291
285
 
292
286
  // Act
293
287
  userEvent.click(screen.getByTestId("button"));
294
- await wait(0);
295
288
 
296
289
  // Assert
297
- expect(window.location.assign).toHaveBeenCalledWith("/foo");
290
+ await waitFor(() => {
291
+ expect(window.location.assign).toHaveBeenCalledWith("/foo");
292
+ });
298
293
  });
299
294
 
300
295
  test("beforeNav resolution and safeWithNav with skipClientNav=true waits for promise resolution", async () => {
@@ -322,10 +317,11 @@ describe("Clickable", () => {
322
317
 
323
318
  // Act
324
319
  userEvent.click(screen.getByTestId("button"));
325
- await wait(0);
326
320
 
327
321
  // Assert
328
- expect(window.location.assign).toHaveBeenCalledWith("/foo");
322
+ await waitFor(() => {
323
+ expect(window.location.assign).toHaveBeenCalledWith("/foo");
324
+ });
329
325
  });
330
326
 
331
327
  test("safeWithNav with skipClientNav=true waits for promise rejection", async () => {
@@ -352,10 +348,11 @@ describe("Clickable", () => {
352
348
 
353
349
  // Act
354
350
  userEvent.click(screen.getByTestId("button"));
355
- await wait(0);
356
351
 
357
352
  // Assert
358
- expect(window.location.assign).toHaveBeenCalledWith("/foo");
353
+ await waitFor(() => {
354
+ expect(window.location.assign).toHaveBeenCalledWith("/foo");
355
+ });
359
356
  });
360
357
 
361
358
  test("safeWithNav with skipClientNav=false calls safeWithNav but doesn't wait to navigate", () => {
@@ -418,10 +415,11 @@ describe("Clickable", () => {
418
415
 
419
416
  // Act
420
417
  userEvent.click(screen.getByTestId("button"));
421
- await wait(0);
422
418
 
423
419
  // Assert
424
- expect(safeWithNavMock).toHaveBeenCalled();
420
+ await waitFor(() => {
421
+ expect(safeWithNavMock).toHaveBeenCalled();
422
+ });
425
423
  // client side nav to /foo
426
424
  expect(screen.getByText("Hello, world!")).toBeInTheDocument();
427
425
  // not a full page nav