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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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('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. })
  28. it('Successfully add comments', () => {
  29. const commetText = 'add comment';
  30. cy.getByTestid('page-comment-button').click();
  31. // Open comment editor
  32. cy.waitUntil(() => {
  33. // do
  34. cy.getByTestid('open-comment-editor-button').click();
  35. // wait until
  36. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  37. });
  38. cy.get('.CodeMirror').type(commetText);
  39. cy.getByTestid("comment-submit-button").eq(0).click();
  40. // Check update comment count
  41. commentCount += 1
  42. cy.getByTestid('page-comment-button').contains(commentCount);
  43. cy.screenshot(`${ssPrefix}1-add-comments`);
  44. });
  45. it('Successfully reply comments', () => {
  46. const commetText = 'reply comment';
  47. cy.getByTestid('page-comment-button').click();
  48. // Open reply comment editor
  49. cy.waitUntil(() => {
  50. // do
  51. cy.getByTestid('comment-reply-button').eq(0).click();
  52. // wait until
  53. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  54. });
  55. cy.get('.CodeMirror').type(commetText);
  56. cy.getByTestid("comment-submit-button").eq(0).click();
  57. // Check update comment count
  58. commentCount += 1
  59. cy.getByTestid('page-comment-button').contains(commentCount);
  60. cy.screenshot(`${ssPrefix}2-reply-comments`);
  61. });
  62. it('Successfully delete comments', () => {
  63. cy.getByTestid('page-comment-button').click();
  64. cy.get('.page-comments').should('be.visible');
  65. cy.getByTestid('comment-delete-button').eq(0).click({force: true});
  66. cy.get('.modal-content').then($elem => $elem.is(':visible'));
  67. cy.get('.modal-footer > button:nth-child(3)').click();
  68. // Check update comment count
  69. commentCount -= 2
  70. cy.getByTestid('page-comment-button').contains(commentCount);
  71. cy.screenshot(`${ssPrefix}3-delete-comments`);
  72. });
  73. // Mention username in comment
  74. it('Successfully mention username in comment', () => {
  75. const username = '@adm';
  76. cy.getByTestid('page-comment-button').click();
  77. // Open comment editor
  78. cy.waitUntil(() => {
  79. // do
  80. cy.getByTestid('open-comment-editor-button').click();
  81. // wait until
  82. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  83. });
  84. cy.appendTextToEditorUntilContains(username);
  85. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}4-mention-username-found`) });
  86. // Click on mentioned username
  87. cy.get('.CodeMirror-hints > li').first().click();
  88. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}5-mention-username-mentioned`) });
  89. });
  90. it('Username not found when mention username in comment', () => {
  91. const username = '@user';
  92. cy.getByTestid('page-comment-button').click();
  93. // Open comment editor
  94. cy.waitUntil(() => {
  95. // do
  96. cy.getByTestid('open-comment-editor-button').click();
  97. // wait until
  98. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  99. });
  100. cy.appendTextToEditorUntilContains(username);
  101. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}6-mention-username-not-found`) });
  102. // Click on username not found hint
  103. cy.get('.CodeMirror-hints > li').first().click();
  104. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}7-mention-no-username-mentioned`) });
  105. });
  106. })