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

Fixed the cypress env config file and removed hardcoded fallback #9184

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { defineConfig } from "cypress";
import cypressSplit from "cypress-split";
import * as dotenv from "dotenv";
import fs from "fs";

dotenv.config();

export default defineConfig({
projectId: "wf7d2m",
defaultCommandTimeout: 10000,
Expand Down Expand Up @@ -32,7 +35,7 @@ export default defineConfig({
requestTimeout: 15000,
},
env: {
API_URL: process.env.REACT_CARE_API_URL ?? "http://localhost:9000",
API_URL: process.env.REACT_CARE_API_URL,
ENABLE_HCX: process.env.REACT_ENABLE_HCX ?? false,
},
});
4 changes: 3 additions & 1 deletion cypress/pageobject/Patient/PatientFileupload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export class PatientFileUpload {

recordAudio() {
cy.get("#record-audio").click();
cy.wait(5000);
cy.wait(2000);
cy.get("#start-recording").click();
cy.wait(2000);
Comment on lines +23 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider replacing hard-coded waits with proper element state checks

The current implementation uses multiple cy.wait() calls with hard-coded timeouts, which could make tests flaky. Consider making the following improvements:

  recordAudio() {
    cy.get("#record-audio").click();
-   cy.wait(2000);
-   cy.get("#start-recording").click();
-   cy.wait(2000);
+   cy.get("#start-recording")
+     .should("be.visible")
+     .and("be.enabled")
+     .click();
+   // Wait for recording to start
+   cy.get("#recording-indicator")
+     .should("be.visible")
+     .and("have.class", "recording");
    cy.get("#stop-recording").click();
-   cy.wait(1000);
+   // Wait for recording to complete
+   cy.get("#recording-indicator")
+     .should("not.have.class", "recording");
    cy.get("#save-recording").click();
  }

This refactor:

  1. Removes arbitrary wait times
  2. Adds proper element state checks
  3. Makes the test more reliable by waiting for actual UI states
  4. Follows Cypress best practices for handling async operations

Note: Adjust the selectors (#recording-indicator) and classes (recording) according to your actual implementation.

Committable suggestion skipped: line range outside the PR's diff.

cy.get("#stop-recording").click();
cy.wait(1000);
cy.get("#save-recording").click();
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/Files/AudioCaptureDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default function AudioCaptureDialog(props: AudioCaptureDialogProps) {
<div>
<h2 className="font-bold text-white">{t("audio__record")}</h2>
<div className="text-secondary-200">{t("audio__record_helper")}</div>
<div className="mt-4">
<div className="mt-4" id="start-recording">
<button
onClick={handleStartRecording}
className="inline-flex aspect-square w-32 items-center justify-center rounded-full bg-white/10 text-6xl text-white hover:bg-white/20"
Expand Down
Loading