20-basic-features--comments.cy.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. context('Comment', () => {
  2. const ssPrefix = 'comments-';
  3. let commentCount = 0;
  4. beforeEach(() => {
  5. // login
  6. cy.fixture("user-admin.json").then(user => {
  7. cy.login(user.username, user.password);
  8. });
  9. // visit page
  10. cy.visit('/comment');
  11. cy.collapseSidebar(true, true);
  12. })
  13. it('Successfully create comment page', () => {
  14. // save page
  15. cy.get('#grw-page-editor-mode-manager').as('pageEditorModeManager').should('be.visible');
  16. cy.waitUntil(() => {
  17. // do
  18. cy.get('@pageEditorModeManager').within(() => {
  19. cy.get('button:nth-child(2)').click();
  20. });
  21. // until
  22. return cy.get('.layout-root').then($elem => $elem.hasClass('editing'));
  23. });
  24. cy.get('.CodeMirror').should('be.visible');
  25. cy.getByTestid('page-editor').should('be.visible');
  26. cy.getByTestid('save-page-btn').click();
  27. cy.get('.wiki').should('be.visible');
  28. })
  29. it('Successfully add comments', () => {
  30. const commetText = 'add comment';
  31. cy.getByTestid('page-comment-button').click();
  32. // Open comment editor
  33. cy.waitUntil(() => {
  34. // do
  35. cy.getByTestid('open-comment-editor-button').click();
  36. // wait until
  37. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  38. });
  39. cy.get('.CodeMirror').type(commetText);
  40. cy.getByTestid("commet-submit-button").eq(0).click();
  41. // Check update comment count
  42. commentCount += 1
  43. cy.getByTestid('page-comment-button').contains(commentCount);
  44. cy.screenshot(`${ssPrefix}1-add-comments`);
  45. });
  46. it('Successfully reply comments', () => {
  47. const commetText = 'reply comment';
  48. cy.getByTestid('page-comment-button').click();
  49. // Open reply comment editor
  50. cy.waitUntil(() => {
  51. // do
  52. cy.getByTestid('comemnt-reply-button').eq(0).click();
  53. // wait until
  54. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  55. });
  56. cy.get('.CodeMirror').type(commetText);
  57. cy.getByTestid("commet-submit-button").eq(0).click();
  58. // Check update comment count
  59. commentCount += 1
  60. cy.getByTestid('page-comment-button').contains(commentCount);
  61. cy.screenshot(`${ssPrefix}2-reply-comments`);
  62. });
  63. it('Successfully delete comments', () => {
  64. cy.getByTestid('page-comment-button').click();
  65. cy.get('.page-comments').should('be.visible');
  66. cy.getByTestid('comment-delete-button').eq(0).click({force: true});
  67. cy.get('.modal-content').then($elem => $elem.is(':visible'));
  68. cy.get('.modal-footer > button:nth-child(3)').click();
  69. // Check update comment count
  70. commentCount -= 2
  71. cy.getByTestid('page-comment-button').contains(commentCount);
  72. cy.screenshot(`${ssPrefix}3-delete-comments`);
  73. });
  74. // Mention username in comment
  75. it('Successfully mention username in comment', () => {
  76. const username = '@adm';
  77. cy.getByTestid('page-comment-button').click();
  78. // Open comment editor
  79. cy.waitUntil(() => {
  80. // do
  81. cy.getByTestid('open-comment-editor-button').click();
  82. // wait until
  83. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  84. });
  85. cy.waitUntil(() => {
  86. // do
  87. cy.get('.CodeMirror').type(username);
  88. // wait until
  89. return cy.get('.CodeMirror-hints').then($elem => $elem.is(':visible'));
  90. });
  91. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}4-mention-username-found`) });
  92. // Click on mentioned username
  93. cy.get('.CodeMirror-hints > li').first().click();
  94. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}5-mention-username-mentioned`) });
  95. });
  96. it('Username not found when mention username in comment', () => {
  97. const username = '@user';
  98. cy.getByTestid('page-comment-button').click();
  99. // Open comment editor
  100. cy.waitUntil(() => {
  101. // do
  102. cy.getByTestid('open-comment-editor-button').click();
  103. // wait until
  104. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  105. });
  106. cy.waitUntil(() => {
  107. // do
  108. cy.get('.CodeMirror').type(username);
  109. // wait until
  110. return cy.get('.CodeMirror-hints').then($elem => $elem.is(':visible'));
  111. });
  112. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}6-mention-username-not-found`) });
  113. // Click on username not found hint
  114. cy.get('.CodeMirror-hints > li').first().click();
  115. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}7-mention-no-username-mentioned`) });
  116. });
  117. })