defaults-popup.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. var t = require('assert')
  2. module.exports = ({popup}) => {
  3. before(async () => {
  4. await popup.bringToFront()
  5. })
  6. it('button - raw', async () => {
  7. t.strictEqual(
  8. await popup.evaluate(() =>
  9. state.raw
  10. ),
  11. false,
  12. 'state.raw should equal false'
  13. )
  14. t.strictEqual(
  15. await popup.evaluate(() =>
  16. document.querySelector('.m-button:first-child').innerText.toLowerCase()
  17. ),
  18. 'markdown',
  19. 'button text should equal markdown'
  20. )
  21. })
  22. it('tabs', async () => {
  23. t.equal(
  24. await popup.evaluate(() =>
  25. state.tab
  26. ),
  27. 'theme',
  28. 'state.tab should equal theme'
  29. )
  30. t.deepStrictEqual(
  31. await popup.evaluate(() =>
  32. state.tabs
  33. ),
  34. await popup.evaluate(() =>
  35. Array.from(document.querySelectorAll('.m-tabs a'))
  36. .map((tab) => tab.innerText.trim().toLowerCase())
  37. ),
  38. 'state.tabs should be identical to dom tabs'
  39. )
  40. t.strictEqual(
  41. await popup.evaluate(() =>
  42. localStorage.getItem('tab')
  43. ),
  44. null,
  45. 'localStorage tab key should be null'
  46. )
  47. })
  48. it('tab - theme', async () => {
  49. t.equal(
  50. await popup.evaluate(() =>
  51. state.theme.name
  52. ),
  53. 'github',
  54. 'state.theme.name should equal github'
  55. )
  56. t.strictEqual(
  57. await popup.evaluate(() =>
  58. document.querySelector('.m-panel:first-child')
  59. .classList.contains('is-active')
  60. ),
  61. true,
  62. 'the first tab panel should be active'
  63. )
  64. t.deepStrictEqual(
  65. await popup.evaluate(() =>
  66. state.themes
  67. ),
  68. await popup.evaluate(() =>
  69. Array.from(document.querySelectorAll('.m-panel:first-child select option'))
  70. .map((option) => option.innerText)
  71. ),
  72. 'state.themes should be identical to dom themes'
  73. )
  74. t.strictEqual(
  75. await popup.evaluate(() =>
  76. document.querySelector('.m-panel:first-child select').selectedIndex
  77. ),
  78. 0,
  79. 'dom select option should be 0'
  80. )
  81. t.strictEqual(
  82. await popup.evaluate(() =>
  83. state.themes.length
  84. ),
  85. 20,
  86. 'state.themes count should be 20'
  87. )
  88. })
  89. it('tab - compiler', async () => {
  90. await popup.click('.m-tabs a:nth-of-type(2)')
  91. t.equal(
  92. await popup.evaluate(() =>
  93. state.tab
  94. ),
  95. 'compiler',
  96. 'state.tab should equal compiler'
  97. )
  98. t.strictEqual(
  99. await popup.evaluate(() =>
  100. localStorage.getItem('compiler')
  101. ),
  102. null,
  103. 'localStorage compiler key should be null'
  104. )
  105. t.strictEqual(
  106. await popup.evaluate(() =>
  107. document.querySelector('.m-panel:nth-of-type(2)')
  108. .classList.contains('is-active')
  109. ),
  110. true,
  111. 'the second tab panel should be active'
  112. )
  113. t.deepStrictEqual(
  114. await popup.evaluate(() =>
  115. state.compilers
  116. ),
  117. await popup.evaluate(() =>
  118. Array.from(document.querySelectorAll('.m-panel:nth-of-type(2) select option'))
  119. .map((option) => option.innerText)
  120. ),
  121. 'state.compilers should be identical to dom compilers'
  122. )
  123. t.strictEqual(
  124. await popup.evaluate(() =>
  125. document.querySelector('.m-panel:first-child select').selectedIndex
  126. ),
  127. 0,
  128. 'dom select option should be 0'
  129. )
  130. t.strictEqual(
  131. await popup.evaluate(() =>
  132. state.compilers.length
  133. ),
  134. 2,
  135. 'state.compilers length should equal 2'
  136. )
  137. t.deepStrictEqual(
  138. await popup.evaluate(() =>
  139. Object.keys(state.options)
  140. .filter((key) => typeof state.options[key] === 'boolean')
  141. .reduce((obj, key) => (obj[key] = state.options[key], obj), {})
  142. ),
  143. await popup.evaluate(() =>
  144. Array.from(document.querySelectorAll('.m-panel:nth-of-type(2) label'))
  145. .reduce((all, option) => (
  146. all[option.querySelector('span').innerText.trim()] =
  147. option.classList.contains('is-checked'), all
  148. ), {})
  149. ),
  150. 'state.options should equal dom compiler options'
  151. )
  152. })
  153. it('tab - content', async () => {
  154. await popup.click('.m-tabs a:nth-of-type(3)')
  155. t.equal(
  156. await popup.evaluate(() =>
  157. state.tab
  158. ),
  159. 'content',
  160. 'state.tab should equal content'
  161. )
  162. t.deepStrictEqual(
  163. await popup.evaluate(() =>
  164. state.content
  165. ),
  166. await popup.evaluate(() =>
  167. Array.from(document.querySelectorAll('.m-panel:nth-of-type(3) label'))
  168. .reduce((all, option) => (
  169. all[option.querySelector('span').innerText.trim()] =
  170. option.classList.contains('is-checked'), all
  171. ), {})
  172. ),
  173. 'state.content should equal dom content options'
  174. )
  175. })
  176. }