123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- import FolderSvg from '@mdi/svg/svg/folder.svg'
- import ShareSvg from '@mdi/svg/svg/share-variant.svg'
- import { createTestingPinia } from '@pinia/testing'
-
- import NavigationService from '../services/Navigation'
- import NavigationView from './Navigation.vue'
- import router from '../router/router.js'
- import { useViewConfigStore } from '../store/viewConfig'
-
- describe('Navigation renders', () => {
- const Navigation = new NavigationService() as NavigationService
-
- before(() => {
- cy.mockInitialState('files', 'storageStats', {
- used: 1000 * 1000 * 1000,
- quota: -1,
- })
- })
-
- after(() => cy.unmockInitialState())
-
- it('renders', () => {
- cy.mount(NavigationView, {
- propsData: {
- Navigation,
- },
- global: {
- plugins: [createTestingPinia({
- createSpy: cy.spy,
- })],
- },
- })
-
- cy.get('[data-cy-files-navigation]').should('be.visible')
- cy.get('[data-cy-files-navigation-settings-quota]').should('be.visible')
- cy.get('[data-cy-files-navigation-settings-button]').should('be.visible')
- })
- })
-
- describe('Navigation API', () => {
- const Navigation = new NavigationService() as NavigationService
-
- it('Check API entries rendering', () => {
- Navigation.register({
- id: 'files',
- name: 'Files',
- getContents: () => Promise.resolve(),
- icon: FolderSvg,
- order: 1,
- })
-
- cy.mount(NavigationView, {
- propsData: {
- Navigation,
- },
- global: {
- plugins: [createTestingPinia({
- createSpy: cy.spy,
- })],
- },
- router,
- })
-
- cy.get('[data-cy-files-navigation]').should('be.visible')
- cy.get('[data-cy-files-navigation-item]').should('have.length', 1)
- cy.get('[data-cy-files-navigation-item="files"]').should('be.visible')
- cy.get('[data-cy-files-navigation-item="files"]').should('contain.text', 'Files')
- })
-
- it('Adds a new entry and render', () => {
- Navigation.register({
- id: 'sharing',
- name: 'Sharing',
- getContents: () => Promise.resolve(),
- icon: ShareSvg,
- order: 2,
- })
-
- cy.mount(NavigationView, {
- propsData: {
- Navigation,
- },
- global: {
- plugins: [createTestingPinia({
- createSpy: cy.spy,
- })],
- },
- router,
- })
-
- cy.get('[data-cy-files-navigation]').should('be.visible')
- cy.get('[data-cy-files-navigation-item]').should('have.length', 2)
- cy.get('[data-cy-files-navigation-item="sharing"]').should('be.visible')
- cy.get('[data-cy-files-navigation-item="sharing"]').should('contain.text', 'Sharing')
- })
-
- it('Adds a new children, render and open menu', () => {
- Navigation.register({
- id: 'sharingin',
- name: 'Shared with me',
- getContents: () => Promise.resolve(),
- parent: 'sharing',
- icon: ShareSvg,
- order: 1,
- })
-
- cy.mount(NavigationView, {
- propsData: {
- Navigation,
- },
- global: {
- plugins: [createTestingPinia({
- createSpy: cy.spy,
- })],
- },
- router,
- })
-
- cy.wrap(useViewConfigStore()).as('viewConfigStore')
-
- cy.get('[data-cy-files-navigation]').should('be.visible')
- cy.get('[data-cy-files-navigation-item]').should('have.length', 3)
-
- // Toggle the sharing entry children
- cy.get('[data-cy-files-navigation-item="sharing"] button.icon-collapse').should('exist')
- cy.get('[data-cy-files-navigation-item="sharing"] button.icon-collapse').click({ force: true })
-
- // Expect store update to be called
- cy.get('@viewConfigStore').its('update').should('have.been.calledWith', 'sharing', 'expanded', true)
-
- // Validate children
- cy.get('[data-cy-files-navigation-item="sharingin"]').should('be.visible')
- cy.get('[data-cy-files-navigation-item="sharingin"]').should('contain.text', 'Shared with me')
-
- // Toggle the sharing entry children 🇦again
- cy.get('[data-cy-files-navigation-item="sharing"] button.icon-collapse').click({ force: true })
- cy.get('[data-cy-files-navigation-item="sharingin"]').should('not.be.visible')
-
- // Expect store update to be called
- cy.get('@viewConfigStore').its('update').should('have.been.calledWith', 'sharing', 'expanded', false)
- })
-
- it('Throws when adding a duplicate entry', () => {
- expect(() => {
- Navigation.register({
- id: 'files',
- name: 'Files',
- getContents: () => Promise.resolve(),
- icon: FolderSvg,
- order: 1,
- })
- }).to.throw('Navigation id files is already registered')
- })
- })
-
- describe('Quota rendering', () => {
- const Navigation = new NavigationService()
-
- afterEach(() => cy.unmockInitialState())
-
- it('Unknown quota', () => {
- cy.mount(NavigationView, {
- propsData: {
- Navigation,
- },
- global: {
- plugins: [createTestingPinia({
- createSpy: cy.spy,
- })],
- },
- })
-
- cy.get('[data-cy-files-navigation-settings-quota]').should('not.exist')
- })
-
- it('Unlimited quota', () => {
- cy.mockInitialState('files', 'storageStats', {
- used: 1000 * 1000 * 1000,
- quota: -1,
- })
-
- cy.mount(NavigationView, {
- propsData: {
- Navigation,
- },
- global: {
- plugins: [createTestingPinia({
- createSpy: cy.spy,
- })],
- },
- })
-
- cy.get('[data-cy-files-navigation-settings-quota]').should('be.visible')
- cy.get('[data-cy-files-navigation-settings-quota]').should('contain.text', '1 GB used')
- cy.get('[data-cy-files-navigation-settings-quota] progress').should('not.exist')
- })
-
- it('Non-reached quota', () => {
- cy.mockInitialState('files', 'storageStats', {
- used: 1000 * 1000 * 1000,
- quota: 5 * 1000 * 1000 * 1000,
- relative: 20, // percent
- })
-
- cy.mount(NavigationView, {
- propsData: {
- Navigation,
- },
- global: {
- plugins: [createTestingPinia({
- createSpy: cy.spy,
- })],
- },
- })
-
- cy.get('[data-cy-files-navigation-settings-quota]').should('be.visible')
- cy.get('[data-cy-files-navigation-settings-quota]').should('contain.text', '1 GB of 5 GB used')
- cy.get('[data-cy-files-navigation-settings-quota] progress').should('be.visible')
- cy.get('[data-cy-files-navigation-settings-quota] progress').should('have.attr', 'value', '20')
- })
-
- it('Reached quota', () => {
- cy.mockInitialState('files', 'storageStats', {
- used: 5 * 1000 * 1000 * 1000,
- quota: 1000 * 1000 * 1000,
- relative: 500, // percent
- })
-
- cy.mount(NavigationView, {
- propsData: {
- Navigation,
- },
- global: {
- plugins: [createTestingPinia({
- createSpy: cy.spy,
- })],
- },
- })
-
- cy.get('[data-cy-files-navigation-settings-quota]').should('be.visible')
- cy.get('[data-cy-files-navigation-settings-quota]').should('contain.text', '5 GB of 1 GB used')
- cy.get('[data-cy-files-navigation-settings-quota] progress').should('be.visible')
- cy.get('[data-cy-files-navigation-settings-quota] progress').should('have.attr', 'value', '100') // progress max is 100
- })
- })
|