371 lines
12 KiB
TypeScript
371 lines
12 KiB
TypeScript
import { shallow } from "enzyme";
|
|
import React from "react";
|
|
import AsyncState from "../../../shared/enumerations/AsyncState";
|
|
import AdminAuctionHouseFormContainer from "./AdminAuctionHouseFormContainer";
|
|
describe("AdminAuctionHouses Container", () => {
|
|
let wrapper: any;
|
|
|
|
beforeEach(()=>{
|
|
wrapper = shallow(
|
|
<AdminAuctionHouseFormContainer
|
|
auctionHouses={
|
|
[{
|
|
auctionID: "10101",
|
|
name: "Test",
|
|
active: "yes",
|
|
address_Line_1: "1010 1st St.",
|
|
address_Line_2: "",
|
|
city: "New York",
|
|
state: "NY",
|
|
zip: 51112,
|
|
country: "USA",
|
|
phone: "14141414",
|
|
fax: "14141414",
|
|
}]
|
|
}
|
|
postedAuctionHouse={{
|
|
state: AsyncState.Inactive
|
|
|
|
}}
|
|
isCollapsed={true}
|
|
newAuctionHouseSubmit={()=>{}}
|
|
clearSelectedAuction={()=>{}}
|
|
updateAuctionHouseSubmit={()=>{}}
|
|
auctionHouseToUpdate={undefined}
|
|
/>
|
|
);
|
|
});
|
|
|
|
|
|
it("Shows the post form when not collapsed and no auction to update", () => {
|
|
wrapper.setProps({
|
|
isCollapsed: false
|
|
})
|
|
wrapper.update();
|
|
const form = wrapper.find(`[data-test='post-form']`);
|
|
expect(form.length).toBe(1);
|
|
});
|
|
|
|
it("Shows the put form when not collapsed and has auction to update", () => {
|
|
wrapper.setProps({
|
|
isCollapsed: false,
|
|
auctionHouseToUpdate:{
|
|
auctionID: "55555",
|
|
name: "Test",
|
|
active: "Test",
|
|
address_Line_1: "Test",
|
|
address_Line_2: "",
|
|
city: "Test",
|
|
state: "WI",
|
|
zip: 200202,
|
|
country: "Test",
|
|
phone: "10101010101",
|
|
fax: "10101010101",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
}
|
|
})
|
|
wrapper.update();
|
|
const form = wrapper.find(`[data-test='put-form']`);
|
|
expect(form.length).toBe(1);
|
|
});
|
|
|
|
it("Doesnt Show Forms When Collapsed", () => {
|
|
const tempWrapper = wrapper.setProps({
|
|
isCollapsed: true
|
|
});
|
|
tempWrapper.update();
|
|
const form = tempWrapper.find(`[data-test='post-form']`);
|
|
expect(form.length).toBe(0);
|
|
});
|
|
|
|
it("Shows Validation Error For Auction ID", () => {
|
|
wrapper.setState({
|
|
auctionHouseDetails: {
|
|
auctionID: "10101",
|
|
name: "",
|
|
active: "",
|
|
address_Line_1: "",
|
|
address_Line_2: "",
|
|
city: "",
|
|
state: "",
|
|
zip: -1,
|
|
country: "",
|
|
phone: "",
|
|
fax: "",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
},
|
|
});
|
|
wrapper.setProps({
|
|
isCollapsed: false
|
|
})
|
|
wrapper.setState({
|
|
showValidationError: false
|
|
});
|
|
const postFormSubmit : Function = wrapper.find(`[data-test='post-form']`).prop("onSubmit");
|
|
postFormSubmit();
|
|
expect(wrapper.state("showValidationError")).toBe(true);
|
|
});
|
|
|
|
it("Shows Validation Error For Auction ID", () => {
|
|
wrapper.setState({
|
|
auctionHouseDetails: {
|
|
auctionID: "10101",
|
|
name: "",
|
|
active: "",
|
|
address_Line_1: "",
|
|
address_Line_2: "",
|
|
city: "",
|
|
state: "",
|
|
zip: -1,
|
|
country: "",
|
|
phone: "",
|
|
fax: "",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
},
|
|
});
|
|
wrapper.setProps({
|
|
isCollapsed: false
|
|
})
|
|
wrapper.setState({
|
|
showValidationError: false
|
|
});
|
|
const postFormSubmit : Function = wrapper.find(`[data-test='post-form']`).prop("onSubmit");
|
|
postFormSubmit();
|
|
expect(wrapper.state("showValidationError")).toBe(true);
|
|
});
|
|
|
|
it("Shows Validation Error For Auction State", () => {
|
|
wrapper.setState({
|
|
auctionHouseDetails: {
|
|
auctionID: "11111",
|
|
name: "",
|
|
active: "",
|
|
address_Line_1: "",
|
|
address_Line_2: "",
|
|
city: "",
|
|
state: "WEEE",
|
|
zip: -1,
|
|
country: "",
|
|
phone: "",
|
|
fax: "",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
},
|
|
});
|
|
wrapper.setProps({
|
|
isCollapsed: false
|
|
})
|
|
wrapper.setState({
|
|
showValidationError: false
|
|
});
|
|
const postFormSubmit : Function = wrapper.find(`[data-test='post-form']`).prop("onSubmit");
|
|
postFormSubmit();
|
|
expect(wrapper.state("showValidationError")).toBe(true);
|
|
});
|
|
|
|
it("Displays Validation Error When Form Is Incomplete", () => {
|
|
wrapper.setState({
|
|
auctionHouseDetails: {
|
|
auctionID: "10101",
|
|
name: "",
|
|
active: "",
|
|
address_Line_1: "",
|
|
address_Line_2: "",
|
|
city: "",
|
|
state: "WEEE",
|
|
zip: -1,
|
|
country: "",
|
|
phone: "",
|
|
fax: "",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
},
|
|
});
|
|
wrapper.setProps({
|
|
isCollapsed: false
|
|
})
|
|
wrapper.setState({
|
|
showValidationError: false
|
|
});
|
|
const postFormSubmit : Function = wrapper.find(`[data-test='post-form']`).prop("onSubmit");
|
|
postFormSubmit();
|
|
expect(wrapper.state("showValidationError")).toBe(true);
|
|
});
|
|
|
|
it("Displays Validation Error When Form Has Validation Errors", () => {
|
|
wrapper.setState({
|
|
auctionHouseDetails: {
|
|
auctionID: "10101",
|
|
name: "Test",
|
|
active: "Test",
|
|
address_Line_1: "Test",
|
|
address_Line_2: "",
|
|
city: "Test",
|
|
state: "WEEE",
|
|
zip: 200202,
|
|
country: "Test",
|
|
phone: "10101010101",
|
|
fax: "10101010101",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
},
|
|
});
|
|
wrapper.setProps({
|
|
isCollapsed: false
|
|
})
|
|
wrapper.setState({
|
|
showValidationError: false
|
|
});
|
|
const postFormSubmit : Function = wrapper.find(`[data-test='post-form']`).prop("onSubmit");
|
|
postFormSubmit();
|
|
expect(wrapper.state("showValidationError")).toBe(true);
|
|
});
|
|
|
|
it("Does not have a validation notification when the form is complete and clears from", () => {
|
|
wrapper.setState({
|
|
auctionHouseDetails: {
|
|
auctionID: "55555",
|
|
name: "Test",
|
|
active: "Test",
|
|
address_Line_1: "Test",
|
|
address_Line_2: "",
|
|
city: "Test",
|
|
state: "WI",
|
|
zip: 200202,
|
|
country: "Test",
|
|
phone: "10101010101",
|
|
fax: "10101010101",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
},
|
|
});
|
|
wrapper.setProps({
|
|
isCollapsed: false
|
|
})
|
|
wrapper.setState({
|
|
showValidationError: false
|
|
});
|
|
const postFormSubmit : Function = wrapper.find(`[data-test='post-form']`).prop("onSubmit");
|
|
postFormSubmit();
|
|
expect(wrapper.state("showValidationError")).toBe(false);
|
|
expect(wrapper.state("auctionHouseDetails").auctionID).toBe("");
|
|
});
|
|
|
|
it("Displays Validation Error When Form Has Validation Errors", () => {
|
|
wrapper.setState({
|
|
auctionHouseDetails: {
|
|
auctionID: "10101",
|
|
name: "Test",
|
|
active: "Test",
|
|
address_Line_1: "Test",
|
|
address_Line_2: "",
|
|
city: "Test",
|
|
state: "WEEE",
|
|
zip: 200202,
|
|
country: "Test",
|
|
phone: "10101010101",
|
|
fax: "10101010101",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
},
|
|
});
|
|
wrapper.setProps({
|
|
isCollapsed: false
|
|
})
|
|
wrapper.setState({
|
|
showValidationError: false
|
|
});
|
|
const postFormSubmit : Function = wrapper.find(`[data-test='post-form']`).prop("onSubmit");
|
|
postFormSubmit();
|
|
expect(wrapper.state("showValidationError")).toBe(true);
|
|
});
|
|
|
|
it("Disables Update Submit if No Change Made", () => {
|
|
wrapper.setState({
|
|
auctionHouseDetails: {
|
|
auctionID: "55555",
|
|
name: "Test",
|
|
active: "Test",
|
|
address_Line_1: "Test",
|
|
address_Line_2: "",
|
|
city: "Test",
|
|
state: "WI",
|
|
zip: 200202,
|
|
country: "Test",
|
|
phone: "10101010101",
|
|
fax: "10101010101",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
},
|
|
});
|
|
wrapper.setProps({
|
|
isCollapsed: false,
|
|
auctionHouseToUpdate: {
|
|
auctionID: "55555",
|
|
name: "Test",
|
|
active: "Test",
|
|
address_Line_1: "Test",
|
|
address_Line_2: "",
|
|
city: "Test",
|
|
state: "WI",
|
|
zip: 200202,
|
|
country: "Test",
|
|
phone: "10101010101",
|
|
fax: "10101010101",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
}
|
|
})
|
|
wrapper.setState({
|
|
showValidationError: false
|
|
});
|
|
const submitDisabled : boolean = wrapper.find(`[data-test='put-form']`).prop("disableSubmitButton");
|
|
expect(submitDisabled).toBe(true);
|
|
});
|
|
|
|
it("Enables Update Submit When Change Made", () => {
|
|
wrapper.setState({
|
|
auctionHouseDetails: {
|
|
auctionID: "0000",
|
|
name: "Test",
|
|
active: "Test",
|
|
address_Line_1: "Test",
|
|
address_Line_2: "",
|
|
city: "Test",
|
|
state: "WI",
|
|
zip: 200202,
|
|
country: "Test",
|
|
phone: "10101010101",
|
|
fax: "10101010101",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
},
|
|
});
|
|
wrapper.setProps({
|
|
isCollapsed: false,
|
|
auctionHouseToUpdate: {
|
|
auctionID: "55555",
|
|
name: "Test",
|
|
active: "Test",
|
|
address_Line_1: "Test",
|
|
address_Line_2: "",
|
|
city: "Test",
|
|
state: "WI",
|
|
zip: 200202,
|
|
country: "Test",
|
|
phone: "10101010101",
|
|
fax: "10101010101",
|
|
latitude: undefined,
|
|
longitude: undefined
|
|
}
|
|
})
|
|
wrapper.setState({
|
|
showValidationError: false
|
|
});
|
|
const submitDisabled : boolean = wrapper.find(`[data-test='put-form']`).prop("disableSubmitButton");
|
|
expect(submitDisabled).toBe(false);
|
|
});
|
|
}); |