feat: setting for force web capture mode for camera uploads

This commit is contained in:
Dirk van der Laarse 2023-06-14 12:45:49 +00:00
parent 99ab17754b
commit 4ee5c015c3
3 changed files with 61 additions and 4 deletions

View file

@ -92,4 +92,49 @@ context("Attach Control", () => {
cy.get('.actions-btn-group > .dropdown-menu [data-label="Delete"]').click();
cy.click_modal_primary_button("Yes");
});
it('Checking that "Camera" button in the "Attach" fieldtype does show if camera is available', () => {
//Navigating to the new form for the newly created doctype
let doctype = "Test Attach Control"
let dt_in_route = doctype.toLowerCase().replace(/ /g, "-");
cy.visit(`/app/${dt_in_route}/new`, {
onBeforeLoad (win) {
// Mock "window.navigator.mediaDevices" property
// to return mock mediaDevices object
win.navigator.mediaDevices = {
ondevicechange: null
}
}
});
cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`);
cy.get("body").should("have.attr", "data-ajax-state", "complete");
//Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype
cy.findByRole("button", { name: "Attach" }).click();
//Clicking on "Camera" button
cy.findByRole("button", { name: "Camera" }).should("exist");
});
it('Checking that "Camera" button in the "Attach" fieldtype does not show if no camera is available', () => {
//Navigating to the new form for the newly created doctype
let doctype = "Test Attach Control"
let dt_in_route = doctype.toLowerCase().replace(/ /g, "-");
cy.visit(`/app/${dt_in_route}/new`, {
onBeforeLoad (win) {
// Delete "window.navigator.mediaDevices" property
delete win.navigator.mediaDevices
}
});
cy.get("body").should("have.attr", "data-route", `Form/${doctype}/new-${dt_in_route}-1`);
cy.get("body").should("have.attr", "data-ajax-state", "complete");
//Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype
cy.findByRole("button", { name: "Attach" }).click();
//Clicking on "Camera" button
cy.findByRole("button", { name: "Camera" }).should("not.exist");
});
});

View file

@ -563,12 +563,19 @@
"fieldtype": "Link",
"label": "Reset Password Template",
"options": "Email Template"
},
{
"default": "0",
"description": "When uploading files, force the use of the web-based image capture. If this is unchecked, the default behavior is to use the mobile native camera when use from a mobile is detected.",
"fieldname": "force_web_capture_mode_for_uploads",
"fieldtype": "Check",
"label": "Force web capture mode for uploads"
}
],
"icon": "fa fa-cog",
"issingle": 1,
"links": [],
"modified": "2023-05-25 13:02:54.808773",
"modified": "2023-06-14 11:19:33.429196",
"modified_by": "Administrator",
"module": "Core",
"name": "System Settings",

View file

@ -76,11 +76,16 @@ frappe.ui.Capture = class {
show() {
this.build_dialog();
if (frappe.is_mobile()) {
this.show_for_mobile();
} else {
if (frappe.boot.sysdefaults.force_web_capture_mode_for_uploads) {
this.show_for_desktop();
}
else {
if (frappe.is_mobile()) {
this.show_for_mobile();
} else {
this.show_for_desktop();
}
}
}
build_dialog() {