Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
extends: [
'@nextcloud/eslint-config',
],
globals: {
OCA: 'readonly',
OC: 'readonly',
},
overrides: [
{
files: ['src/__tests__/**/*'],
rules: {
'n/no-unpublished-import': 'off',
'jsdoc/require-jsdoc': 'off',
},
},
],
}
100 changes: 100 additions & 0 deletions .github/workflows/lint-eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: Lint eslint

on: pull_request

permissions:
contents: read

concurrency:
group: lint-eslint-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
changes:
runs-on: ubuntu-latest-low
permissions:
contents: read
pull-requests: read

outputs:
src: ${{ steps.changes.outputs.src}}

steps:
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
id: changes
continue-on-error: true
with:
filters: |
src:
- '.github/workflows/**'
- 'src/**'
- 'appinfo/info.xml'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '.eslintrc.*'
- '.eslintignore'
- '**.js'
- '**.ts'
- '**.vue'

lint:
runs-on: ubuntu-latest

needs: changes
if: needs.changes.outputs.src != 'false'

name: NPM lint

steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false

- name: Read package.json node and npm engines version
uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
id: versions
with:
fallbackNode: '^24'
fallbackNpm: '^11.3'

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g 'npm@${{ steps.versions.outputs.npmVersion }}'

- name: Install dependencies
env:
CYPRESS_INSTALL_BINARY: 0
PUPPETEER_SKIP_DOWNLOAD: true
run: npm ci

- name: Lint
run: npm run lint

summary:
permissions:
contents: none
runs-on: ubuntu-latest-low
needs: [changes, lint]

if: always()

# This is the summary, we just avoid to rename it so that branch protection rules still match
name: eslint

steps:
- name: Summary status
run: if ${{ needs.changes.outputs.src != 'false' && needs.lint.result != 'success' }}; then exit 1; fi
104 changes: 104 additions & 0 deletions .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: Node tests

on:
pull_request:
push:
branches:
- main
- master
- stable*

permissions:
contents: read

concurrency:
group: node-tests-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
changes:
runs-on: ubuntu-latest-low
permissions:
contents: read
pull-requests: read

outputs:
src: ${{ steps.changes.outputs.src}}

steps:
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
id: changes
continue-on-error: true
with:
filters: |
src:
- '.github/workflows/**'
- 'src/**'
- 'appinfo/info.xml'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- 'vitest.config.*'
- '**.js'
- '**.ts'
- '**.vue'

test:
runs-on: ubuntu-latest

needs: changes
if: needs.changes.outputs.src != 'false'

steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false

- name: Read package.json node and npm engines version
uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
id: versions
with:
fallbackNode: '^24'
fallbackNpm: '^11.3'

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g 'npm@${{ steps.versions.outputs.npmVersion }}'

- name: Install dependencies & build
env:
CYPRESS_INSTALL_BINARY: 0
PUPPETEER_SKIP_DOWNLOAD: true
run: |
npm ci
npm run build --if-present

- name: Test
run: npm run test

summary:
permissions:
contents: none
runs-on: ubuntu-latest-low
needs: [changes, test]

if: always()

name: npm-test-summary

steps:
- name: Summary status
run: if ${{ needs.changes.outputs.src != 'false' && needs.test.result != 'success' }}; then exit 1; fi
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
"build": "vite --mode production build",
"dev": "vite --mode development build",
"watch": "vite --mode development build --watch",
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.vue,.ts src",
"test": "vitest run",
"test:watch": "vitest"
},
"dependencies": {
"@mdi/svg": "^7.3.67",
"@nextcloud/auth": "^2.5.0",
"@nextcloud/axios": "^2.4.0",
"@nextcloud/dialogs": "^5.0.0",
"@nextcloud/event-bus": "^3.1.0",
Expand All @@ -37,6 +39,8 @@
"@nextcloud/l10n": "^3.0.0",
"@nextcloud/logger": "^3.0.0",
"@nextcloud/paths": "^3.0.0",
"@nextcloud/router": "^3.1.0",
"@nextcloud/sharing": "^0.3.0",
"jszip": "^3.10.1"
},
"devDependencies": {
Expand Down
111 changes: 111 additions & 0 deletions src/__tests__/MindMap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { shallowMount } from '@vue/test-utils'
import MindMap from '../views/MindMap.vue'

vi.mock('@nextcloud/l10n', () => ({ getLanguage: () => 'en' }))
vi.mock('@nextcloud/router', () => ({
generateUrl: (path, params = {}) =>
Object.entries(params).reduce(
(acc, [k, v]) => acc.replace(`{${k}}`, v ?? ''),
path,
),
}))
vi.mock('@nextcloud/sharing/public', () => ({
isPublicShare: vi.fn(() => false),
getSharingToken: () => '',
}))

// Viewer mixin that supplies the props/methods the component expects
const viewerMixin = {
data() {
return {
fileList: [],
fileid: null,
source: null,
davPath: null,
}
},
methods: {
doneLoading() {},
handleWebviewerloaded() {},
},
}

function mountMindMap(dataOverrides = {}) {
return shallowMount(MindMap, {
mixins: [
{
...viewerMixin,
data() {
return { ...viewerMixin.data(), ...dataOverrides }
},
},
],
})
}

describe('MindMap.vue', () => {
beforeEach(() => {
window.OCA = { FilesMindMap: { setFile: vi.fn() } }
})

afterEach(() => {
delete window.OCA
})

it('renders an iframe element', () => {
const wrapper = mountMindMap()
expect(wrapper.find('iframe').exists()).toBe(true)
})

describe('iframeSrc computed property', () => {
it('uses source when available', () => {
const wrapper = mountMindMap({
source: '/remote.php/dav/files/user/test.km',
})
expect(wrapper.vm.iframeSrc).toContain('/remote.php/dav/files/user/test.km')
})

it('falls back to davPath when source is null', () => {
const wrapper = mountMindMap({
source: null,
davPath: '/dav/path/test.km',
})
expect(wrapper.vm.iframeSrc).toContain('/dav/path/test.km')
})
})

describe('file computed property', () => {
it('returns the file whose fileid matches the current fileid', () => {
const file = { fileid: 7, name: 'test.km' }
const wrapper = mountMindMap({ fileList: [file], fileid: 7 })
expect(wrapper.vm.file).toBe(file)
})

it('returns undefined when no file matches', () => {
const wrapper = mountMindMap({
fileList: [{ fileid: 1, name: 'other.km' }],
fileid: 99,
})
expect(wrapper.vm.file).toBeUndefined()
})
})

describe('lifecycle hooks', () => {
it('calls OCA.FilesMindMap.setFile on mount', () => {
mountMindMap({
fileList: [{ fileid: 3, name: 'test.km' }],
fileid: 3,
})
expect(window.OCA.FilesMindMap.setFile).toHaveBeenCalled()
})

it('removes the webviewerloaded event listener on destroy', () => {
const spy = vi.spyOn(document, 'removeEventListener')
const wrapper = mountMindMap()
wrapper.destroy()
expect(spy).toHaveBeenCalledWith('webviewerloaded', expect.anything())
spy.mockRestore()
})
})
})
Loading
Loading