argumentIdCollision.mjs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. argumentFieldId,
  7. getRootAndWait,
  8. getActionButton,
  9. takeScreenshotOnFailure,
  10. waitForArgumentFormPage,
  11. waitForArgumentFormReady,
  12. waitForLogsPage,
  13. waitForExecutionComplete,
  14. getTerminalBuffer,
  15. } from '../../lib/elements.js'
  16. async function openArgumentForm (actionTitle) {
  17. await getRootAndWait()
  18. const btn = await getActionButton(webdriver, actionTitle)
  19. await btn.click()
  20. await waitForArgumentFormPage()
  21. await waitForArgumentFormReady()
  22. }
  23. async function waitForStartButtonEnabled () {
  24. await webdriver.wait(
  25. new Condition('wait for Start button to be enabled', async () => {
  26. const submitButton = await webdriver.findElement(By.css('button[name="start"]'))
  27. return await submitButton.isEnabled()
  28. }),
  29. DEFAULT_UI_WAIT_MS
  30. )
  31. }
  32. async function waitForTerminalOutput (expectedSubstring) {
  33. await webdriver.wait(
  34. new Condition(`wait for terminal output containing ${expectedSubstring}`, async () => {
  35. try {
  36. const terminalReady = await webdriver.executeScript(`
  37. return !!(window.terminal && window.terminal.getBufferAsString);
  38. `)
  39. if (!terminalReady) {
  40. return false
  41. }
  42. const output = await getTerminalBuffer()
  43. return output && output.includes(expectedSubstring)
  44. } catch (e) {
  45. return false
  46. }
  47. }),
  48. DEFAULT_UI_WAIT_MS
  49. )
  50. }
  51. describe('config: argumentIdCollision', function () {
  52. this.timeout(10000)
  53. before(async function () {
  54. await runner.start('argumentIdCollision')
  55. })
  56. after(async () => {
  57. await runner.stop()
  58. })
  59. afterEach(function () {
  60. takeScreenshotOnFailure(this.currentTest, webdriver)
  61. })
  62. it('Argument named content validates and submits (#1071)', async function () {
  63. await openArgumentForm('Test content argument collision')
  64. const contentWrapper = await webdriver.findElement(By.id('content'))
  65. expect(await contentWrapper.getTagName()).to.equal('div')
  66. const textarea = await webdriver.findElement(By.id(argumentFieldId('content')))
  67. expect(await textarea.getTagName()).to.equal('textarea')
  68. expect(await textarea.getAttribute('id')).to.not.equal('content')
  69. const label = await webdriver.findElement(By.css(`label[for="${argumentFieldId('content')}"]`))
  70. expect(await label.getText()).to.contain('Cmd input')
  71. await textarea.sendKeys('hello from collision test')
  72. const submitButton = await webdriver.findElement(By.css('button[name="start"]'))
  73. await waitForStartButtonEnabled()
  74. await submitButton.click()
  75. await waitForLogsPage()
  76. await waitForExecutionComplete()
  77. await waitForTerminalOutput('Cmd input: hello from collision test')
  78. })
  79. it('Argument named layout validates and submits (#1071)', async function () {
  80. await openArgumentForm('Test layout argument collision')
  81. const layoutWrapper = await webdriver.findElement(By.id('layout'))
  82. expect(await layoutWrapper.getTagName()).to.equal('div')
  83. const input = await webdriver.findElement(By.id(argumentFieldId('layout')))
  84. expect(await input.getAttribute('type')).to.equal('text')
  85. expect(await input.getAttribute('id')).to.not.equal('layout')
  86. await input.sendKeys('testlayoutvalue')
  87. const submitButton = await webdriver.findElement(By.css('button[name="start"]'))
  88. await waitForStartButtonEnabled()
  89. await submitButton.click()
  90. await waitForLogsPage()
  91. await waitForExecutionComplete()
  92. await waitForTerminalOutput('Layout value: testlayoutvalue')
  93. })
  94. it('Namespaced argument ids do not match app-shell ids', async function () {
  95. await openArgumentForm('Test content argument collision')
  96. const namespacedIds = await webdriver.executeScript(`
  97. const requiredShellIds = ['content', 'layout'];
  98. const optionalShellIds = ['banner', 'app', 'mainnav', 'big-error'];
  99. const fieldId = arguments[0];
  100. const fieldElement = document.getElementById(fieldId);
  101. return {
  102. fieldTag: fieldElement?.tagName?.toLowerCase() ?? null,
  103. required: requiredShellIds.map((shellId) => {
  104. const shellElement = document.getElementById(shellId);
  105. return {
  106. shellId,
  107. shellTag: shellElement?.tagName?.toLowerCase() ?? null,
  108. sameElement: shellElement != null && shellElement === fieldElement
  109. };
  110. }),
  111. optional: optionalShellIds.map((shellId) => {
  112. const shellElement = document.getElementById(shellId);
  113. return {
  114. shellId,
  115. sameElement: shellElement != null && shellElement === fieldElement
  116. };
  117. })
  118. };
  119. `, argumentFieldId('content'))
  120. expect(namespacedIds.fieldTag, `argument field ${argumentFieldId('content')} should exist`).to.equal('textarea')
  121. for (const entry of namespacedIds.required) {
  122. expect(entry.shellTag, `app-shell #${entry.shellId} should exist`).to.not.equal(null)
  123. expect(entry.sameElement, `arg field must not resolve to #${entry.shellId}`).to.be.false
  124. }
  125. for (const entry of namespacedIds.optional) {
  126. expect(entry.sameElement, `arg field must not resolve to #${entry.shellId}`).to.be.false
  127. }
  128. })
  129. })