Skip to content

Commit

Permalink
Merge branch 'master' into importing-gha
Browse files Browse the repository at this point in the history
  • Loading branch information
emvaldes authored Oct 22, 2024
2 parents 5af3c9c + d91cf24 commit 31b2d85
Show file tree
Hide file tree
Showing 22 changed files with 3,778 additions and 1,308 deletions.
4 changes: 4 additions & 0 deletions frontend-react/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@ module.exports = {
/* Custom project rules */
"no-console": ["error", { allow: ["warn", "error", "info", "trace"] }],
"@typescript-eslint/no-explicit-any": ["off"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
},
],
"import/order": [
Expand All @@ -141,5 +144,6 @@ module.exports = {
],
"sort-imports": ["error", { ignoreCase: true, ignoreDeclarationSort: true }],
"@typescript-eslint/prefer-nullish-coalescing": ["error"],
"@typescript-eslint/no-empty-object-type": ["error", { allowInterfaces: "always" }],
},
};
4 changes: 2 additions & 2 deletions frontend-react/e2e/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function fromDateWithTime(date: string, time?: string) {
.substring(0, time.length - 2)
.split(":")
.map(Number);
hours = hours + (time.indexOf("pm") !== -1 ? 12 : 0);
hours = hours + (time.includes("pm") ? 12 : 0);
fromDateTime.setHours(hours, minutes, 0, 0);
} else {
fromDateTime.setHours(0, 0, 0);
Expand All @@ -132,7 +132,7 @@ export function toDateWithTime(date: string, time?: string) {
.substring(0, time.length - 2)
.split(":")
.map(Number);
hours = hours + (time.indexOf("pm") !== -1 ? 12 : 0);
hours = hours + (time.includes("pm") ? 12 : 0);
toDateTime.setHours(hours, minutes, 0, 0);
} else {
toDateTime.setHours(23, 59, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ test.describe("Evaluate links on public facing pages", { tag: "@warning" }, () =
}

return { url, status: 200 };
} catch (error) {
} catch (_error) {
warnings.push({ url, message: "Internal link: Page error" });
return { url, status: 400 };
} finally {
Expand Down
12 changes: 7 additions & 5 deletions frontend-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
"@types/react-router-dom": "^5.3.3",
"@types/react-scroll-sync": "^0.9.0",
"@types/sanitize-html": "^2.13.0",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@typescript-eslint/eslint-plugin": "^8.10.0",
"@typescript-eslint/parser": "^8.10.0",
"@vitejs/plugin-react": "^4.3.3",
"@vitest/coverage-istanbul": "^2.1.3",
"@vitest/ui": "^2.1.3",
Expand Down Expand Up @@ -187,8 +187,8 @@
"storybook": "^8.3.6",
"storybook-addon-remix-react-router": "^3.0.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"tslib": "^2.8.0",
"typescript": "^5.6.3",
"undici": "^6.20.1",
"vite": "^5.4.9",
"vite-plugin-checker": "^0.8.0",
Expand All @@ -197,7 +197,9 @@
},
"resolutions": {
"@types/react": "18.3.11",
"@okta/okta-auth-js": ">=7.8.1"
"@okta/okta-auth-js": ">=7.8.1",
"cookie": ">=0.7.0",
"send": ">=0.19.0"
},
"engines": {
"node": "^20.15"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ import { fireEvent, screen, waitFor } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { Suspense } from "react";

import FileHandlerFileUploadStep, {
getClientHeader,
} from "./FileHandlerFileUploadStep";
import {
fakeFile,
mockSendFileWithErrors,
mockSendValidFile,
} from "../../__mocks__/validation";
import FileHandlerFileUploadStep, { getClientHeader } from "./FileHandlerFileUploadStep";
import { fakeFile, mockSendFileWithErrors, mockSendValidFile } from "../../__mocks__/validation";
import { sendersGenerator } from "../../__mockServers__/OrganizationMockServer";
import { RSSender } from "../../config/endpoints/settings";
import { UseSenderResourceHookResult } from "../../hooks/api/organizations/UseOrganizationSender/UseOrganizationSender";
Expand All @@ -19,11 +13,7 @@ import useAppInsightsContext from "../../hooks/UseAppInsightsContext/UseAppInsig
import { INITIAL_STATE } from "../../hooks/UseFileHandler/UseFileHandler";
import { renderApp } from "../../utils/CustomRenderUtils";
import { MembershipSettings, MemberType } from "../../utils/OrganizationUtils";
import {
CustomerStatus,
FileType,
Format,
} from "../../utils/TemporarySettingsAPITypes";
import { CustomerStatus, FileType, Format } from "../../utils/TemporarySettingsAPITypes";

const { mockSessionContentReturnValue } = await vi.importMock<
typeof import("../../contexts/Session/__mocks__/useSessionContext")
Expand All @@ -42,9 +32,7 @@ describe("FileHandlerFileUploadStep", () => {
};
const DEFAULT_SENDERS: RSSender[] = sendersGenerator(2);

function mockUseSenderResource(
result: Partial<UseSenderResourceHookResult> = {},
) {
function mockUseSenderResource(result: Partial<UseSenderResourceHookResult> = {}) {
vi.spyOn(useSenderResourceExports, "default").mockReturnValue({
isInitialLoading: false,
isLoading: false,
Expand Down Expand Up @@ -80,14 +68,8 @@ describe("FileHandlerFileUploadStep", () => {

test("renders the CSV-specific text", async () => {
setup();
await waitFor(() =>
expect(screen.getByText("Upload CSV file")).toBeVisible(),
);
expect(
screen.getByText(
"Make sure your file has a .csv extension",
),
).toBeVisible();
await waitFor(() => expect(screen.getByText("Upload CSV file")).toBeVisible());
expect(screen.getByText("Make sure your file has a .csv extension")).toBeVisible();
});
});

Expand All @@ -109,16 +91,8 @@ describe("FileHandlerFileUploadStep", () => {

test("renders the HL7-specific text", async () => {
setup();
await waitFor(() =>
expect(
screen.getByText("Upload HL7 v2.5.1 file"),
).toBeVisible(),
);
expect(
screen.getByText(
"Make sure your file has a .hl7 extension",
),
).toBeVisible();
await waitFor(() => expect(screen.getByText("Upload HL7 v2.5.1 file")).toBeVisible());
expect(screen.getByText("Make sure your file has a .hl7 extension")).toBeVisible();
});
});

Expand All @@ -140,20 +114,14 @@ describe("FileHandlerFileUploadStep", () => {
);

await waitFor(async () => {
await userEvent.upload(
screen.getByTestId("file-input-input"),
fakeFile,
);
await userEvent.upload(screen.getByTestId("file-input-input"), fakeFile);
await new Promise((res) => setTimeout(res, 100));
});
}

test("calls onFileChange with the file and content", async () => {
await setup();
expect(onFileChangeSpy).toHaveBeenCalledWith(
fakeFile,
"foo,bar\r\nbar,foo",
);
expect(onFileChangeSpy).toHaveBeenCalledWith(fakeFile, "foo,bar\r\nbar,foo");
});
});

Expand Down Expand Up @@ -198,8 +166,7 @@ describe("FileHandlerFileUploadStep", () => {
vi.spyOn(useWatersUploaderExports, "default").mockReturnValue({
isPending: false,
error: null,
mutateAsync: async () =>
await Promise.resolve(mockSendValidFile),
mutateAsync: async () => await Promise.resolve(mockSendValidFile),
} as any);

renderApp(
Expand All @@ -214,12 +181,7 @@ describe("FileHandlerFileUploadStep", () => {
}}
fileContent="whatever"
fileName="whatever.csv"
file={
new File(
[new Blob(["whatever"])],
"whatever.csv",
)
}
file={new File([new Blob(["whatever"])], "whatever.csv")}
onFileSubmitSuccess={onFileSubmitSuccessSpy}
onNextStepClick={onNextStepClickSpy}
/>
Expand All @@ -234,9 +196,7 @@ describe("FileHandlerFileUploadStep", () => {
// eslint-disable-next-line testing-library/no-wait-for-side-effects
fireEvent.submit(form);
});
await waitFor(() =>
expect(onFileSubmitSuccessSpy).toHaveBeenCalled(),
);
await waitFor(() => expect(onFileSubmitSuccessSpy).toHaveBeenCalled());
}

afterEach(() => {
Expand All @@ -245,9 +205,7 @@ describe("FileHandlerFileUploadStep", () => {

test("it calls onFileSubmitSuccess with the response", async () => {
await setup();
expect(onFileSubmitSuccessSpy).toHaveBeenCalledWith(
mockSendValidFile,
);
expect(onFileSubmitSuccessSpy).toHaveBeenCalledWith(mockSendValidFile);
});

test("it calls onNextStepClick", async () => {
Expand Down Expand Up @@ -280,6 +238,7 @@ describe("FileHandlerFileUploadStep", () => {
isPending: false,
error: null,
mutateAsync: async () =>
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
await Promise.reject({
data: mockSendFileWithErrors,
}),
Expand All @@ -296,12 +255,7 @@ describe("FileHandlerFileUploadStep", () => {
}}
fileContent="whatever"
fileName="whatever.csv"
file={
new File(
[new Blob(["whatever"])],
"whatever.csv",
)
}
file={new File([new Blob(["whatever"])], "whatever.csv")}
onFileSubmitError={onFileSubmitErrorSpy}
/>
</Suspense>,
Expand All @@ -315,9 +269,7 @@ describe("FileHandlerFileUploadStep", () => {
// eslint-disable-next-line testing-library/no-wait-for-side-effects
fireEvent.submit(form);
});
await waitFor(() =>
expect(onFileSubmitErrorSpy).toHaveBeenCalled(),
);
await waitFor(() => expect(onFileSubmitErrorSpy).toHaveBeenCalled());
}

afterEach(() => {
Expand Down Expand Up @@ -373,84 +325,50 @@ describe("getClientHeader", () => {

describe("when selectedSchemaName is falsy", () => {
test("returns an empty string", () => {
expect(
getClientHeader(
undefined,
DEFAULT_ACTIVE_MEMBERSHIP,
DEFAULT_SENDER,
),
).toEqual("");
expect(getClientHeader(undefined, DEFAULT_ACTIVE_MEMBERSHIP, DEFAULT_SENDER)).toEqual("");
});
});

describe("when activeMembership is falsy", () => {
test("returns an empty string", () => {
expect(
getClientHeader(DEFAULT_SCHEMA_NAME, undefined, DEFAULT_SENDER),
).toEqual("");
expect(
getClientHeader(DEFAULT_SCHEMA_NAME, null, DEFAULT_SENDER),
).toEqual("");
expect(getClientHeader(DEFAULT_SCHEMA_NAME, undefined, DEFAULT_SENDER)).toEqual("");
expect(getClientHeader(DEFAULT_SCHEMA_NAME, null, DEFAULT_SENDER)).toEqual("");
});
});

describe("when sender is falsy", () => {
test("returns an empty string", () => {
expect(
getClientHeader(
DEFAULT_SCHEMA_NAME,
DEFAULT_ACTIVE_MEMBERSHIP,
undefined,
),
).toEqual("");
expect(getClientHeader(DEFAULT_SCHEMA_NAME, DEFAULT_ACTIVE_MEMBERSHIP, undefined)).toEqual("");
});
});

describe("when activeMembership.parsedName is falsy", () => {
test("returns an empty string", () => {
expect(
getClientHeader(
DEFAULT_SCHEMA_NAME,
{ ...DEFAULT_ACTIVE_MEMBERSHIP, parsedName: "" },
DEFAULT_SENDER,
),
getClientHeader(DEFAULT_SCHEMA_NAME, { ...DEFAULT_ACTIVE_MEMBERSHIP, parsedName: "" }, DEFAULT_SENDER),
).toEqual("");
});
});

describe("when activeMembership.service is falsy", () => {
test("returns an empty string", () => {
expect(
getClientHeader(
DEFAULT_SCHEMA_NAME,
{ ...DEFAULT_ACTIVE_MEMBERSHIP, service: "" },
DEFAULT_SENDER,
),
getClientHeader(DEFAULT_SCHEMA_NAME, { ...DEFAULT_ACTIVE_MEMBERSHIP, service: "" }, DEFAULT_SENDER),
).toEqual("");
});
});

describe("when selected schema value matches sender's schema", () => {
test("returns the client value from the organization's parsed name and service", () => {
expect(
getClientHeader(
DEFAULT_SCHEMA_NAME,
DEFAULT_ACTIVE_MEMBERSHIP,
DEFAULT_SENDER,
),
).toEqual("orgName.serviceName");
expect(getClientHeader(DEFAULT_SCHEMA_NAME, DEFAULT_ACTIVE_MEMBERSHIP, DEFAULT_SENDER)).toEqual(
"orgName.serviceName",
);
});
});

describe("when selected schema value does not match the sender's schema", () => {
test("returns an empty string", () => {
expect(
getClientHeader(
"bogus-schema",
DEFAULT_ACTIVE_MEMBERSHIP,
DEFAULT_SENDER,
),
).toEqual("");
expect(getClientHeader("bogus-schema", DEFAULT_ACTIVE_MEMBERSHIP, DEFAULT_SENDER)).toEqual("");
});
});
});
Loading

0 comments on commit 31b2d85

Please sign in to comment.