ds-nav-page-switcher.spec.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { DsNavPageSwitcher } from '../../../../../frontend/js/shared/components/sidebar/ds-nav-page-switcher'
  2. import { SplitTestProvider } from '@/shared/context/split-test-context'
  3. import { UserSettingsProvider } from '@/shared/context/user-settings-context'
  4. function mountDsNavPageSwitcher(
  5. props: React.ComponentProps<typeof DsNavPageSwitcher>
  6. ) {
  7. cy.mount(
  8. <SplitTestProvider>
  9. <UserSettingsProvider>
  10. <DsNavPageSwitcher {...props} />
  11. </UserSettingsProvider>
  12. </SplitTestProvider>
  13. )
  14. }
  15. describe('<DsNavPageSwitcher />', function () {
  16. describe('activePage="library"', function () {
  17. beforeEach(function () {
  18. mountDsNavPageSwitcher({ activePage: 'library' })
  19. })
  20. it('marks the Library link as active', function () {
  21. cy.findByRole('link', { name: /library/i }).should('have.class', 'active')
  22. })
  23. it('does not mark the Projects link as active', function () {
  24. cy.findByRole('link', { name: /projects/i }).should(
  25. 'not.have.class',
  26. 'active'
  27. )
  28. })
  29. it('sets aria-current on the Library link', function () {
  30. cy.findByRole('link', { name: /library/i }).should(
  31. 'have.attr',
  32. 'aria-current',
  33. 'page'
  34. )
  35. })
  36. it('does not set aria-current on the Projects link', function () {
  37. cy.findByRole('link', { name: /projects/i }).should(
  38. 'not.have.attr',
  39. 'aria-current'
  40. )
  41. })
  42. it('renders the logo', function () {
  43. cy.get('.ds-nav-page-switcher-logo img').should('exist')
  44. })
  45. })
  46. describe('activePage="projects"', function () {
  47. beforeEach(function () {
  48. mountDsNavPageSwitcher({ activePage: 'projects' })
  49. })
  50. it('marks the Projects link as active', function () {
  51. cy.findByRole('link', { name: /projects/i }).should(
  52. 'have.class',
  53. 'active'
  54. )
  55. })
  56. it('does not mark the Library link as active', function () {
  57. cy.findByRole('link', { name: /library/i }).should(
  58. 'not.have.class',
  59. 'active'
  60. )
  61. })
  62. it('renders the logo', function () {
  63. cy.get('.ds-nav-page-switcher-logo img').should('exist')
  64. })
  65. })
  66. describe('link hrefs', function () {
  67. beforeEach(function () {
  68. mountDsNavPageSwitcher({ activePage: 'library' })
  69. })
  70. it('Library link points to /library', function () {
  71. cy.findByRole('link', { name: /library/i }).should(
  72. 'have.attr',
  73. 'href',
  74. '/library'
  75. )
  76. })
  77. it('Projects link points to /project', function () {
  78. cy.findByRole('link', { name: /projects/i }).should(
  79. 'have.attr',
  80. 'href',
  81. '/project'
  82. )
  83. })
  84. })
  85. describe('showLogo={false}', function () {
  86. beforeEach(function () {
  87. mountDsNavPageSwitcher({ activePage: 'projects', showLogo: false })
  88. })
  89. it('does not render the logo', function () {
  90. cy.get('.ds-nav-page-switcher-logo').should('not.exist')
  91. })
  92. it('still renders both nav links', function () {
  93. cy.findByRole('link', { name: /library/i }).should('exist')
  94. cy.findByRole('link', { name: /projects/i }).should('exist')
  95. })
  96. })
  97. })