workspace.spec.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const os = require('os')
  2. const {openAtom, runCommand, typeInEditor} = require('./helpers')
  3. const { test, expect } = require('@playwright/test')
  4. const languages = [
  5. {language: "JavaScript", code: 'function aFunction() { 10 }', checks: {numeric: '10', name: 'aFunction'}},
  6. {language: "Ruby", code: 'def a_function\n 10\nend', checks: {numeric: '10', name: 'a_function'}},
  7. {language: "Java", code: 'public int blah { return 10; }', checks: {numeric: '10', type: 'int'}},
  8. {language: "C", code: '10', checks: {numeric: '10'}},
  9. {language: "Clojure", code: '10', checks: {numeric: '10'}},
  10. {language: "CoffeeScript", code: '10', checks: {numeric: '10'}},
  11. {language: "C#", code: '10', checks: {numeric: '10'}},
  12. // {language: "css", code: '10', checks: {numeric: '10'}},
  13. // {language: "gfm", code: '10', checks: {numeric: '10'}},
  14. // {language: "git", code: '10', checks: {numeric: '10'}},
  15. {language: "Go", code: '10', checks: {numeric: '10'}},
  16. {language: "HTML", code: '<foo type="10"></foo>', checks: {string: '10'}},
  17. {language: "XML", code: '<foo type="10"></foo>', checks: {string: '"10"'}},
  18. // {language: "hyperlink", code: '10', checks: {numeric: '10'}},
  19. {language: "JSON", code: '10', checks: {numeric: '10'}},
  20. // {language: "less", code: '10', checks: {numeric: '10'}},
  21. // {language: "make", code: '10', checks: {numeric: '10'}},
  22. // {language: "mustache", code: '10', checks: {numeric: '10'}},
  23. {language: "Objective C", code: '10', checks: {numeric: '10'}},
  24. {language: "Perl", code: '10', checks: {numeric: '10'}},
  25. {language: "PHP", code: '<? 10 %>', checks: {numeric: '10'}},
  26. // {language: "property-list", code: '10', checks: {numeric: '10'}},
  27. {language: "Python", code: '10', checks: {numeric: '10'}},
  28. {language: "Ruby on Rails", code: '10', checks: {numeric: '10'}},
  29. {language: "Rust", code: '10', checks: {numeric: '10'}},
  30. // {language: "sass", code: '10', checks: {numeric: '10'}},
  31. {language: "Shell Script", code: 'a="10"', checks: {variable: 'a', string: '"10"'}},
  32. // {language: "source", code: '10', checks: {numeric: '10'}},
  33. {language: "SQL", code: '10', checks: {numeric: '10'}},
  34. // {language: "text", code: '10', checks: {numeric: '10'}},
  35. // {language: "todo", code: '10', checks: {numeric: '10'}},
  36. // {language: "toml", code: '10', checks: {numeric: '10'}},
  37. {language: "Typescript", code: '10', checks: {numeric: '10'}},
  38. {language: "YAML", code: 'a: 10', checks: {numeric: '10'}},
  39. ]
  40. let editor
  41. test.describe('Opening Atom for the first time', () => {
  42. test.beforeAll(async () => {
  43. editor = await openAtom("atom-home-tests", "opening-first-time")
  44. })
  45. test.afterAll(async () => {
  46. const closing = editor.app.close()
  47. await closing
  48. })
  49. test('the editor opens at the welcome page', async () => {
  50. const workspace = editor.page.locator('atom-workspace')
  51. await expect(workspace).toHaveText(/A Community-led Hyper-Hackable Text Editor/, {
  52. useInnerText: true,
  53. })
  54. })
  55. //test('shows core packages', async () => {
  56. // await runCommand(editor, 'Settings View: Open')
  57. // await editor.page.locator('a.icon', { hasText: 'Packages' }).click()
  58. // await expect(editor.page.locator('.package-name', { hasText: 'about' }).first())
  59. // .toBeVisible()
  60. //})
  61. //test('allows to install for packages', async () => {
  62. // await runCommand(editor, 'Settings View: Open')
  63. // await editor.page.locator('a.icon', { hasText: 'Install' }).click()
  64. // await typeInEditor(editor, '.packages', "termination")
  65. // await editor.page.locator('button.install-button:visible', { hasText: 'Install' }).click()
  66. // test.setTimeout(120000);
  67. // await expect(editor.page.locator('button', { hasText: 'Settings' }).first())
  68. // .toBeVisible({ timeout: 120000 })
  69. //})
  70. test.describe('the editor have syntax highlight', async () => {
  71. test.beforeAll(async () => {
  72. const workspace = editor.page.locator('atom-workspace')
  73. await expect(workspace).toHaveText(/A Community-led Hyper-Hackable Text Editor/, {
  74. useInnerText: true,
  75. })
  76. await runCommand(editor, 'Tabs: Close All Tabs')
  77. })
  78. test.afterEach(async () => {
  79. if(os.platform() === 'darwin') {
  80. await editor.page.keyboard.press('Meta+a')
  81. } else {
  82. await editor.page.keyboard.press('Control+a')
  83. }
  84. await editor.page.keyboard.press('Delete')
  85. await runCommand(editor, 'Tabs: Close Tab')
  86. })
  87. languages.forEach(({language, code, checks}) => {
  88. test(`for ${language}`, async () => {
  89. await runCommand(editor, 'Application: New File')
  90. await editor.page.locator('atom-text-editor.is-focused').type(code)
  91. await editor.page.locator('grammar-selector-status').click()
  92. const modalInput = editor.page.locator(".modal:visible atom-text-editor.is-focused")
  93. await modalInput.type(language)
  94. await modalInput.press('Enter')
  95. await Promise.all(
  96. Object.keys(checks).map(k =>
  97. expect(syntaxElement(k, checks[k])).toHaveText(checks[k])
  98. )
  99. )
  100. })
  101. })
  102. })
  103. })
  104. function syntaxElement(kind, text) {
  105. return editor.page.locator(
  106. `atom-text-editor.is-focused .syntax--${kind}`,
  107. { hasText: text }
  108. )
  109. }