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.
 
 
 
 
 
 

127 regels
3.4 KiB

  1. import datetime_doctype from "../fixtures/datetime_doctype";
  2. const doctype_name = datetime_doctype.name;
  3. context("Control Date, Time and DateTime", () => {
  4. before(() => {
  5. cy.login();
  6. cy.visit("/app/website");
  7. return cy.insert_doc("DocType", datetime_doctype, true);
  8. });
  9. describe("Date formats", () => {
  10. let date_formats = [
  11. {
  12. date_format: "dd-mm-yyyy",
  13. part: 2,
  14. length: 4,
  15. separator: "-",
  16. },
  17. {
  18. date_format: "mm/dd/yyyy",
  19. part: 0,
  20. length: 2,
  21. separator: "/",
  22. },
  23. ];
  24. date_formats.forEach((d) => {
  25. it("test date format " + d.date_format, () => {
  26. cy.set_value("System Settings", "System Settings", {
  27. date_format: d.date_format,
  28. });
  29. cy.window()
  30. .its("xhiveframework")
  31. .then((xhiveframework) => {
  32. // update sys_defaults value to avoid a reload
  33. xhiveframework.sys_defaults.date_format = d.date_format;
  34. });
  35. cy.new_form(doctype_name);
  36. cy.get(".form-control[data-fieldname=date]").focus();
  37. cy.get(".datepickers-container .datepicker.active").should("be.visible");
  38. cy.get(
  39. ".datepickers-container .datepicker.active .datepicker--cell-day.-current-"
  40. ).click({ force: true });
  41. cy.window()
  42. .its("cur_frm")
  43. .then((cur_frm) => {
  44. let formatted_value = cur_frm.get_field("date").input.value;
  45. let parts = formatted_value.split(d.separator);
  46. expect(parts[d.part].length).to.equal(d.length);
  47. });
  48. });
  49. });
  50. });
  51. describe("Time formats", () => {
  52. let time_formats = [
  53. {
  54. time_format: "HH:mm:ss",
  55. value: " 11:00:12",
  56. match_value: "11:00:12",
  57. },
  58. {
  59. time_format: "HH:mm",
  60. value: " 11:00:12",
  61. match_value: "11:00",
  62. },
  63. ];
  64. time_formats.forEach((d) => {
  65. it("test time format " + d.time_format, () => {
  66. cy.set_value("System Settings", "System Settings", {
  67. time_format: d.time_format,
  68. });
  69. cy.window()
  70. .its("xhiveframework")
  71. .then((xhiveframework) => {
  72. xhiveframework.sys_defaults.time_format = d.time_format;
  73. });
  74. cy.new_form(doctype_name);
  75. cy.fill_field("time", d.value, "Time").blur();
  76. cy.get_field("time").should("have.value", d.match_value);
  77. });
  78. });
  79. });
  80. describe("DateTime formats", () => {
  81. let datetime_formats = [
  82. {
  83. date_format: "dd.mm.yyyy",
  84. time_format: "HH:mm:ss",
  85. value: " 02.12.2019 11:00:12",
  86. doc_value: "2019-12-02 00:30:12", // system timezone (America/New_York)
  87. input_value: "02.12.2019 11:00:12", // admin timezone (Asia/Kolkata)
  88. },
  89. {
  90. date_format: "mm-dd-yyyy",
  91. time_format: "HH:mm",
  92. value: " 12-02-2019 11:00:00",
  93. doc_value: "2019-12-02 00:30:00", // system timezone (America/New_York)
  94. input_value: "12-02-2019 11:00", // admin timezone (Asia/Kolkata)
  95. },
  96. ];
  97. datetime_formats.forEach((d) => {
  98. it(`test datetime format ${d.date_format} ${d.time_format}`, () => {
  99. cy.set_value("System Settings", "System Settings", {
  100. date_format: d.date_format,
  101. time_format: d.time_format,
  102. });
  103. cy.window()
  104. .its("xhiveframework")
  105. .then((xhiveframework) => {
  106. xhiveframework.sys_defaults.date_format = d.date_format;
  107. xhiveframework.sys_defaults.time_format = d.time_format;
  108. });
  109. cy.new_form(doctype_name);
  110. cy.fill_field("datetime", d.value, "Datetime").blur();
  111. cy.get_field("datetime").should("have.value", d.input_value);
  112. cy.window().its("cur_frm.doc.datetime").should("eq", d.doc_value);
  113. });
  114. });
  115. });
  116. });