Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QRCodeScanner unit tests #484

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

QRCodeScanner unit tests #484

wants to merge 4 commits into from

Conversation

jlsOsorio
Copy link
Contributor

No description provided.

Simplify code in order to understand all QRCodeScanner states;
Remove unused QRButton component. The only place where QRCodeScanner is being used is in BottomNav component.
Rename files to .jsx in order to run successfully the component to test.
@jlsOsorio jlsOsorio requested a review from pstamatop December 3, 2024 15:07
@jlsOsorio jlsOsorio linked an issue Dec 3, 2024 that may be closed by this pull request
Comment on lines +96 to +102
let backCameraIndex = -1;
if (bestBackCamera) {
backCameraIndex = filteredDevices.findIndex(devices =>
devices.device.deviceId === bestBackCamera.device.deviceId);
}

setCurrentDeviceIndex(backCameraIndex > -1 ? backCameraIndex : 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let backCameraIndex = -1;
if (bestBackCamera) {
backCameraIndex = filteredDevices.findIndex(devices =>
devices.device.deviceId === bestBackCamera.device.deviceId);
}
setCurrentDeviceIndex(backCameraIndex > -1 ? backCameraIndex : 0);
setCurrentDeviceIndex(Math.max(0, filteredDevices.findIndex(({ device: { deviceId } }) => deviceId === bestBackCamera?.device.deviceId)));


useEffect(() => {
navigator.mediaDevices.getUserMedia({ video: true })
.then(stream => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use async/await with try/catch everywhere instead of then/catch

@@ -0,0 +1,270 @@
import React, { useState, useEffect, useRef } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When refactoring or adding code, I think we should use always use typescript

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you. We usually refactor with TS. We'll definitely look into that. Do you think it is suitable to make that change in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessarily in this PR

setQrDetected(true);
// Redirect to the URL found in the QR code
const scannedUrl = result.data;
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this timeout have any effect, since there is a shorter timeout for switching the window.location.href defined right after?

};

const onUserMedia = () => {
if (webcamRef.current && webcamRef.current.video) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is more readable if you return early on the opposite condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unit test QR Code module
2 participants