You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Navigation.cy.ts 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import FolderSvg from '@mdi/svg/svg/folder.svg'
  2. import ShareSvg from '@mdi/svg/svg/share-variant.svg'
  3. import { createTestingPinia } from '@pinia/testing'
  4. import NavigationService from '../services/Navigation'
  5. import NavigationView from './Navigation.vue'
  6. import router from '../router/router.js'
  7. import { useViewConfigStore } from '../store/viewConfig'
  8. describe('Navigation renders', () => {
  9. const Navigation = new NavigationService() as NavigationService
  10. before(() => {
  11. cy.mockInitialState('files', 'storageStats', {
  12. used: 1000 * 1000 * 1000,
  13. quota: -1,
  14. })
  15. })
  16. after(() => cy.unmockInitialState())
  17. it('renders', () => {
  18. cy.mount(NavigationView, {
  19. propsData: {
  20. Navigation,
  21. },
  22. global: {
  23. plugins: [createTestingPinia({
  24. createSpy: cy.spy,
  25. })],
  26. },
  27. })
  28. cy.get('[data-cy-files-navigation]').should('be.visible')
  29. cy.get('[data-cy-files-navigation-settings-quota]').should('be.visible')
  30. cy.get('[data-cy-files-navigation-settings-button]').should('be.visible')
  31. })
  32. })
  33. describe('Navigation API', () => {
  34. const Navigation = new NavigationService() as NavigationService
  35. it('Check API entries rendering', () => {
  36. Navigation.register({
  37. id: 'files',
  38. name: 'Files',
  39. getContents: () => Promise.resolve(),
  40. icon: FolderSvg,
  41. order: 1,
  42. })
  43. cy.mount(NavigationView, {
  44. propsData: {
  45. Navigation,
  46. },
  47. global: {
  48. plugins: [createTestingPinia({
  49. createSpy: cy.spy,
  50. })],
  51. },
  52. router,
  53. })
  54. cy.get('[data-cy-files-navigation]').should('be.visible')
  55. cy.get('[data-cy-files-navigation-item]').should('have.length', 1)
  56. cy.get('[data-cy-files-navigation-item="files"]').should('be.visible')
  57. cy.get('[data-cy-files-navigation-item="files"]').should('contain.text', 'Files')
  58. })
  59. it('Adds a new entry and render', () => {
  60. Navigation.register({
  61. id: 'sharing',
  62. name: 'Sharing',
  63. getContents: () => Promise.resolve(),
  64. icon: ShareSvg,
  65. order: 2,
  66. })
  67. cy.mount(NavigationView, {
  68. propsData: {
  69. Navigation,
  70. },
  71. global: {
  72. plugins: [createTestingPinia({
  73. createSpy: cy.spy,
  74. })],
  75. },
  76. router,
  77. })
  78. cy.get('[data-cy-files-navigation]').should('be.visible')
  79. cy.get('[data-cy-files-navigation-item]').should('have.length', 2)
  80. cy.get('[data-cy-files-navigation-item="sharing"]').should('be.visible')
  81. cy.get('[data-cy-files-navigation-item="sharing"]').should('contain.text', 'Sharing')
  82. })
  83. it('Adds a new children, render and open menu', () => {
  84. Navigation.register({
  85. id: 'sharingin',
  86. name: 'Shared with me',
  87. getContents: () => Promise.resolve(),
  88. parent: 'sharing',
  89. icon: ShareSvg,
  90. order: 1,
  91. })
  92. cy.mount(NavigationView, {
  93. propsData: {
  94. Navigation,
  95. },
  96. global: {
  97. plugins: [createTestingPinia({
  98. createSpy: cy.spy,
  99. })],
  100. },
  101. router,
  102. })
  103. cy.wrap(useViewConfigStore()).as('viewConfigStore')
  104. cy.get('[data-cy-files-navigation]').should('be.visible')
  105. cy.get('[data-cy-files-navigation-item]').should('have.length', 3)
  106. // Toggle the sharing entry children
  107. cy.get('[data-cy-files-navigation-item="sharing"] button.icon-collapse').should('exist')
  108. cy.get('[data-cy-files-navigation-item="sharing"] button.icon-collapse').click({ force: true })
  109. // Expect store update to be called
  110. cy.get('@viewConfigStore').its('update').should('have.been.calledWith', 'sharing', 'expanded', true)
  111. // Validate children
  112. cy.get('[data-cy-files-navigation-item="sharingin"]').should('be.visible')
  113. cy.get('[data-cy-files-navigation-item="sharingin"]').should('contain.text', 'Shared with me')
  114. // Toggle the sharing entry children 🇦again
  115. cy.get('[data-cy-files-navigation-item="sharing"] button.icon-collapse').click({ force: true })
  116. cy.get('[data-cy-files-navigation-item="sharingin"]').should('not.be.visible')
  117. // Expect store update to be called
  118. cy.get('@viewConfigStore').its('update').should('have.been.calledWith', 'sharing', 'expanded', false)
  119. })
  120. it('Throws when adding a duplicate entry', () => {
  121. expect(() => {
  122. Navigation.register({
  123. id: 'files',
  124. name: 'Files',
  125. getContents: () => Promise.resolve(),
  126. icon: FolderSvg,
  127. order: 1,
  128. })
  129. }).to.throw('Navigation id files is already registered')
  130. })
  131. })
  132. describe('Quota rendering', () => {
  133. const Navigation = new NavigationService()
  134. afterEach(() => cy.unmockInitialState())
  135. it('Unknown quota', () => {
  136. cy.mount(NavigationView, {
  137. propsData: {
  138. Navigation,
  139. },
  140. global: {
  141. plugins: [createTestingPinia({
  142. createSpy: cy.spy,
  143. })],
  144. },
  145. })
  146. cy.get('[data-cy-files-navigation-settings-quota]').should('not.exist')
  147. })
  148. it('Unlimited quota', () => {
  149. cy.mockInitialState('files', 'storageStats', {
  150. used: 1000 * 1000 * 1000,
  151. quota: -1,
  152. })
  153. cy.mount(NavigationView, {
  154. propsData: {
  155. Navigation,
  156. },
  157. global: {
  158. plugins: [createTestingPinia({
  159. createSpy: cy.spy,
  160. })],
  161. },
  162. })
  163. cy.get('[data-cy-files-navigation-settings-quota]').should('be.visible')
  164. cy.get('[data-cy-files-navigation-settings-quota]').should('contain.text', '1 GB used')
  165. cy.get('[data-cy-files-navigation-settings-quota] progress').should('not.exist')
  166. })
  167. it('Non-reached quota', () => {
  168. cy.mockInitialState('files', 'storageStats', {
  169. used: 1000 * 1000 * 1000,
  170. quota: 5 * 1000 * 1000 * 1000,
  171. relative: 20, // percent
  172. })
  173. cy.mount(NavigationView, {
  174. propsData: {
  175. Navigation,
  176. },
  177. global: {
  178. plugins: [createTestingPinia({
  179. createSpy: cy.spy,
  180. })],
  181. },
  182. })
  183. cy.get('[data-cy-files-navigation-settings-quota]').should('be.visible')
  184. cy.get('[data-cy-files-navigation-settings-quota]').should('contain.text', '1 GB of 5 GB used')
  185. cy.get('[data-cy-files-navigation-settings-quota] progress').should('be.visible')
  186. cy.get('[data-cy-files-navigation-settings-quota] progress').should('have.attr', 'value', '20')
  187. })
  188. it('Reached quota', () => {
  189. cy.mockInitialState('files', 'storageStats', {
  190. used: 5 * 1000 * 1000 * 1000,
  191. quota: 1000 * 1000 * 1000,
  192. relative: 500, // percent
  193. })
  194. cy.mount(NavigationView, {
  195. propsData: {
  196. Navigation,
  197. },
  198. global: {
  199. plugins: [createTestingPinia({
  200. createSpy: cy.spy,
  201. })],
  202. },
  203. })
  204. cy.get('[data-cy-files-navigation-settings-quota]').should('be.visible')
  205. cy.get('[data-cy-files-navigation-settings-quota]').should('contain.text', '5 GB of 1 GB used')
  206. cy.get('[data-cy-files-navigation-settings-quota] progress').should('be.visible')
  207. cy.get('[data-cy-files-navigation-settings-quota] progress').should('have.attr', 'value', '100') // progress max is 100
  208. })
  209. })