origin-add.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. var t = require('assert')
  2. module.exports = ({popup, advanced, content}) => {
  3. before(async () => {
  4. // popup
  5. await popup.bringToFront()
  6. // defaults button
  7. await popup.click('button:nth-of-type(2)')
  8. // advanced
  9. await advanced.bringToFront()
  10. // remove origin
  11. if (await advanced.evaluate(() => Object.keys(state.origins).length > 1)) {
  12. // expand origin
  13. if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(2)').classList.contains('m-expanded'))) {
  14. await advanced.click('.m-list li:nth-of-type(2)')
  15. }
  16. await advanced.click('.m-list li:nth-of-type(2) .m-footer .m-button')
  17. }
  18. // add origin
  19. await advanced.select('.m-select', 'http')
  20. await advanced.type('[type=text]', 'localhost:3000')
  21. await advanced.click('button')
  22. await advanced.waitFor(200)
  23. // expand origin
  24. if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(2)').classList.contains('m-expanded'))) {
  25. await advanced.click('.m-list li:nth-of-type(2)')
  26. }
  27. })
  28. describe('defaults', () => {
  29. it('localhost:3000', async () => {
  30. t.equal(
  31. await advanced.evaluate(() =>
  32. document.querySelectorAll('.m-list li').length
  33. ),
  34. 2,
  35. 'allowed origins count should be 2'
  36. )
  37. t.equal(
  38. await advanced.evaluate(() =>
  39. document.querySelector('.m-list li:nth-of-type(2) .m-origin').innerText
  40. ),
  41. 'http://localhost:3000',
  42. 'origin name should be http://localhost:3000'
  43. )
  44. t.strictEqual(
  45. await advanced.evaluate(() =>
  46. document.querySelector('.m-list li:nth-of-type(2) .m-switch').classList.contains('is-checked')
  47. ),
  48. false,
  49. 'csp checkbox should be disabled'
  50. )
  51. t.equal(
  52. await advanced.evaluate(() =>
  53. document.querySelector('.m-list li:nth-of-type(2) .m-encoding select').value
  54. ),
  55. '',
  56. 'encoding should be set to auto'
  57. )
  58. t.strictEqual(
  59. await advanced.evaluate(() =>
  60. document.querySelectorAll('.m-list li:nth-of-type(2) .m-footer .m-button').length
  61. ),
  62. 1,
  63. 'only one button should be visible in the origin footer'
  64. )
  65. t.equal(
  66. await advanced.evaluate(() =>
  67. document.querySelector('.m-list li:nth-of-type(2) .m-footer .m-button').innerText.toLowerCase()
  68. ),
  69. 'remove',
  70. 'remove origin button should be rendered'
  71. )
  72. })
  73. })
  74. }