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.

169 lines
5.8 KiB

  1. // Copyright 2004-2018 Odoo SA
  2. // Copyright 2018 Lambda IS DOOEL <https://www.lambda-is.com>
  3. // License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. odoo.define('pos_loyalty.tour.test_pos_loyalty', function(require) {
  5. "use strict";
  6. // Some of the steps are taken from the pos_basic_order tour in point_of_sale.
  7. // Added additional ones necessary for testing the rewards.
  8. var Tour = require("web_tour.tour");
  9. function add_customer(customer_name) {
  10. return [{
  11. content: 'open customer screen',
  12. trigger: '.button.set-customer',
  13. }, {
  14. content: 'choose customer ' + customer_name,
  15. trigger: 'table.client-list tbody.client-list-contents tr.client-line td:contains("' + customer_name + '")',
  16. }, {
  17. content: 'select customer ' + customer_name,
  18. trigger: '.button.next:contains("Set Customer")',
  19. }, {
  20. content: 'Check if customer ' + customer_name + ' is added',
  21. trigger: '.button.set-customer:contains("' + customer_name + '")',
  22. run: function() {}, // it's a check
  23. }];
  24. }
  25. function add_reward(reward_name) {
  26. return [{
  27. content: 'open rewards screen',
  28. trigger: '.control-button:contains("Rewards")',
  29. }, {
  30. content: 'choose reward',
  31. trigger: '.selection-item:contains("' + reward_name + '")',
  32. }]
  33. }
  34. function add_product_to_order(product_name) {
  35. return [{
  36. content: 'buy ' + product_name,
  37. trigger: '.product-list .product-name:contains("' + product_name + '")',
  38. }, {
  39. content: 'the ' + product_name + ' have been added to the order',
  40. trigger: '.order .product-name:contains("' + product_name + '")',
  41. run: function() {}, // it's a check
  42. }];
  43. }
  44. function verify_order_product(product_name) {
  45. return [{
  46. content: 'check if ' + product_name + ' is in order',
  47. trigger: '.orderline .product-name:contains("' + product_name + '")',
  48. run: function() {}, // it's a check
  49. }]
  50. }
  51. function generate_keypad_steps(amount_str, keypad_selector) {
  52. var i, steps = [],
  53. current_char;
  54. for (i = 0; i < amount_str.length; ++i) {
  55. current_char = amount_str[i];
  56. steps.push({
  57. content: 'press ' + current_char + ' on payment keypad',
  58. trigger: keypad_selector + ' .input-button:contains("' + current_char + '"):visible'
  59. });
  60. }
  61. return steps;
  62. }
  63. function generate_payment_screen_keypad_steps(amount_str) {
  64. return generate_keypad_steps(amount_str, '.payment-numpad');
  65. }
  66. function generate_product_screen_keypad_steps(amount_str) {
  67. return generate_keypad_steps(amount_str, '.numpad');
  68. }
  69. function verify_order_total(total_str) {
  70. return [{
  71. content: 'order total contains ' + total_str,
  72. trigger: '.order .total .value:contains("' + total_str + '")',
  73. run: function() {}, // it's a check
  74. }];
  75. }
  76. function goto_payment_screen_and_select_payment_method() {
  77. return [{
  78. content: "go to payment screen",
  79. trigger: '.button.pay',
  80. }, {
  81. content: "pay with cash",
  82. trigger: '.paymentmethod:contains("Cash")',
  83. }];
  84. }
  85. function finish_order() {
  86. return [{
  87. content: "validate the order",
  88. trigger: '.button.next:visible',
  89. }, {
  90. content: "verify that the order is being sent to the backend",
  91. trigger: ".js_connecting:visible",
  92. run: function() {}, // it's a check
  93. }, {
  94. content: "verify that the order has been succesfully sent to the backend",
  95. trigger: ".js_connected:visible",
  96. run: function() {}, // it's a check
  97. }, {
  98. content: "next order",
  99. trigger: '.button.next:visible',
  100. }];
  101. }
  102. var steps = [{
  103. content: 'waiting for loading to finish',
  104. trigger: '.o_main_content:has(.loader:hidden)',
  105. run: function() {}, // it's a check
  106. }];
  107. steps = steps.concat(add_customer('Agrolait'));
  108. steps = steps.concat(add_product_to_order('Peaches'));
  109. steps = steps.concat(verify_order_total('5.10'));
  110. steps = steps.concat(add_product_to_order('Peaches')); // buy another kg of peaches
  111. steps = steps.concat(verify_order_total('10.20'));
  112. steps = steps.concat(goto_payment_screen_and_select_payment_method());
  113. steps = steps.concat(generate_payment_screen_keypad_steps("12.20"));
  114. steps = steps.concat([{
  115. content: "verify tendered",
  116. trigger: '.col-tendered:contains("12.20")',
  117. run: function() {}, // it's a check
  118. }, {
  119. content: "verify change",
  120. trigger: '.col-change:contains("2.00")',
  121. run: function() {}, // it's a check
  122. }]);
  123. steps = steps.concat(finish_order());
  124. Tour.register('test_pos_loyalty_acquire_points', {
  125. test: true,
  126. url: '/pos/web'
  127. }, steps);
  128. steps = [{
  129. content: 'waiting for loading to finish',
  130. trigger: '.o_main_content:has(.loader:hidden)',
  131. run: function() {}, // it's a check
  132. }];
  133. steps = steps.concat(add_customer('Agrolait'));
  134. steps = steps.concat(add_reward('Free Peaches'));
  135. steps = steps.concat(verify_order_product('Peaches'));
  136. steps = steps.concat(verify_order_total('0.00'));
  137. steps = steps.concat(goto_payment_screen_and_select_payment_method());
  138. steps = steps.concat([{
  139. content: "verify tendered",
  140. trigger: '.col-tendered:contains("0.00")',
  141. run: function() {}, // it's a check
  142. }]);
  143. steps = steps.concat(finish_order());
  144. Tour.register('test_pos_loyalty_spend_points', {
  145. test: true,
  146. url: '/pos/web'
  147. }, steps);
  148. })