您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

integration.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const fs = require("../server/fs_promises.js");
  2. const os = require("os");
  3. const path = require("path");
  4. const PORT = 8487
  5. const SERVER = 'http://localhost:' + PORT;
  6. let wbo, data_path;
  7. async function beforeEach(browser, done) {
  8. data_path = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'wbo-test-data-'));
  9. process.env["PORT"] = PORT;
  10. process.env["WBO_HISTORY_DIR"] = data_path;
  11. console.log("Launching WBO in " + data_path);
  12. wbo = require("../server/server.js");
  13. done();
  14. }
  15. async function afterEach(browser, done) {
  16. wbo.close();
  17. done();
  18. }
  19. function testPencil(browser) {
  20. return browser
  21. .assert.titleContains('WBO')
  22. .click('.tool[title ~= Crayon]') // pencil
  23. .assert.cssClassPresent('.tool[title ~= Crayon]', ['curTool'])
  24. .executeAsync(async function (done) {
  25. function sleep(t) {
  26. return new Promise(function (accept) { setTimeout(accept, t); });
  27. }
  28. // A straight path with just two points
  29. Tools.setColor('#123456');
  30. Tools.curTool.listeners.press(100, 200, new Event("mousedown"));
  31. await sleep(80);
  32. Tools.curTool.listeners.release(300, 400, new Event("mouseup"));
  33. // A line with three points that form an "U" shape
  34. await sleep(80);
  35. Tools.setColor('#abcdef');
  36. Tools.curTool.listeners.press(0, 0, new Event("mousedown"));
  37. await sleep(80);
  38. Tools.curTool.listeners.move(90, 120, new Event("mousemove"));
  39. await sleep(80);
  40. Tools.curTool.listeners.release(180, 0, new Event("mouseup"));
  41. done();
  42. })
  43. .assert.visible("path[d='M 100 200 L 100 200 C 100 200 300 400 300 400'][stroke='#123456']")
  44. .assert.visible("path[d='M 0 0 L 0 0 C 0 0 40 120 90 120 C 140 120 180 0 180 0'][stroke='#abcdef']")
  45. .refresh()
  46. .waitForElementVisible("path[d='M 100 200 L 100 200 C 100 200 300 400 300 400'][stroke='#123456']")
  47. .assert.visible("path[d='M 0 0 L 0 0 C 0 0 40 120 90 120 C 140 120 180 0 180 0'][stroke='#abcdef']")
  48. .url(SERVER + '/preview/anonymous')
  49. .waitForElementVisible("path[d='M 100 200 L 100 200 C 100 200 300 400 300 400'][stroke='#123456']")
  50. .assert.visible("path[d='M 0 0 L 0 0 C 0 0 40 120 90 120 C 140 120 180 0 180 0'][stroke='#abcdef']")
  51. .back()
  52. }
  53. function testCircle(browser) {
  54. return browser
  55. .click('#toolID-Ellipse')
  56. .executeAsync(function (done) {
  57. Tools.setColor('#112233');
  58. Tools.curTool.listeners.press(200, 400, new Event("mousedown"));
  59. setTimeout(() => {
  60. const evt = new Event("mousemove");
  61. evt.shiftKey = true;
  62. Tools.curTool.listeners.move(0, 0, evt);
  63. done();
  64. }, 100);
  65. })
  66. .assert.visible("ellipse[cx='0'][cy='200'][rx='200'][ry='200'][stroke='#112233']")
  67. .refresh()
  68. .waitForElementVisible("ellipse[cx='0'][cy='200'][rx='200'][ry='200'][stroke='#112233']")
  69. .click('#toolID-Ellipse') // Click the ellipse tool
  70. .click('#toolID-Ellipse') // Click again to toggle
  71. .assert.containsText('#toolID-Ellipse .tool-name', 'Cercle') // Circle in french
  72. }
  73. function testCursor(browser) {
  74. return browser
  75. .execute(function (done) {
  76. Tools.setColor('#456123'); // Move the cursor over the board
  77. var e = new Event("mousemove");
  78. e.pageX = 150;
  79. e.pageY = 200;
  80. Tools.board.dispatchEvent(e)
  81. })
  82. .assert.cssProperty("#cursor-me", "transform", "matrix(1, 0, 0, 1, 150, 200)")
  83. .assert.attributeEquals("#cursor-me", "fill", "#456123")
  84. }
  85. function testBoard(browser) {
  86. var page = browser.url(SERVER + '/boards/anonymous?lang=fr')
  87. .waitForElementVisible('.tool[title ~= Crayon]') // pencil
  88. page = testPencil(page);
  89. page = testCircle(page);
  90. page = testCursor(page);
  91. // test hideMenu
  92. browser.url(SERVER + '/boards/anonymous?lang=fr&hideMenu=true').waitForElementNotVisible('#menu');
  93. browser.url(SERVER + '/boards/anonymous?lang=fr&hideMenu=false').waitForElementVisible('#menu');
  94. page.end();
  95. }
  96. module.exports = { beforeEach, testBoard, afterEach };