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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. context('Comment', () => {
  2. const ssPrefix = 'comments-';
  3. beforeEach(() => {
  4. // login
  5. cy.fixture("user-admin.json").then(user => {
  6. cy.login(user.username, user.password);
  7. });
  8. // visit page
  9. cy.visit('/comments');
  10. cy.collapseSidebar(true, true);
  11. cy.getByTestid('page-comment-button').click();
  12. })
  13. it('Successfully add comments', () => {
  14. const commetText = 'add comment';
  15. // Open comment editor
  16. cy.waitUntil(() => {
  17. // do
  18. cy.getByTestid('open-comment-editor-button').click();
  19. // wait until
  20. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  21. });
  22. cy.waitUntil(() => {
  23. // do
  24. cy.get('.CodeMirror').type(commetText);
  25. // wait until
  26. return cy.get('.CodeMirror-hints').then($elem => $elem.is(':visible'));
  27. });
  28. // Check update comment count
  29. cy.getByTestid('page-comment-button').get('span:nth-child(2)').contains(1);
  30. cy.screenshot(`${ssPrefix}1-add-comments`);
  31. });
  32. it('Successfully reply comments', () => {
  33. const commetText = 'reply comment';
  34. // Open reply comment editor
  35. cy.waitUntil(() => {
  36. // do
  37. cy.get('.btn-comment-reply').click();
  38. // wait until
  39. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  40. });
  41. cy.waitUntil(() => {
  42. // do
  43. cy.get('.CodeMirror').type(commetText);
  44. // wait until
  45. return cy.get('.CodeMirror-hints').then($elem => $elem.is(':visible'));
  46. });
  47. // Check update comment count
  48. cy.getByTestid('page-comment-button').get('span:nth-child(2)').contains(1);
  49. cy.screenshot(`${ssPrefix}2-reply-comments`);
  50. });
  51. // Mention username in comment
  52. it('Successfully mention username in comment', () => {
  53. const username = '@adm';
  54. // Open comment editor
  55. cy.waitUntil(() => {
  56. // do
  57. cy.getByTestid('open-comment-editor-button').click();
  58. // wait until
  59. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  60. });
  61. cy.waitUntil(() => {
  62. // do
  63. cy.get('.CodeMirror').type(username);
  64. // wait until
  65. return cy.get('.CodeMirror-hints').then($elem => $elem.is(':visible'));
  66. });
  67. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}3-mention-username-found`) });
  68. // Click on mentioned username
  69. cy.get('.CodeMirror-hints > li').first().click();
  70. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}4-mention-username-mentioned`) });
  71. });
  72. it('Username not found when mention username in comment', () => {
  73. const username = '@user';
  74. // Open comment editor
  75. cy.waitUntil(() => {
  76. // do
  77. cy.getByTestid('open-comment-editor-button').click();
  78. // wait until
  79. return cy.get('.comment-write').then($elem => $elem.is(':visible'));
  80. });
  81. cy.waitUntil(() => {
  82. // do
  83. cy.get('.CodeMirror').type(username);
  84. // wait until
  85. return cy.get('.CodeMirror-hints').then($elem => $elem.is(':visible'));
  86. });
  87. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}5-mention-username-not-found`) });
  88. // Click on username not found hint
  89. cy.get('.CodeMirror-hints > li').first().click();
  90. cy.get('#comments-container').within(() => { cy.screenshot(`${ssPrefix}6-mention-no-username-mentioned`) });
  91. });
  92. })