20-basic-features--sticky-features.cy.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. context('Access to any page', () => {
  2. const ssPrefix = 'subnav-and-fab-';
  3. beforeEach(() => {
  4. // login
  5. cy.fixture("user-admin.json").then(user => {
  6. cy.login(user.username, user.password);
  7. });
  8. cy.visit('/');
  9. cy.waitUntilSkeletonDisappear();
  10. cy.collapseSidebar(true, true);
  11. });
  12. it('Subnavigation and fab displays changes on scroll down and up', () => {
  13. cy.waitUntil(() => {
  14. // do
  15. // Scroll the window 250px down is enough to trigger sticky effect
  16. cy.scrollTo(0, 250);
  17. // wait until
  18. return cy.getByTestid('grw-subnav-switcher').then($elem => !$elem.hasClass('grw-subnav-switcher-hidden'));
  19. });
  20. // wait until fab visible
  21. cy.waitUntil(() => cy.getByTestid('grw-fab-page-create-button').then($elem => $elem.hasClass('visible')));
  22. cy.waitUntilSkeletonDisappear();
  23. cy.screenshot(`${ssPrefix}visible-on-scroll-down`);
  24. cy.waitUntil(() => {
  25. // do
  26. // Scroll the window back to top
  27. cy.scrollTo(0, 0);
  28. // wait until
  29. return cy.waitUntil(() => cy.getByTestid('grw-subnav-switcher').then($elem => $elem.hasClass('grw-subnav-switcher-hidden')));
  30. });
  31. // wait until fab invisible
  32. cy.waitUntil(() => cy.getByTestid('grw-fab-page-create-button').then($elem => $elem.hasClass('invisible')));
  33. cy.screenshot(`${ssPrefix}invisible-on-scroll-top`);
  34. });
  35. it('Subnavigation and fab are not displayed when move to other pages', () => {
  36. cy.waitUntil(() => {
  37. // do
  38. // Scroll the window 250px down is enough to trigger sticky effect
  39. cy.scrollTo(0, 250);
  40. // wait until
  41. return () => cy.getByTestid('grw-subnav-switcher').then($elem => !$elem.hasClass('grw-subnav-switcher-hidden'));
  42. });
  43. cy.waitUntil(() => cy.getByTestid('grw-fab-page-create-button').then($elem => $elem.hasClass('visible')));
  44. // Move to /Sandbox page
  45. cy.visit('/Sandbox');
  46. cy.waitUntilSkeletonDisappear();
  47. cy.collapseSidebar(true);
  48. cy.waitUntil(() => cy.getByTestid('grw-fab-page-create-button').then($elem => $elem.hasClass('invisible')));
  49. cy.waitUntil(() => cy.getByTestid('grw-subnav-switcher').then($elem => $elem.hasClass('grw-subnav-switcher-hidden')));
  50. cy.screenshot(`${ssPrefix}not-visible-on-move-to-other-pages`);
  51. });
  52. it('Able to open create page modal from fab', () => {
  53. cy.waitUntil(() => {
  54. // do
  55. // Scroll the window back to top
  56. cy.scrollTo(0, 250);
  57. // wait until
  58. return cy.getByTestid('grw-fab-page-create-button')
  59. .should('have.class', 'visible')
  60. .within(() => {
  61. cy.get('.btn-create-page').click();
  62. return true;
  63. });
  64. });
  65. cy.getByTestid('page-create-modal').should('be.visible').within(() => {
  66. cy.screenshot(`${ssPrefix}new-page-modal-opened-from-fab`);
  67. cy.get('button.close').click();
  68. });
  69. });
  70. it('Able to scroll page to top from fab', () => {
  71. // Initial scroll down
  72. cy.waitUntil(() => {
  73. // do
  74. // Scroll the window 250px down is enough to trigger sticky effect
  75. cy.scrollTo(0, 250);
  76. // wait until
  77. return cy.getByTestid('grw-fab-return-to-top')
  78. .should('have.class', 'visible')
  79. .then(() => {
  80. cy.waitUntil(() => {
  81. cy.get('.btn-scroll-to-top').click();
  82. return cy.getByTestid('grw-fab-return-to-top').should('have.class', 'invisible');
  83. });
  84. });
  85. });
  86. cy.waitUntilSkeletonDisappear();
  87. cy.screenshot(`${ssPrefix}scroll-page-to-top`);
  88. });
  89. it('Able to click buttons on subnavigation switcher when sticky', () => {
  90. cy.waitUntil(() => {
  91. // do
  92. // Scroll the window 250px down is enough to trigger sticky effect
  93. cy.scrollTo(0, 250);
  94. // wait until
  95. return cy.getByTestid('grw-subnav-switcher').then($elem => !$elem.hasClass('grw-subnav-switcher-hidden'));
  96. });
  97. cy.waitUntil(() => {
  98. cy.getByTestid('grw-subnav-switcher').within(() => {
  99. cy.getByTestid('editor-button').as('editorButton').should('be.visible');
  100. cy.get('@editorButton').click();
  101. });
  102. return cy.get('.layout-root').then($elem => $elem.hasClass('editing'));
  103. });
  104. cy.get('.grw-editor-navbar-bottom').should('be.visible');
  105. cy.get('.CodeMirror').should('be.visible');
  106. cy.screenshot(`${ssPrefix}open-editor-when-sticky`);
  107. });
  108. it('Subnavigation is sticky when on small window', () => {
  109. cy.waitUntil(() => {
  110. // do
  111. // Scroll the window 500px down
  112. cy.scrollTo(0, 500);
  113. // wait until
  114. return cy.getByTestid('grw-subnav-switcher').then($elem => !$elem.hasClass('grw-subnav-switcher-hidden'));
  115. });
  116. cy.waitUntilSkeletonDisappear();
  117. cy.viewport(600, 1024);
  118. cy.getByTestid('grw-subnav-switcher').within(() => {
  119. cy.get('#grw-page-editor-mode-manager').should('be.visible');
  120. })
  121. cy.screenshot(`${ssPrefix}sticky-on-small-window`);
  122. });
  123. });