You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

multi_select_dialog.js 2.7 KiB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. context("MultiSelectDialog", () => {
  2. before(() => {
  3. cy.login();
  4. cy.visit("/app");
  5. const contact_template = {
  6. doctype: "Contact",
  7. first_name: "Test",
  8. status: "Passive",
  9. email_ids: [
  10. {
  11. doctype: "Contact Email",
  12. email_id: "test@example.com",
  13. is_primary: 0,
  14. },
  15. ],
  16. };
  17. const promises = Array.from({ length: 25 }).map(() =>
  18. cy.insert_doc("Contact", contact_template, true)
  19. );
  20. Promise.all(promises);
  21. });
  22. function open_multi_select_dialog() {
  23. cy.window()
  24. .its("xhiveframework")
  25. .then((xhiveframework) => {
  26. new xhiveframework.ui.form.MultiSelectDialog({
  27. doctype: "Contact",
  28. target: {},
  29. setters: {
  30. status: null,
  31. gender: null,
  32. },
  33. add_filters_group: 1,
  34. allow_child_item_selection: 1,
  35. child_fieldname: "email_ids",
  36. child_columns: ["email_id", "is_primary"],
  37. });
  38. });
  39. }
  40. it("checks multi select dialog api works", () => {
  41. open_multi_select_dialog();
  42. cy.get_open_dialog().should("contain", "Select Contacts");
  43. });
  44. it("checks for filters", () => {
  45. ["search_term", "status", "gender"].forEach((fieldname) => {
  46. cy.get_open_dialog()
  47. .get(`.xhiveframework-control[data-fieldname="${fieldname}"]`)
  48. .should("exist");
  49. });
  50. // add_filters_group: 1 should add a filter group
  51. cy.get_open_dialog().get(`.xhiveframework-control[data-fieldname="filter_area"]`).should("exist");
  52. });
  53. it("checks for child item selection", () => {
  54. cy.get_open_dialog().get(`.dt-row-header`).should("not.exist");
  55. cy.get_open_dialog()
  56. .get(`.xhiveframework-control[data-fieldname="allow_child_item_selection"]`)
  57. .find('input[data-fieldname="allow_child_item_selection"]')
  58. .should("exist")
  59. .click({ force: true });
  60. cy.get_open_dialog()
  61. .get(`.xhiveframework-control[data-fieldname="child_selection_area"]`)
  62. .should("exist");
  63. cy.get_open_dialog().get(`.dt-row-header`).should("contain", "Contact");
  64. cy.get_open_dialog().get(`.dt-row-header`).should("contain", "Email Id");
  65. cy.get_open_dialog().get(`.dt-row-header`).should("contain", "Is Primary");
  66. });
  67. it("tests more button", () => {
  68. cy.get_open_dialog()
  69. .get(`.xhiveframework-control[data-fieldname="more_child_btn"]`)
  70. .should("exist")
  71. .as("more-btn");
  72. cy.get_open_dialog()
  73. .get(".datatable .dt-scrollable .dt-row")
  74. .should(($rows) => {
  75. expect($rows).to.have.length(20);
  76. });
  77. cy.intercept("POST", "api/method/xhiveframework.client.get_list").as("get-more-records");
  78. cy.get("@more-btn").find("button").click({ force: true });
  79. cy.wait("@get-more-records");
  80. cy.get_open_dialog()
  81. .get(".datatable .dt-scrollable .dt-row")
  82. .should(($rows) => {
  83. if ($rows.length <= 20) {
  84. throw new Error("More button doesn't work");
  85. }
  86. });
  87. });
  88. });