Skip to content

Commit

Permalink
Investigate more test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Etheryte committed Oct 3, 2024
1 parent c083a3a commit 2c828fa
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 166 deletions.
2 changes: 2 additions & 0 deletions web/html/src/components/input/InputBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ export class InputBase<ValueType = string> extends React.Component<InputBaseProp
}

this.props.onChange?.(name, value);
// TODO: Document
// this.forceUpdate();
};

pushHint(hints: React.ReactNode[], hint?: React.ReactNode) {
Expand Down
3 changes: 2 additions & 1 deletion web/html/src/components/input/check/Check.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function Check(props: Props) {
<InputBase {...propsToPass}>
{({ setValue, onBlur }) => {
const setChecked = (event: any) => {
setValue(event.target.name, event.target.checked);
console.log("setChecked", event.target.name, event.target.checked);
setValue(props.name, event.target.checked);
};
const fieldValue = (formContext.model || {})[props.name] || props.defaultValue || "";
return (
Expand Down
3 changes: 3 additions & 0 deletions web/html/src/components/input/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export class Form extends React.Component<Props> {
inputs: { [key: string]: InputBaseRef | undefined } = {};

setModelValue = (name: string, value: any) => {
if (name === "ipv6-enabled") {
debugger;
}
/**
* NB! This is incorrect, but a lot of other code relies on this bug so we can't change it.
* We modify the object directly, as opposed to creating a new interface, which means React doesn't know changes have occurred.
Expand Down
284 changes: 142 additions & 142 deletions web/html/src/manager/virtualization/nets/network-properties.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,152 +116,152 @@ describe("Rendering", () => {
click(screen.getByText("Submit"));
});

// test("Create network with all addressing fields", async (done) => {
// onSubmit = ({ definition }) => {
// expect(definition).toStrictEqual({
// type: "open",
// bridge: "virbr2",
// name: "open0",
// domain: "tf.local",
// ipv4: {
// address: "192.168.10.0",
// prefix: 24,
// dhcpranges: [
// { start: "192.168.10.10", end: "192.168.10.20" },
// { start: "192.168.10.110", end: "192.168.10.120" },
// ],
// hosts: [
// { mac: "2A:C3:A7:A6:01:00", name: "dev-srv", ip: "192.168.10.2" },
// { mac: "2A:C3:A7:A6:01:01", ip: "192.168.10.3" },
// ],
// bootpfile: "pxelinux.0",
// bootpserver: "192.168.10.2",
// tftp: "/path/to/tftproot",
// },
// ipv6: {
// address: "2001:db8:ac10:fd01::",
// prefix: 64,
// dhcpranges: [{ start: "2001:db8:ac10:fd01::10", end: "2001:db8:ac10:fd01::20" }],
// hosts: [{ id: "0:3:0:1:0:16:3e:11:22:33", name: "peter.xyz", ip: "2001:db8:ac10:fd01::2" }],
// },
// dns: {
// hosts: [{ address: "192.168.10.1", names: ["host", "gateway"] }],
// srvs: [
// {
// name: "srv1",
// protocol: "tcp",
// domain: "test-domain-name.com",
// target: "test.example.com",
// port: 1111,
// priority: 11,
// weight: 111,
// },
// {
// name: "srv2",
// protocol: "udp",
// },
// ],
// txts: [
// { name: "example", value: "foo" },
// { name: "bar", value: "other value" },
// ],
// forwarders: [
// { address: "8.8.4.4" },
// { address: "192.168.1.1", domain: "example.com" },
// { domain: "acme.com" },
// ],
// },
// });
// done();
// };
test("Create network with all addressing fields", async (done) => {
onSubmit = ({ definition }) => {
expect(definition).toStrictEqual({
type: "open",
bridge: "virbr2",
name: "open0",
domain: "tf.local",
ipv4: {
address: "192.168.10.0",
prefix: 24,
dhcpranges: [
{ start: "192.168.10.10", end: "192.168.10.20" },
{ start: "192.168.10.110", end: "192.168.10.120" },
],
hosts: [
{ mac: "2A:C3:A7:A6:01:00", name: "dev-srv", ip: "192.168.10.2" },
{ mac: "2A:C3:A7:A6:01:01", ip: "192.168.10.3" },
],
bootpfile: "pxelinux.0",
bootpserver: "192.168.10.2",
tftp: "/path/to/tftproot",
},
ipv6: {
address: "2001:db8:ac10:fd01::",
prefix: 64,
dhcpranges: [{ start: "2001:db8:ac10:fd01::10", end: "2001:db8:ac10:fd01::20" }],
hosts: [{ id: "0:3:0:1:0:16:3e:11:22:33", name: "peter.xyz", ip: "2001:db8:ac10:fd01::2" }],
},
dns: {
hosts: [{ address: "192.168.10.1", names: ["host", "gateway"] }],
srvs: [
{
name: "srv1",
protocol: "tcp",
domain: "test-domain-name.com",
target: "test.example.com",
port: 1111,
priority: 11,
weight: 111,
},
{
name: "srv2",
protocol: "udp",
},
],
txts: [
{ name: "example", value: "foo" },
{ name: "bar", value: "other value" },
],
forwarders: [
{ address: "8.8.4.4" },
{ address: "192.168.1.1", domain: "example.com" },
{ domain: "acme.com" },
],
},
});
done();
};

// await renderWithNetwork();
// await select(screen.getByLabelText("Network type"), "open");
// await type(screen.getByLabelText("Name"), "open0");
// await type(screen.getByLabelText("Bridge"), "virbr2");
// await type(screen.getByLabelText("Domain name"), "tf.local");

// // IPv4 fields setting
// const ipv4_address = await screen.findByTitle("IPv4 Network address");
// await type(ipv4_address, "192.168.10.0");
// await type(screen.getByTitle("IPv4 Network address prefix"), "24");

// click(screen.getByTitle("Add DHCP Ranges"));
// const dhcp0_start = await screen.findByTitle("DHCP address range 0 start");
// await type(dhcp0_start, "192.168.10.10");
// await type(screen.getByTitle("DHCP address range 0 end"), "192.168.10.20");
// click(screen.getByTitle("Add DHCP Ranges"));
// const dhcp1_start = await screen.findByTitle("DHCP address range 1 start");
// await type(dhcp1_start, "192.168.10.110");
// await type(screen.getByTitle("DHCP address range 1 end"), "192.168.10.120");
// click(screen.getByTitle("Add DHCP Hosts"));
// const dhcp0_host = await screen.findByTitle("DHCP host 0 address");
// await type(dhcp0_host, "192.168.10.2");
// await type(screen.getByTitle("DHCP host 0 MAC address"), "2A:C3:A7:A6:01:00");
// await type(screen.getByTitle("DHCP host 0 name"), "dev-srv");
// click(screen.getByTitle("Add DHCP Hosts"));
// const dhcp1_host = await screen.findByTitle("DHCP host 1 address");
// await type(dhcp1_host, "192.168.10.3");
// await type(screen.getByTitle("DHCP host 1 MAC address"), "2A:C3:A7:A6:01:01");
// await type(screen.getByLabelText("BOOTP image file"), "pxelinux.0");
// await type(screen.getByLabelText("BOOTP server"), "192.168.10.2");
// await type(screen.getByLabelText("TFTP root path"), "/path/to/tftproot");
await renderWithNetwork();
await select(screen.getByLabelText("Network type"), "open");
await type(screen.getByLabelText("Name"), "open0");
await type(screen.getByLabelText("Bridge"), "virbr2");
await type(screen.getByLabelText("Domain name"), "tf.local");

// // IPv6 fields checks
// click(screen.getByText("Enable IPv6"));
// const ipv6_address = await screen.findByTitle("IPv6 Network address");
// await type(ipv6_address, "2001:db8:ac10:fd01::");
// await type(screen.getByRole("textbox", { name: "IPv6 Network address prefix" }), "64");
// click(screen.getByTitle("Add DHCPv6 Ranges"));
// const dhcpv6_range0 = await screen.findByTitle("DHCPv6 address range 0 start");
// await type(dhcpv6_range0, "2001:db8:ac10:fd01::10");
// await type(screen.getByTitle("DHCPv6 address range 0 end"), "2001:db8:ac10:fd01::20");
// click(screen.getByTitle("Add DHCPv6 Hosts"));
// const dhcpv6_host0 = await screen.findByTitle("DHCPv6 host 0 address");
// await type(dhcpv6_host0, "2001:db8:ac10:fd01::2");
// await type(screen.getByTitle("DHCPv6 host 0 DUID"), "0:3:0:1:0:16:3e:11:22:33");
// await type(screen.getByTitle("DHCPv6 host 0 name"), "peter.xyz");
// IPv4 fields setting
const ipv4_address = await screen.findByTitle("IPv4 Network address");
await type(ipv4_address, "192.168.10.0");
await type(screen.getByTitle("IPv4 Network address prefix"), "24");

// // DNS fields checks
// click(screen.getByTitle("Add Forwarders"));
// const fwd0 = await screen.findByTitle("DNS forwarder 0 address");
// await type(fwd0, "8.8.4.4");
// click(screen.getByTitle("Add Forwarders"));
// const fwd1 = await screen.findByTitle("DNS forwarder 1 domain name");
// await type(fwd1, "example.com");
// await type(screen.getByTitle("DNS forwarder 1 address"), "192.168.1.1");
// click(screen.getByTitle("Add Forwarders"));
// const fwd2 = await screen.findByTitle("DNS forwarder 2 domain name");
// await type(fwd2, "acme.com");
// click(screen.getByTitle("Add Hosts"));
// const dns_host0 = await screen.findByTitle("DNS host 0 names");
// await type(dns_host0, "host,gateway");
// await type(screen.getByTitle("DNS host 0 address"), "192.168.10.1");
// click(screen.getByTitle("Add SRV records"));
// const srv0 = await screen.findByTitle("DNS SRV record 0 service");
// await type(srv0, "srv1");
// await select(screen.getByLabelText("DNS SRV record 0 protocol"), "TCP");
// await type(screen.getByTitle("DNS SRV record 0 domain name"), "test-domain-name.com");
// await type(screen.getByTitle("DNS SRV record 0 target hostname"), "test.example.com");
// await type(screen.getByTitle("DNS SRV record 0 port"), "1111");
// await type(screen.getByTitle("DNS SRV record 0 priority"), "11");
// await type(screen.getByTitle("DNS SRV record 0 weight"), "111");
// click(screen.getByTitle("Add SRV records"));
// const srv1 = await screen.findByTitle("DNS SRV record 1 service");
// await type(srv1, "srv2");
// await select(screen.getByLabelText("DNS SRV record 1 protocol"), "UDP");
// click(screen.getByTitle("Add TXT records"));
// const txt0 = await screen.findByTitle("DNS TXT record 0 name");
// await type(txt0, "example");
// await type(screen.getByTitle("DNS TXT record 0 value"), "foo");
// click(screen.getByTitle("Add TXT records"));
// const txt1 = await screen.findByTitle("DNS TXT record 1 name");
// await type(txt1, "bar");
// await type(screen.getByTitle("DNS TXT record 1 value"), "other value");
click(screen.getByTitle("Add DHCP Ranges"));
const dhcp0_start = await screen.findByTitle("DHCP address range 0 start");
await type(dhcp0_start, "192.168.10.10");
await type(screen.getByTitle("DHCP address range 0 end"), "192.168.10.20");
click(screen.getByTitle("Add DHCP Ranges"));
const dhcp1_start = await screen.findByTitle("DHCP address range 1 start");
await type(dhcp1_start, "192.168.10.110");
await type(screen.getByTitle("DHCP address range 1 end"), "192.168.10.120");
click(screen.getByTitle("Add DHCP Hosts"));
const dhcp0_host = await screen.findByTitle("DHCP host 0 address");
await type(dhcp0_host, "192.168.10.2");
await type(screen.getByTitle("DHCP host 0 MAC address"), "2A:C3:A7:A6:01:00");
await type(screen.getByTitle("DHCP host 0 name"), "dev-srv");
click(screen.getByTitle("Add DHCP Hosts"));
const dhcp1_host = await screen.findByTitle("DHCP host 1 address");
await type(dhcp1_host, "192.168.10.3");
await type(screen.getByTitle("DHCP host 1 MAC address"), "2A:C3:A7:A6:01:01");
await type(screen.getByLabelText("BOOTP image file"), "pxelinux.0");
await type(screen.getByLabelText("BOOTP server"), "192.168.10.2");
await type(screen.getByLabelText("TFTP root path"), "/path/to/tftproot");

// IPv6 fields checks
click(screen.getByText("Enable IPv6"));
const ipv6_address = await screen.findByTitle("IPv6 Network address");
await type(ipv6_address, "2001:db8:ac10:fd01::");
await type(screen.getByRole("textbox", { name: "IPv6 Network address prefix" }), "64");
click(screen.getByTitle("Add DHCPv6 Ranges"));
const dhcpv6_range0 = await screen.findByTitle("DHCPv6 address range 0 start");
await type(dhcpv6_range0, "2001:db8:ac10:fd01::10");
await type(screen.getByTitle("DHCPv6 address range 0 end"), "2001:db8:ac10:fd01::20");
click(screen.getByTitle("Add DHCPv6 Hosts"));
const dhcpv6_host0 = await screen.findByTitle("DHCPv6 host 0 address");
await type(dhcpv6_host0, "2001:db8:ac10:fd01::2");
await type(screen.getByTitle("DHCPv6 host 0 DUID"), "0:3:0:1:0:16:3e:11:22:33");
await type(screen.getByTitle("DHCPv6 host 0 name"), "peter.xyz");

// DNS fields checks
click(screen.getByTitle("Add Forwarders"));
const fwd0 = await screen.findByTitle("DNS forwarder 0 address");
await type(fwd0, "8.8.4.4");
click(screen.getByTitle("Add Forwarders"));
const fwd1 = await screen.findByTitle("DNS forwarder 1 domain name");
await type(fwd1, "example.com");
await type(screen.getByTitle("DNS forwarder 1 address"), "192.168.1.1");
click(screen.getByTitle("Add Forwarders"));
const fwd2 = await screen.findByTitle("DNS forwarder 2 domain name");
await type(fwd2, "acme.com");
click(screen.getByTitle("Add Hosts"));
const dns_host0 = await screen.findByTitle("DNS host 0 names");
await type(dns_host0, "host,gateway");
await type(screen.getByTitle("DNS host 0 address"), "192.168.10.1");
click(screen.getByTitle("Add SRV records"));
const srv0 = await screen.findByTitle("DNS SRV record 0 service");
await type(srv0, "srv1");
await select(screen.getByLabelText("DNS SRV record 0 protocol"), "TCP");
await type(screen.getByTitle("DNS SRV record 0 domain name"), "test-domain-name.com");
await type(screen.getByTitle("DNS SRV record 0 target hostname"), "test.example.com");
await type(screen.getByTitle("DNS SRV record 0 port"), "1111");
await type(screen.getByTitle("DNS SRV record 0 priority"), "11");
await type(screen.getByTitle("DNS SRV record 0 weight"), "111");
click(screen.getByTitle("Add SRV records"));
const srv1 = await screen.findByTitle("DNS SRV record 1 service");
await type(srv1, "srv2");
await select(screen.getByLabelText("DNS SRV record 1 protocol"), "UDP");
click(screen.getByTitle("Add TXT records"));
const txt0 = await screen.findByTitle("DNS TXT record 0 name");
await type(txt0, "example");
await type(screen.getByTitle("DNS TXT record 0 value"), "foo");
click(screen.getByTitle("Add TXT records"));
const txt1 = await screen.findByTitle("DNS TXT record 1 name");
await type(txt1, "bar");
await type(screen.getByTitle("DNS TXT record 1 value"), "other value");

// expect(screen.getByText<HTMLButtonElement>("Submit").disabled).toBeFalsy();
// click(screen.getByText("Submit"));
// });
expect(screen.getByText<HTMLButtonElement>("Submit").disabled).toBeFalsy();
click(screen.getByText("Submit"));
});

// test("Create openVSwitch bridge network", async (done) => {
// onSubmit = ({ definition }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export function NetworkProperties(props: Props) {

const isInitialRender = React.useRef(true);
React.useEffect(() => {
console.log("override");
if (isInitialRender.current) {
isInitialRender.current = false;
return;
Expand All @@ -129,7 +130,6 @@ export function NetworkProperties(props: Props) {
}, [props.initialModel]);

const onValidate = (isValid: boolean) => {
console.log("onValidate", isValid);
setInvalid(!isValid);
};

Expand Down Expand Up @@ -204,6 +204,8 @@ export function NetworkProperties(props: Props) {
label: FieldsData.getValue(value, "label", value),
}));

console.log(model);

return (
<VirtualizationNetworkDevsApi hostId={props.serverId}>
{({ netDevices, messages: netDevicesError }) => {
Expand Down Expand Up @@ -455,6 +457,7 @@ export function NetworkProperties(props: Props) {
<Panel key="addressing" title={t("Addressing")} headingLevel="h2">
<IpConfig />
<Check name="ipv6-enabled" label={t("Enable IPv6")} divClass="col-md-6 col-md-offset-3 offset-md-3" />
{model["ipv6-enabled"] ? "true" : "false"}
{model["ipv6-enabled"] && <IpConfig ipv6 />}
<Text name="domain" label={t("Domain name")} labelClass="col-md-3" divClass="col-md-6" />
<DnsConfig />
Expand Down
Loading

0 comments on commit 2c828fa

Please sign in to comment.