Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

94 rindas
2.6 KiB

  1. import test from 'ava';
  2. import {getLoginForm} from '../extension/form-parser';
  3. test('get login form', t => {
  4. global.document = require('jsdom').jsdom('<!doctype html><html><body><form><input type="password"></form></body></html>');
  5. global.window = document.defaultView;
  6. global.navigator = window.navigator;
  7. const loginForm = getLoginForm();
  8. const expectedForm = document.forms[0];
  9. t.is(expectedForm, loginForm.form);
  10. });
  11. test('get first login form with password field in it', t => {
  12. global.document = require('jsdom').jsdom(`
  13. <!doctype html>
  14. <html>
  15. <body>
  16. <form></form>
  17. <form id="second-form">
  18. <input type="password">
  19. </form>
  20. </body>
  21. </html>`);
  22. global.window = document.defaultView;
  23. global.navigator = window.navigator;
  24. const loginForm = getLoginForm();
  25. const expectedForm = document.getElementById('second-form');
  26. t.is(expectedForm, loginForm.form);
  27. });
  28. test('get password field', t => {
  29. global.document = require('jsdom').jsdom(`
  30. <!doctype html>
  31. <html>
  32. <body>
  33. <form>
  34. <input id="password-field" type="password">
  35. </form>
  36. </body>
  37. </html>`);
  38. global.window = document.defaultView;
  39. global.navigator = window.navigator;
  40. const loginForm = getLoginForm();
  41. const expectPasswordField = document.getElementById('password-field');
  42. t.is(expectPasswordField, loginForm.passwordField);
  43. });
  44. test('get login field', t => {
  45. global.document = require('jsdom').jsdom(`
  46. <!doctype html>
  47. <html>
  48. <body>
  49. <form>
  50. <input id="login-field" type="text">
  51. <input id="password-field" type="password">
  52. </form>
  53. </body>
  54. </html>`);
  55. global.window = document.defaultView;
  56. global.navigator = window.navigator;
  57. const loginForm = getLoginForm();
  58. const expectedLoginField = document.getElementById('login-field');
  59. t.is(expectedLoginField, loginForm.loginField);
  60. });
  61. test('get real example', t => {
  62. global.document = require('jsdom').jsdom(`
  63. <!doctype html>
  64. <html>
  65. <body>
  66. <form class="form signin" method="post">
  67. <div class="username field">
  68. <input type="text" id="signin-email" class="text-input email-input"
  69. name="username_or_email" placeholder="Phone, email or username"/>
  70. </div>
  71. <div class="password field">
  72. <input type="password" id="signin-password" class="text-input password-input"
  73. name="password" placeholder="Password">
  74. </div>
  75. </form>
  76. </body>
  77. </html>`);
  78. global.window = document.defaultView;
  79. global.navigator = window.navigator;
  80. const loginForm = getLoginForm();
  81. t.is(document.forms[0], loginForm.form);
  82. t.is(document.getElementById('signin-email'), loginForm.loginField);
  83. t.is(document.getElementById('signin-password'), loginForm.passwordField);
  84. });