summaryrefslogtreecommitdiffstats
path: root/src/components/molecules/nav/pagination.stories.tsx
Commit message (Expand)AuthorAgeFilesLines
* chore: add a Pagination componentArmand Philippot2022-04-211-0/+175
6 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
describe('Settings', () => {
  beforeEach(() => {
    cy.visit('/');
  });

  it('should open and close a settings menu by clicking on a button', () => {
    cy.findByLabelText(/Fermer les réglages/i).should('not.exist');
    cy.findByLabelText(/Ouvrir les réglages/i).click();
    cy.findByLabelText(/Ouvrir les réglages/i).should('not.exist');
    cy.findByLabelText(/Fermer les réglages/i).click();
    cy.findByLabelText(/Fermer les réglages/i).should('not.exist');
    cy.findByLabelText(/Ouvrir les réglages/i).should('exist');
  });

  it('should open and close a tooltip by clicking on a button', () => {
    cy.findByLabelText(/Ouvrir les réglages/i).click();
    cy.findByText(/Ackee/).should('not.be.visible');
    cy.findByRole('button', { name: /Aide/i }).click();
    cy.findByText(/Ackee/).should('be.visible');
    cy.findByRole('button', { name: /Aide/i }).click();
    cy.findByText(/Ackee/).should('not.be.visible');
  });

  it('should change the current theme', () => {
    cy.findByLabelText(/Ouvrir les réglages/i).click();
    cy.findByRole('document')
      .parent()
      .then(($html) => {
        const initialTheme = $html.attr('data-theme');

        if (initialTheme === 'light') {
          cy.findByRole('radiogroup', { name: /Thème/i })
            .findByRole('radio', { name: /Thème clair/i })
            .should('be.checked');
          cy.findByRole('radiogroup', { name: /Thème/i })
            .findByRole('radio', { name: /Thème sombre/i })
            .should('not.be.checked')
            .check({ force: true }) // because of label
            .should('be.checked');
          cy.findByRole('radiogroup', { name: /Thème/i })
            .findByRole('radio', { name: /Thème clair/i })
            .should('not.be.checked');
          cy.findByRole('document')
            .parent()
            .should('have.attr', 'data-theme', 'dark')
            .then(() => {
              expect(localStorage.getItem('theme')).to.eq('dark');
            });
        } else {
          cy.findByRole('radiogroup', { name: /Thème/i })
            .findByRole('radio', { name: /Thème sombre/i })
            .should('be.checked');
          cy.findByRole('radiogroup', { name: /Thème/i })
            .findByRole('radio', { name: /Thème clair/i })
            .should('not.be.checked')
            .check({ force: true }) // because of label
            .should('be.checked');
          cy.findByRole('radiogroup', { name: /Thème/i })
            .findByRole('radio', { name: /Thème sombre/i })
            .should('not.be.checked');
          cy.findByRole('document')
            .parent()
            .should('have.attr', 'data-theme', 'light')
            .then(() => {
              expect(localStorage.getItem('theme')).to.eq('light');
            });
        }
      });
  });

  it('should change the Prism theme', () => {
    cy.findByLabelText(/Ouvrir les réglages/i).click();
    // We assume that the default theme is light theme.
    cy.findByRole('radiogroup', { name: /Blocs de code/i })
      .findByRole('radio', { name: /Thème sombre/i })
      .check({ force: true }) // because of label
      .should('be.checked')
      .then(() => {
        expect(localStorage.getItem('prismjs-color-scheme')).to.eq('"dark"');
      });
    cy.findByRole('radiogroup', { name: /Blocs de code/i })
      .findByRole('radio', { name: /Thème clair/i })
      .check({ force: true }) // because of label
      .should('be.checked')
      .then(() => {
        expect(localStorage.getItem('prismjs-color-scheme')).to.eq('"light"');
      });
  });

  it('should change the motion setting', () => {
    cy.findByLabelText(/Ouvrir les réglages/i).click();
    cy.findByRole('document')
      .parent()
      .then(($html) => {
        const initialValue = $html.attr('data-reduced-motion');

        if (initialValue === 'false') {
          cy.findByRole('radiogroup', { name: /Animations/i })
            .findByRole('radio', { name: /Marche/i })
            .should('be.checked');
          cy.findByRole('radiogroup', { name: /Animations/i })
            .findByRole('radio', { name: /Arrêt/i })
            .should('not.be.checked')
            .check({ force: true }) // because of label
            .should('be.checked');
          cy.findByRole('radiogroup', { name: /Animations/i })
            .findByRole('radio', { name: /Marche/i })
            .should('not.be.checked');
          cy.findByRole('document')
            .parent()
            .should('have.attr', 'data-reduced-motion', 'true')
            .then(() => {
              expect(localStorage.getItem('reduced-motion')).to.eq('true');
            });
        } else {
          cy.findByRole('radiogroup', { name: /Animations/i })
            .findByRole('radio', { name: /Arrêt/i })
            .should('be.checked');
          cy.findByRole('radiogroup', { name: /Animations/i })
            .findByRole('radio', { name: /Marche/i })
            .should('not.be.checked')
            .check({ force: true }) // because of label
            .should('be.checked');
          cy.findByRole('radiogroup', { name: /Animations/i })
            .findByRole('radio', { name: /Arrêt/i })
            .should('not.be.checked');
          cy.findByRole('document')
            .parent()
            .should('have.attr', 'data-reduced-motion', 'true')
            .then(() => {
              expect(localStorage.getItem('reduced-motion')).to.eq('true');
            });
        }
      });
  });

  it('should change the Ackee setting', () => {
    cy.findByLabelText(/Ouvrir les réglages/i)
      .click()
      .then(() => {
        const storedValue = localStorage.getItem('ackee-tracking');
        const parsedStoredValue = storedValue ? JSON.parse(storedValue) : '';

        if (parsedStoredValue === 'full') {
          cy.findByRole('radio', { name: /Complet/i }).should('be.checked');
          cy.findByRole('radio', { name: /Partiel/i })
            .should('not.be.checked')
            .check({ force: true }) // because of label
            .should('be.checked');
          cy.findByRole('radio', { name: /Complet/i })
            .should('not.be.checked')
            .then(() => {
              const newStoredValue = localStorage.getItem('ackee-tracking');
              const parsedNewStoredValue = newStoredValue
                ? JSON.parse(newStoredValue)
                : '';
              expect(parsedNewStoredValue).to.eq('partial');
            });
        } else {
          cy.findByRole('radio', { name: /Partiel/i }).should('be.checked');
          cy.findByRole('radio', { name: /Complet/i })
            .should('not.be.checked')
            .check({ force: true }) // because of label
            .should('be.checked');
          cy.findByRole('radio', { name: /Partiel/i })
            .should('not.be.checked')
            .then(() => {
              const newStoredValue = localStorage.getItem('ackee-tracking');
              const parsedNewStoredValue = newStoredValue
                ? JSON.parse(newStoredValue)
                : '';
              expect(parsedNewStoredValue).to.eq('full');
            });
        }
      });
  });
});