Skip to content
Open
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
2 changes: 1 addition & 1 deletion Anlab.Mvc/AnlabMvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<SpaRoot>ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
<UserSecretsId>f3c999a5-2304-44e0-a49e-f43333bf9ccf</UserSecretsId>
<Version>2.0.3.2</Version>
<Version>2.0.3.3</Version>
<Description>Order and results management system for AnLab@UCDavis</Description>
<TypeScriptToolsVersion>2.3</TypeScriptToolsVersion>
</PropertyGroup>
Expand Down
16 changes: 10 additions & 6 deletions Anlab.Mvc/ClientApp/src/components/OrderForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SampleDisposition } from "./SampleDisposition";
import { IPayment, PaymentSelection } from "./PaymentSelection";
import { IOtherPaymentInfo } from "./OtherPaymentQuestions";
import { Project } from "./Project";
import { Quantity } from "./Quantity";
import { ORDER_QUANTITY_MAX, Quantity } from "./Quantity";
import {
ISampleTypeQuestions,
SampleTypeQuestions,
Expand Down Expand Up @@ -401,7 +401,7 @@ export default class OrderForm extends React.Component<
}
/>
<Input
label="Client Provided ID (CDFA Only)"
label="Client Provided Id"
value={clientProvidedId}
maxLength={6}
onChange={(e) =>
Expand Down Expand Up @@ -474,8 +474,9 @@ export default class OrderForm extends React.Component<
How many samples will you be submitting?
</label>
<p className="help-block">
Note: 100 sample limit per work order. If submitting more than
100 sample please create additional work orders.
Note: {ORDER_QUANTITY_MAX} sample limit per work order. If
submitting more than {ORDER_QUANTITY_MAX} samples please
create additional work orders.
</p>
<p className="help-block">
Each sample container must be numbered consecutively beginning
Expand Down Expand Up @@ -640,7 +641,7 @@ export default class OrderForm extends React.Component<
}

// check quantity
if (this.state.quantity <= 0 || this.state.quantity > 100) {
if (this.state.quantity <= 0 || this.state.quantity > ORDER_QUANTITY_MAX) {
valid = false;
}

Expand Down Expand Up @@ -968,7 +969,10 @@ export default class OrderForm extends React.Component<
!this.state.sampleDisposition.trim()
) {
this._focusInput(this.sampleDispositionRef);
} else if (this.state.quantity <= 0 || this.state.quantity > 100) {
} else if (
this.state.quantity <= 0 ||
this.state.quantity > ORDER_QUANTITY_MAX
) {
this._focusInput(this.quantityRef);
} else if (
(this.state.sampleType === "Water" ||
Expand Down
28 changes: 15 additions & 13 deletions Anlab.Mvc/ClientApp/src/components/Quantity.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as React from "react";
import { IntegerInput } from "./ui/integerInput/integerInput";

interface IQuantityProps {
quantity?: number;
onQuantityChanged: (value: number) => void;
import * as React from "react";
import { IntegerInput } from "./ui/integerInput/integerInput";

export const ORDER_QUANTITY_MAX = 200;

interface IQuantityProps {
quantity?: number;
onQuantityChanged: (value: number) => void;
quantityRef: (element: HTMLInputElement) => void;
}

Expand All @@ -13,13 +15,13 @@ export class Quantity extends React.Component<IQuantityProps, {}> {
<IntegerInput
name="quantity"
label="Quantity"
value={this.props.quantity}
onChange={this.props.onQuantityChanged}
min={1}
max={100}
required={true}
inputRef={this.props.quantityRef}
/>
value={this.props.quantity}
onChange={this.props.onQuantityChanged}
min={1}
max={ORDER_QUANTITY_MAX}
required={true}
inputRef={this.props.quantityRef}
/>
);
}
}
75 changes: 60 additions & 15 deletions Anlab.Mvc/ClientApp/src/components/specs/Quantity.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import * as React from "react";
import { render, screen } from "@testing-library/react";

import { Quantity } from "../Quantity";

describe("<Quantity />", () => {
import * as React from "react";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

import { ORDER_QUANTITY_MAX, Quantity } from "../Quantity";

const QuantityHarness = () => {
const [quantity, setQuantity] = React.useState<number>();
return (
<Quantity
quantity={quantity}
onQuantityChanged={setQuantity}
quantityRef={() => {}}
/>
);
};

describe("<Quantity />", () => {
it("should render an IntegerInput", () => {
render(
<Quantity quantity={1} onQuantityChanged={null} quantityRef={null} />
);
expect(screen.getByRole("textbox")).toBeInTheDocument();
});

describe("properties", () => {
describe("properties", () => {
it("should have a max quantity of 200", () => {
expect(ORDER_QUANTITY_MAX).toBe(200);
});

it("should have a name", () => {
render(
<Quantity quantity={1} onQuantityChanged={null} quantityRef={null} />
Expand All @@ -31,11 +47,40 @@ describe("<Quantity />", () => {
);
expect(screen.getByRole("textbox")).toHaveAttribute("value", "33");
});
it("should have be required", () => {
render(
<Quantity quantity={33} onQuantityChanged={null} quantityRef={null} />
);
expect(screen.getByRole("textbox")).toHaveAttribute("required");
});
});
});
it("should have be required", () => {
render(
<Quantity quantity={33} onQuantityChanged={null} quantityRef={null} />
);
expect(screen.getByRole("textbox")).toHaveAttribute("required");
});

it("should allow 200 samples", async () => {
render(<QuantityHarness />);

const user = userEvent.setup();
await user.type(screen.getByRole("textbox"), String(ORDER_QUANTITY_MAX));

expect(
screen.queryByText(
`Must be a number less than or equal to ${ORDER_QUANTITY_MAX}.`
)
).not.toBeInTheDocument();
});

it("should reject more than 200 samples", async () => {
render(<QuantityHarness />);

const user = userEvent.setup();
await user.type(
screen.getByRole("textbox"),
String(ORDER_QUANTITY_MAX + 1)
);

expect(
screen.getByText(
`Must be a number less than or equal to ${ORDER_QUANTITY_MAX}.`
)
).toBeInTheDocument();
});
});
});
4 changes: 4 additions & 0 deletions Anlab.Mvc/ClientApp/src/css/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ table.table {
color: $unitrans-red;
}

.text-error {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is new, error message wasn't red. Maybe a hold over from the bootstrap update.

color: $unitrans-red;
}

.inline-block {
padding-left: 1em;
display: inline-block;
Expand Down
4 changes: 2 additions & 2 deletions Anlab.Mvc/Models/Order/OrderSaveModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class OrderSaveModel
{

public int? OrderId { get; set; }
[Range(1, 100)]
public int Quantity { get; set; }
[Range(1, 200)]
public int Quantity { get; set; }

[Required]
public string SampleType { get; set; }
Expand Down
Loading