authRequireGuestsToLogin.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect } from 'chai'
  3. import { By } from 'selenium-webdriver'
  4. import {
  5. takeScreenshotOnFailure,
  6. } from '../../lib/elements.js'
  7. describe('config: authRequireGuestsToLogin', function () {
  8. this.timeout(30000)
  9. before(async function () {
  10. await runner.start('authRequireGuestsToLogin')
  11. })
  12. after(async () => {
  13. await runner.stop()
  14. })
  15. afterEach(function () {
  16. takeScreenshotOnFailure(this.currentTest, webdriver);
  17. });
  18. it('Guest is redirected to login', async function () {
  19. // Don't use getRootAndWait here because we want to test the redirect, and getRootAndWait waits for the dashboard to load
  20. await webdriver.get(runner.baseUrl())
  21. await webdriver.wait(async () => {
  22. const loginRequired = await webdriver.executeScript(
  23. 'return !!(window.initResponse && window.initResponse.loginRequired)'
  24. )
  25. const url = await webdriver.getCurrentUrl()
  26. return loginRequired && url.includes('/login')
  27. }, 15000, 'Guest should be redirected to login after Init')
  28. // Verify login UI elements are present
  29. const loginElements = await webdriver.findElements(By.css('form.local-login-form, .login-oauth2, .login-disabled'))
  30. expect(loginElements.length).to.be.greaterThan(0)
  31. console.log('✓ Login page loaded correctly')
  32. })
  33. })