Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.24 KB | None | 0 0
  1. const input = require('../input').input;
  2. const expect = require('chai').expect;
  3. const configureJsDom = require('../test-context').configureJsDom;
  4. const keyboard = input.keyboard;
  5. const Q = require('q');
  6.  
  7. describe('Made To Measure measurements form', function() {
  8.  
  9. beforeEach(() => configureJsDom({
  10. html: `<html>
  11. <body>
  12. <header class="header-site-wide"></header>
  13. <main class="m2m-standard-product-page-main">
  14. <div class="u-hidden m2m-product-info-drawer">
  15. <div class="m2m-product-info-drawer-back-link-container">
  16. <a class="m2m-product-info-drawer-back-link u-no-underline" href="#">Back to your roller blind</a>
  17. </div>
  18. <div class="m2m-product-info-drawer-title">
  19. <h1>Roller Blind with seven colors, Dark Egg</h1>
  20. </div>
  21. <div class="m2m-product-details-drawer">
  22. <section class="m2m-product-detail m2m-product-detail--info product-detail">
  23. <h2 class="product-detail__title">Product details</h2>
  24. <div class="m2m-product-detail__content m2m-product-detail__content--info product-detail__content">
  25. <ul>
  26. <li>Bright, contemporary design</li>
  27. <li>Soft and durable texture</li>
  28. <li>Child safe with breakaway system</li>
  29. <li>Simple to install</li>
  30. </ul>
  31. <p>This printed blind is a bright and breezy accent for your room. The fabric has been specially engineered to have a pleasingly soft testure to the touch. What's more, it's speedy to put in place and durable too</p>
  32. <p>This blind is operated with a side control mechanism by default. Alternatively, you can upgrade to a spring mechanism with a central cord pull (with acorn handle) if you prefer</p>
  33. <p>This blind can be fitted either inside or outside the window recess. Instructions and fittings are included</p>
  34. </div>
  35. </section>
  36. <section class="product-detail product-detail--specifications">
  37. <h2 class="product-detail__title">Product specifications</h2>
  38. </section>
  39. </div>
  40. </div>
  41. <div class="m2m-standard-product-container">
  42. <div class="m2m-standard-product-column-left">
  43. </div>
  44. <div class="m2m-standard-product-column-right">
  45. <div class="m2m-product-info-link">
  46. </div>
  47. <form class="m2m-measurements-form" action="/update-m2m" method="POST" id="m2m-measurements-form" novalidate="novalidate">
  48. <section class="m2m-swatch-list-section">
  49. <div class="m2m-swatch-hidden-submit" aria-hidden="true">
  50. <button class="button" type="submit" data-adding-to-basket="Adding..." id="button--add-to-basket" data-alert-text="Adding to basket">Get price</button>
  51. </div>
  52. <ul class="m2m-swatch-list">
  53. <li class="m2m-swatch-list-item">
  54. <button class="m2m-swatch m2m-swatch--current button" name="skuUrl" value="/roller-blind-with-seven-colors/dark-egg/p/33100015" type="submit">
  55. <img class="swatch-image swatch-image--current" src="//johnlewis.scene7.com/is/image/JohnLewis/002255341alt1?cropN=0.42105263157894735,0.42105263157894735,0.16842105263157894,0.16842105263157894&amp;$rsp-pdp-swtch$" alt="">
  56. <span class="swatch-text">Dark Egg
  57. </span>
  58. <span class="u-audible">This is the current selected colour</span>
  59. </button>
  60. </li>
  61. <li class="m2m-swatch-list-item">
  62. <button class="m2m-swatch button" name="skuUrl" value="/roller-blind-with-seven-colors/pale-lilac/p/33100015" type="submit">
  63. <img class="swatch-image" src="//johnlewis.scene7.com/is/image/JohnLewis/001147358alt1?cropN=0.42105263157894735,0.42105263157894735,0.16842105263157894,0.16842105263157894&amp;$rsp-pdp-swtch$" alt="">
  64. <span class="swatch-text">Pale Lilac
  65. </span>
  66. </button>
  67. </li>
  68. </ul>
  69. </section>
  70. <div class="m2m-measurements-inputs u-padding-default-left u-padding-default-right u-padding-section-top">
  71. <h2 class="u-padding-default-right">Add your measurements in centimetres (cm) to get a price</h2>
  72. <h3 id="recess-fitting-heading">1. Select a window fitting</h3>
  73. <a class="m2m-help-link m2m-help-link--window-fitting" href="#help-to-select-a-window-fitting" id="m2m-window-fitting-help-link">
  74. <span>Learn about window fittings</span>
  75. <span class="u-audible"> to help you measure your made to measure roller blinds</span>
  76. </a>
  77. <div class="m2m-recess">
  78. <div class="u-float-left m2m-inside-recess">
  79. <label class="label" for="m2m-inside-recess-btn">Inside recess</label>
  80. <label class="m2m-inside-recess-btn label">
  81. <input class="input" id="inside-recess" type="radio" name="recess" value="Inside recess" placeholder="Select inside recess" aria-label="select inside recess">
  82. <span></span>
  83. </label>
  84. </div>
  85. <div class="u-float-left m2m-outside-recess">
  86. <label class="label" for="m2m-outside-recess-btn">Outside recess</label>
  87. <label class="m2m-outside-recess-btn label">
  88. <input class="input" id="outside-recess" type="radio" name="recess" value="Outside recess" placeholder="Select ouside recess" aria-label="select outside recess">
  89. <span></span>
  90. </label>
  91. </div>
  92. <div class="u-hidden m2m-invalid-recess-error">
  93. <span class="u-audible">error select a window fitting</span>
  94. <span aria-hidden="true">Select a window fitting</span>
  95. </div>
  96. </div>
  97. <h3 class="u-heavy-text" id="enter-measurements-heading">2. Enter your measurements</h3>
  98. <a class="m2m-help-link m2m-help-link--measurements" href="#help-to-measure-roller-blind" id="m2m-measurements-help-link">
  99. <span>Learn how to measure correctly</span>
  100. <span class="u-audible"> your made to measure roller blinds</span>
  101. </a>
  102. <div class="m2m-width-container">
  103. <label class="label">Width</label>
  104. <input class="m2m-input-width" type="number" name="width" id="width" step="0.01" pattern="[0-9]+([/,|/.][0-9]+)?" value="" min="41" max="" required="" placeholder="e.g. 150.5" aria-label="width in centimeters" data-incomplete-message="please enter your measurements" autocorrect="off">
  105. <div class="m2m-cm">
  106. <p aria-hidden="true">(cm)</p>
  107. </div>
  108. <p class="m2m-min-width">
  109. <span class="m2m-min-width-text" aria-hidden="true">Min. 41 cm</span>
  110. <span class="m2m-min-width-aria u-audible">Minimum 41 centimeters</span>
  111. </p>
  112. </div>
  113. <div class="m2m-height-container">
  114. <label class="label">Height</label>
  115. <input class="m2m-input-height" type="number" name="height" id="height" step="0.01" pattern="[0-9]+([/,|/.][0-9]+)?" value="" min="40" max="" required="" placeholder="e.g. 165.2" aria-label="height in centimeters" data-incomplete-message="please enter your measurements" autocorrect="off">
  116. <div class="m2m-cm">
  117. <p aria-hidden="true">(cm)</p>
  118. </div>
  119. <p class="m2m-min-height">
  120. <span class="m2m-min-height-text" aria-hidden="true">Min. 40 cm</span>
  121. <span class="m2m-min-height-aria u-audible">Minimum 40 centimeters</span>
  122. </p>
  123. </div>
  124. <h3 class="u-heavy-text" id="installation-height-heading">3. Enter your installation height</h3>
  125. <a class="m2m-help-link m2m-help-link--installation-height" href="#help-to-measure-installation-height" id="m2m-installation-height-help-link">
  126. <span>What is the installation height?</span>
  127. </a>
  128. <div class="m2m-installation-height-container">
  129. <label class="label" for="installationHeight"></label>
  130. <input class="m2m-input-installation-height" type="number" name="installationHeight" id="installationHeight" step="0.01" pattern="[0-9]+([/,|/.][0-9]+)?" value="" required="" placeholder="e.g. 240.2" aria-label="installation height in centimeters" data-incomplete-message="please enter your measurements" autocorrect="off">
  131. <div class="m2m-cm">
  132. <p aria-hidden="true">(cm)</p>
  133. </div>
  134. </div>
  135. <h3 id="roll-direction-heading">4. Select which way you want your blind to be rolled</h3>
  136. <a class="m2m-help-link m2m-help-link--roll-direction" href="#help-to-select-a-roll-type" id="m2m-roll-direction-help-link">
  137. <span>What does roll type mean?</span>
  138. </a>
  139. <div class="m2m-roll-direction">
  140. <div class="u-float-left m2m-standard-roll">
  141. <label class="label" for="m2m-standard-roll-btn">Standard roll</label>
  142. <label class="m2m-standard-roll-btn label">
  143. <input class="input" id="standard-roll" type="radio" name="rollDirection" value="Standard" placeholder="Select standard roll" aria-label="select standard roll">
  144. <span></span>
  145. </label>
  146. </div>
  147. <div class="u-float-left m2m-reverse-roll">
  148. <label class="label" for="m2m-reverse-roll-btn">Reverse roll</label>
  149. <label class="m2m-reverse-roll-btn label">
  150. <input class="input" id="reverse-roll" type="radio" name="rollDirection" value="Reverse" placeholder="Select reverse roll" aria-label="select reverse roll">
  151. <span></span>
  152. </label>
  153. </div>
  154. <div class="u-hidden m2m-invalid-roll-direction-error">
  155. <span class="u-audible">error select a roll type</span>
  156. <span aria-hidden="true">Select a roll type</span>
  157. </div>
  158. </div>
  159. </div>
  160. <div class="m2m-check-measurements">
  161. <p>Please double check your measurements, as we custom make every blind.</p>
  162. </div>
  163. <div class="m2m-summary-and-cta">
  164. <p>Roller Blind with seven colors, Dark Egg</p>
  165. <div class="m2m-add-to-basket-item-details">
  166. <p class="m2m-price-from">Blind price from
  167. </p>
  168. <p class="u-semibold-text">£68.48</p>
  169. <p></p>
  170. <p class="price-included-additional-services u-hidden price u-centred">
  171. <span> (inc. additional services)</span>
  172. </p>
  173. </div>
  174. <button class="button" type="submit" data-adding-to-basket="Adding..." id="button--add-to-basket" data-alert-text="Adding to basket">Get price</button>
  175. </div>
  176. <input class="m2m-input-sku-id" type="hidden" name="skuId" value="240555" id="sku-id-input">
  177. <input class="m2m-input-price-per-metre" type="hidden" name="pricePerMetre" value="35.00" id="price-per-metre-input">
  178. <input class="m2m-input-currency-symbol" type="hidden" name="currencySymbol" value="£" id="currency-symbol-input">
  179. </form>
  180. </div>
  181. <div class="m2m-standard-product-column-full">
  182. <div class="product-details" id="product-details">
  183. <a id="skip-link--product-details" data-skiplink="true" href="#product-details">View product details</a>
  184. </div>
  185. </div>
  186. </div>
  187. </main>
  188. <footer class="footer-site-wide">
  189. this is test content
  190. </footer>
  191. </body>
  192. </html>`,
  193. onload(window) {}
  194. }));
  195.  
  196. function mainClass(){
  197. return document.querySelector( 'main' );
  198. }
  199.  
  200. function selectDetailsForm() {
  201. return document.querySelector('.m2m-measurements-form')
  202. }
  203.  
  204. function selectWidthContainer() {
  205. return selectDetailsForm().querySelector('.m2m-width-container');
  206. }
  207.  
  208. function selectHeightContainer() {
  209. return selectDetailsForm().querySelector('.m2m-height-container');
  210. }
  211.  
  212. function selectInstallationHeightContainer() {
  213. return selectDetailsForm().querySelector('.m2m-installation-height-container');
  214. }
  215.  
  216. function selectWidthInput() {
  217. return selectDetailsForm().querySelector('#width');
  218. }
  219.  
  220. function selectHeightInput() {
  221. return selectDetailsForm().querySelector('#height');
  222. }
  223.  
  224. function selectInstallationHeightInput() {
  225. return selectDetailsForm().querySelector('#installationHeight');
  226. }
  227.  
  228. function selectReviewYourRollerBlindButton() {
  229. return selectDetailsForm().querySelector('button[type="submit"]');
  230. }
  231.  
  232. function selectSwatchListSection() {
  233. return selectDetailsForm().querySelector('.m2m-swatch-list-section')
  234. }
  235.  
  236. it( 'should initialise on m2m product page class', () => {
  237. expect ( mainClass().classList.contains('m2m-standard-product-page-main') ).to.not.be.null;
  238. });
  239.  
  240. it( "should have an inactive 'review your roller blind' button on load", () => {
  241. expect (selectReviewYourRollerBlindButton()).to.have.class('button--inactive');
  242. expect (selectReviewYourRollerBlindButton().innerHTML).to.equal('Review your roller blind');
  243. });
  244.  
  245. it( 'should prevent form submission when input values are empty and error on all fields', (done) => {
  246. selectReviewYourRollerBlindButton().click();
  247. setTimeout(function() {
  248. expect(selectDetailsForm().querySelector('label[for="m2m-inside-recess-btn"]')).to.have.id('m2m-label-error');
  249. expect(selectDetailsForm().querySelector('label[for="m2m-outside-recess-btn"]')).to.have.id('m2m-label-error');
  250. expect(selectDetailsForm().querySelector('.m2m-invalid-recess-error')).to.not.have.class('u-hidden');
  251. expect(selectWidthContainer().querySelector('label')).to.have.id('m2m-label-error');
  252. expect(selectWidthContainer().querySelector('p.m2m-error-text')).to.exist;
  253. expect(selectWidthInput()).to.have.class('u-input--invalid');
  254. expect(selectHeightContainer().querySelector('label')).to.have.id('m2m-label-error');
  255. expect(selectHeightContainer().querySelector('p.m2m-error-text')).to.exist
  256. expect(selectHeightInput()).to.have.class('u-input--invalid');
  257. expect(selectInstallationHeightContainer().querySelector('label')).to.have.id('m2m-label-error');
  258. expect(selectInstallationHeightContainer().querySelector('p.m2m-error-text')).to.exist;
  259. expect(selectInstallationHeightInput()).to.have.class('u-input--invalid');
  260. expect(selectDetailsForm().querySelector('label[for="m2m-standard-roll-btn"]')).to.have.id('m2m-label-error');
  261. expect(selectDetailsForm().querySelector('label[for="m2m-reverse-roll-btn"]')).to.have.id('m2m-label-error');
  262. expect(selectDetailsForm().querySelector('.m2m-invalid-roll-direction-error')).to.not.have.class('u-hidden');
  263. done();
  264. }, 100);
  265. });
  266.  
  267. it( 'if swatches exist on page, it should remove the hidden core submit button', () => {
  268. if (selectSwatchListSection()) {
  269. expect(selectSwatchListSection().querySelector('.m2m-swatch-hidden-submit')).to.not.exist;
  270. }
  271. });
  272.  
  273. it( 'if swatches exist on page, they should be converted from submits to buttons', () => {
  274. if (selectSwatchListSection()) {
  275. expect(selectSwatchListSection().querySelector('.m2m-swatch-list-item button')).to.have.property('type','button');
  276. }
  277. });
  278.  
  279. it.only( 'should return a total price on all inputs valid', () => {
  280. //const widthInput = selectWidthInput();
  281. try {
  282. keyboard.enter("111", selectWidthInput());
  283.  
  284.  
  285. //console.log(selectWidthInput().value);
  286. expect(selectWidthInput()).to.have.value('111');
  287. } catch(err) {
  288. console.log(err);
  289. }
  290. });
  291.  
  292. /*
  293. expect(selectWidthInput()).to.have.value('111');
  294. selectDetailsForm().querySelector('#inside-recess').click();
  295. selectDetailsForm().querySelector('#reverse-roll').click();
  296.  
  297. const heightInput = selectHeightInput();
  298. const installationHeightInput = selectInstallationHeightInput();
  299.  
  300. keyboard.enter("111", heightInput);
  301. keyboard.enter("111", installationHeightInput);
  302.  
  303. expect(widthInput).to.have.value('111');
  304. expect(heightInput).to.have.value('111');
  305. expect(installationHeightInput).to.have.value('111');
  306. console.log(selectDetailsForm().querySelector('#inside-recess'))
  307. console.log(heightInput.value)
  308. console.log(widthInput.value)
  309. console.log(installationHeightInput.value)
  310. console.log(selectDetailsForm().querySelector('#inside-re'))
  311. setTimeout(function() {
  312. expect(selectDetailsForm().querySelector('.m2m-price-from').innerText).to.equal('Total roller blind price');
  313. done();
  314. }, 2000);
  315.  
  316. describe('Suite A', function () {
  317. it('Foo', function (done) {
  318. setTimeout(function () {
  319. (true).should.equal(true);
  320. done();
  321. }, 1000);
  322. });
  323. */
  324. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement