import custom_submittable_pagetype from "../fixtures/custom_submittable_pagetype";
const pagetype_name = custom_submittable_pagetype.name;

context("Report View", () => {
	before(() => {
		cy.login();
		cy.visit("/app/website");
		cy.insert_pg("PageType", custom_submittable_pagetype, true);
		cy.clear_cache();
		cy.insert_pg(
			pagetype_name,
			{
				title: "Pg 1",
				description: "Random Text",
				enabled: 0,
				pagestatus: 1, // submit document
			},
			true
		);
	});

	it("Field with enabled allow_on_submit should be editable.", () => {
		cy.intercept("POST", "api/action/jingrow.client.set_value").as("value-update");
		cy.visit(`/app/List/${pagetype_name}/Report`);

		// check status column added from pagestatus
		cy.get(".dt-row-0 > .dt-cell--col-3").should("contain", "Submitted");
		let cell = cy.get(".dt-row-0 > .dt-cell--col-4");

		// select the cell
		cell.dblclick();
		cell.get(".dt-cell__edit--col-4").findByRole("checkbox").check({ force: true });
		cy.get(".dt-row-0 > .dt-cell--col-3").click(); // click outside

		cy.wait("@value-update");

		cy.call("jingrow.client.get_value", {
			pagetype: pagetype_name,
			filters: {
				title: "Pg 1",
			},
			fieldname: "enabled",
		}).then((r) => {
			expect(r.message.enabled).to.equals(1);
		});
	});
});
