Skip to content

Commit 7b5f446

Browse files
committed
chore: update snapshots
1 parent 8c9c581 commit 7b5f446

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

packages/pluggableWidgets/barcode-scanner-native/src/__tests__/BarcodeScanner.spec.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// __tests__/BarcodeScanner.spec.tsx
22
import { actionValue, EditableValueBuilder } from "@mendix/piw-utils-internal";
3+
import { render } from "@testing-library/react-native";
34
import { createElement } from "react";
45
import { View } from "react-native";
5-
import { fireEvent, render, RenderAPI } from "@testing-library/react-native";
66
import { BarcodeScanner, Props } from "../BarcodeScanner";
7-
import { Camera } from "react-native-vision-camera";
7+
8+
let mockOnCodeScanned: ((codes: { value: string }[]) => void) | undefined;
89

910
jest.mock("react-native-vision-camera", () => ({
1011
Camera: ({ children, ...props }: any) => <View {...props}>{children}</View>,
1112
useCameraDevice: () => "mock-device",
12-
useCodeScanner: () => jest.fn()
13+
useCodeScanner: (options: any) => {
14+
mockOnCodeScanned = options.onCodeScanned;
15+
return "mockCodeScanner";
16+
}
1317
}));
1418

1519
jest.mock("react-native-barcode-mask", () => "BarcodeMask");
@@ -49,27 +53,20 @@ describe("BarcodeScanner", () => {
4953

5054
it("sets a value and executes the onDetect action when a new barcode is scanned", () => {
5155
const onDetectAction = actionValue();
52-
const component = render(<BarcodeScanner {...defaultProps} onDetect={onDetectAction} />);
56+
render(<BarcodeScanner {...defaultProps} onDetect={onDetectAction} />);
5357

54-
detectBarcode(component, "value");
58+
// Simulate scanning
59+
mockOnCodeScanned?.([{ value: "value" }]);
5560
jest.advanceTimersByTime(2000);
5661

5762
expect(defaultProps.barcode.setValue).toHaveBeenCalledWith("value");
5863
expect(onDetectAction.execute).toHaveBeenCalledTimes(1);
5964

60-
detectBarcode(component, "value1");
65+
// Another scan
66+
mockOnCodeScanned?.([{ value: "value1" }]);
6167
jest.advanceTimersByTime(2000);
6268

6369
expect(defaultProps.barcode.setValue).toHaveBeenCalledWith("value1");
6470
expect(onDetectAction.execute).toHaveBeenCalledTimes(2);
6571
});
6672
});
67-
68-
function detectBarcode(component: RenderAPI, barcode: string): void {
69-
fireEvent(component.UNSAFE_getByType(Camera), "onCodeScanned", [
70-
{
71-
value: barcode,
72-
type: "qr"
73-
}
74-
]);
75-
}

packages/pluggableWidgets/barcode-scanner-native/src/__tests__/__snapshots__/BarcodeScanner.spec.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exports[`BarcodeScanner renders 1`] = `
1212
>
1313
<View
1414
audio={false}
15-
codeScanner={[MockFunction]}
15+
codeScanner="mockCodeScanner"
1616
device="mock-device"
1717
isActive={true}
1818
style={
@@ -39,7 +39,7 @@ exports[`BarcodeScanner renders with mask 1`] = `
3939
>
4040
<View
4141
audio={false}
42-
codeScanner={[MockFunction]}
42+
codeScanner="mockCodeScanner"
4343
device="mock-device"
4444
isActive={true}
4545
style={
@@ -72,7 +72,7 @@ exports[`BarcodeScanner renders with mask with animated line 1`] = `
7272
>
7373
<View
7474
audio={false}
75-
codeScanner={[MockFunction]}
75+
codeScanner="mockCodeScanner"
7676
device="mock-device"
7777
isActive={true}
7878
style={

0 commit comments

Comments
 (0)