argumentActionFlash.mjs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { describe, it, before, after } from 'mocha'
  2. import { expect } from 'chai'
  3. import { By, Condition } from 'selenium-webdriver'
  4. import {
  5. DEFAULT_UI_WAIT_MS,
  6. getRootAndWait,
  7. getActionButton,
  8. takeScreenshotOnFailure,
  9. waitForArgumentFormPage,
  10. waitForArgumentFormReady,
  11. waitForDashboardLoaded,
  12. } from '../../lib/elements.js'
  13. async function waitForStartButtonEnabled () {
  14. await webdriver.wait(
  15. new Condition('wait for Start button to be enabled', async () => {
  16. const submitButton = await webdriver.findElement(By.css('button[name="start"]'))
  17. return await submitButton.isEnabled()
  18. }),
  19. DEFAULT_UI_WAIT_MS
  20. )
  21. }
  22. async function waitForActionSuccessFlash (actionTitle) {
  23. await webdriver.wait(
  24. new Condition(`wait for ${actionTitle} success flash`, async () => {
  25. try {
  26. const button = await getActionButton(webdriver, actionTitle)
  27. const classAttr = await button.getAttribute('class')
  28. return classAttr && classAttr.includes('action-success')
  29. } catch (e) {
  30. return false
  31. }
  32. }),
  33. DEFAULT_UI_WAIT_MS
  34. )
  35. }
  36. describe('config: argumentActionFlash', function () {
  37. this.timeout(15000)
  38. before(async function () {
  39. await runner.start('argumentActionFlash')
  40. })
  41. after(async () => {
  42. await runner.stop()
  43. })
  44. afterEach(function () {
  45. takeScreenshotOnFailure(this.currentTest, webdriver)
  46. })
  47. it('Action with arguments flashes success after returning to dashboard (#920)', async function () {
  48. await getRootAndWait()
  49. const argButton = await getActionButton(webdriver, 'Hello world')
  50. await argButton.click()
  51. await waitForArgumentFormPage()
  52. await waitForArgumentFormReady()
  53. await waitForStartButtonEnabled()
  54. const submitButton = await webdriver.findElement(By.css('button[name="start"]'))
  55. await submitButton.click()
  56. await webdriver.wait(
  57. new Condition('wait to leave argument form', async () => {
  58. const url = await webdriver.getCurrentUrl()
  59. return !url.includes('/argumentForm')
  60. }),
  61. DEFAULT_UI_WAIT_MS
  62. )
  63. await waitForDashboardLoaded()
  64. await waitForActionSuccessFlash('Hello world')
  65. const flashedButton = await getActionButton(webdriver, 'Hello world')
  66. const classAttr = await flashedButton.getAttribute('class')
  67. expect(classAttr).to.include('action-success')
  68. })
  69. it('Action without arguments still flashes success on the dashboard', async function () {
  70. await getRootAndWait()
  71. const simpleButton = await getActionButton(webdriver, 'Simple action')
  72. await simpleButton.click()
  73. await waitForActionSuccessFlash('Simple action')
  74. const flashedButton = await getActionButton(webdriver, 'Simple action')
  75. const classAttr = await flashedButton.getAttribute('class')
  76. expect(classAttr).to.include('action-success')
  77. })
  78. })