test01-system-setup.spec.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. describe('Typemill Setup', function()
  2. {
  3. it('validates form input', function ()
  4. {
  5. // visit setup form
  6. cy.visit('/setup')
  7. // cy.visit('/setup',{ onBeforeLoad: (_contentWindow) => { Object.defineProperty(navigator, 'language', { value: 'fr-FR' }) } })
  8. cy.url().should('include','/setup')
  9. // add data and check attributes
  10. cy.get('input[name="username"]')
  11. .type('?1')
  12. .should('have.value', '?1')
  13. .and('have.attr', 'required')
  14. cy.get('input[name="email"]')
  15. .type('trendschau.net')
  16. .should('have.value', 'trendschau.net')
  17. .and('have.attr', 'required')
  18. cy.get('input[name="password"]')
  19. .type('pass')
  20. .should('have.value', 'pass')
  21. .and('have.attr', 'required')
  22. // submit and get validation errors
  23. cy.get('form').submit()
  24. cy.get('#flash-message').should('contain', 'Please check your input and try again')
  25. cy.get('.error').should('contain', 'invalid characters')
  26. cy.get('.error').should('contain', 'e-mail is invalid')
  27. cy.get('.error').should('contain', 'Length between 5 - 20')
  28. })
  29. it('fails without CSRF-token', function ()
  30. {
  31. cy.request({
  32. method: 'POST',
  33. url: '/setup', // baseUrl is prepended to url
  34. form: true, // indicates the body should be form urlencoded and sets Content-Type: application/x-www-form-urlencoded headers
  35. failOnStatusCode: false,
  36. body: {
  37. username: 'trendschau',
  38. email: 'trendschau@gmail.com',
  39. password: 'password'
  40. }
  41. })
  42. .its('body')
  43. .should('include', 'Failed CSRF check')
  44. })
  45. it('submits valid form data and visit welcome and settings page', function ()
  46. {
  47. cy.visit('/setup')
  48. // enter correct data
  49. cy.get('input[name="username"]').clear().type('trendschau')
  50. cy.get('input[name="email"]').clear().type('trendschau@gmail.com')
  51. cy.get('input[name="password"]').clear().type('password')
  52. // submits valid form
  53. cy.get('form').submit()
  54. cy.url().should('include','/welcome')
  55. cy.getCookie('typemill-session').should('exist')
  56. Cypress.Cookies.preserveOnce('typemill-session')
  57. // clicks link on welcome page to settings page
  58. // cy.get('.button').should('contain', 'Configure your website')
  59. cy.get('.button').click()
  60. cy.url().should('include', '/tm/settings')
  61. })
  62. it('creates default settings data', function()
  63. {
  64. cy.get('input[name="settings[title]"]')
  65. .should('have.value', 'TYPEMILL')
  66. .and('have.attr','required')
  67. cy.get('input[name="settings[author]"]')
  68. cy.get('select[name="settings[copyright]"]')
  69. cy.get('input[name="settings[year]"]')
  70. .should('have.attr', 'required')
  71. cy.get('select[name="settings[language]"]')
  72. // cy.get('select[name="settings[langattr]"]')
  73. cy.get('input[name="settings[sitemap]"]')
  74. .should('have.value', 'http://localhost/typemillTest/cache/sitemap.xml')
  75. .and('have.attr','readonly')
  76. cy.get('input[name="settings[logo]"]')
  77. cy.get('input[name="settings[deletelogo]"]')
  78. cy.get('input[name="settings[favicon]"]')
  79. cy.get('input[name="settings[deletefav]"]')
  80. cy.get('input[name="settings[headlineanchors]"]')
  81. cy.get('input[name="settings[editor]"]')
  82. cy.get('select[name="settings[language]"]')
  83. .select('en')
  84. .should('have.value', 'en')
  85. cy.get('form').submit()
  86. cy.get('#flash-message').should('contain', 'Settings are stored')
  87. Cypress.Cookies.preserveOnce('typemill-session')
  88. })
  89. it('creates default user data', function()
  90. {
  91. cy.visit('/tm/user/trendschau')
  92. cy.url().should('include', '/tm/user/trendschau')
  93. cy.get('input[name="user[username]"]')
  94. .should('have.value', 'trendschau')
  95. cy.get('input[name="user[firstname]"]')
  96. .clear()
  97. .type('Sebastian')
  98. .should('have.value', 'Sebastian')
  99. cy.get('input[name="user[lastname]"]')
  100. .clear()
  101. .type('Schürmanns')
  102. .should('have.value', 'Schürmanns')
  103. cy.get('input[name="user[email]"]')
  104. .should('have.value', 'trendschau@gmail.com')
  105. cy.get('select[name="user[userrole]"]')
  106. .should('have.value','administrator')
  107. cy.get('input[name="user[password]"]')
  108. .should('have.value', '')
  109. cy.get('input[name="user[newpassword]"]')
  110. .should('have.value', '')
  111. cy.get('#userform').submit()
  112. cy.get('#flash-message').should('contain', 'Saved all changes')
  113. })
  114. it('logouts out', function()
  115. {
  116. // visits logout link
  117. cy.visit('/tm/logout')
  118. cy.url().should('include', '/tm/login')
  119. // tries to open setup form again and gets redirected to login
  120. cy.visit('/setup')
  121. cy.url().should('include','/login')
  122. })
  123. it('redirects when tries to setup again', function()
  124. {
  125. // tries to open setup form again and gets redirected to login
  126. cy.visit('/setup')
  127. cy.url().should('include','/login')
  128. })
  129. })