diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f1de366..06dc84ef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added +- Show new OpenProject work package display ID if available [#1071](https://github.com/nextcloud/integration_openproject/pull/1071) + ### Fixed - Fix: Unnecessary 404 requests when searching OpenProject work packages [#1070](https://github.com/nextcloud/integration_openproject/pull/1070) diff --git a/jest.config.js b/jest.config.js index 32665f12d..d35a03e10 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,6 +5,8 @@ module.exports = { testMatch: ['**/tests/**/*.spec.{js,ts}'], + testPathIgnorePatterns: ['/node_modules/', '/server/'], + modulePathIgnorePatterns: ['/server/', '/dev/'], moduleNameMapper: { '\\.(scss)$': '/tests/jest/stubs/empty.js', '@nextcloud/l10n/gettext': '/tests/jest/__mocks__/@nextcloud/l10n.js', diff --git a/src/components/tab/WorkPackage.vue b/src/components/tab/WorkPackage.vue index 3da629074..c04500c1a 100644 --- a/src/components/tab/WorkPackage.vue +++ b/src/components/tab/WorkPackage.vue @@ -14,7 +14,7 @@
- #{{ workpackage.id }} - {{ workpackage.project }} + {{ getWPDisplayID }} - {{ workpackage.project }}
@@ -70,6 +70,16 @@ export default { wpStatusFontColor: '#FFFFFF', wpStatusBorder: '0', }), + computed: { + getWPDisplayID() { + const id = this.workpackage.displayId + const isNumericId = /^\d+$/.test(id) + if (isNumericId) { + return '#' + id + } + return id + }, + }, created() { this.setWPTypeTextStroke() this.setWPStatusFontColor() diff --git a/src/utils/workpackageHelper.js b/src/utils/workpackageHelper.js index b117cfae6..d47116822 100644 --- a/src/utils/workpackageHelper.js +++ b/src/utils/workpackageHelper.js @@ -81,6 +81,7 @@ export const workpackageHelper = { return { id: workPackage.id, + displayId: workPackage.displayId || workPackage.id.toString(), subject: workPackage.subject, project: workPackage._links.project.title, projectId, diff --git a/tests/jest/components/tab/WorkPackage.spec.js b/tests/jest/components/tab/WorkPackage.spec.js index f5b162fbb..765e3a93a 100644 --- a/tests/jest/components/tab/WorkPackage.spec.js +++ b/tests/jest/components/tab/WorkPackage.spec.js @@ -11,33 +11,60 @@ import workPackagesSearchResponse from '../../fixtures/workPackagesSearchRespons const localVue = createLocalVue() +const selectors = { + wpItemSelector: '.workpackage', + wpInfoSelector: '.row__workpackage', +} + describe('WorkPackage.vue', () => { let wrapper - const workPackagesSelector = '.workpackage' - beforeEach(() => { - - wrapper = shallowMount(WorkPackage, { - localVue, - propsData: { - workpackage: workPackagesSearchResponse[0], - }, + describe('old work package id', () => { + const wp = structuredClone(workPackagesSearchResponse[0]) + wp.displayId = `${wp.id}` + beforeEach(() => { + wrapper = shallowMount(WorkPackage, { + localVue, + propsData: { + workpackage: wp, + }, + }) + }) + it('shows work packages information', async () => { + const workPackages = wrapper.find(selectors.wpItemSelector) + expect(workPackages.exists()).toBeTruthy() + expect(workPackages.find(selectors.wpInfoSelector).text()).toBe(`#${wp.displayId} - ${wp.project}`) + expect(workPackages.element).toMatchSnapshot() }) - }) - it('shows work packages information', async () => { - const workPackages = wrapper.find(workPackagesSelector) - expect(workPackages.exists()).toBeTruthy() - expect(workPackages).toMatchSnapshot() + it('passes displayName, size and url props to NcAvatar but does not pass the user props', () => { + const avatar = wrapper.findComponent({ name: 'NcAvatar' }) + expect(avatar.exists()).toBe(true) + expect(avatar.props()).toMatchObject({ + displayName: wp.assignee, + size: expect.any(Number), + url: '/server/index.php/apps/integration_openproject/avatar?userId=1&userName=System', + }) + expect(avatar.props('user')).toBeUndefined() + }) }) - it('passes displayName, size and url props to NcAvatar but does not pass the user props', () => { - const avatar = wrapper.findComponent({ name: 'NcAvatar' }) - expect(avatar.exists()).toBe(true) - expect(avatar.props()).toMatchObject({ - displayName: 'test', - size: expect.any(Number), - url: '/server/index.php/apps/integration_openproject/avatar?userId=1&userName=System', + describe('new work package id', () => { + const wp = structuredClone(workPackagesSearchResponse[0]) + wp.displayId = `WP-${wp.id}` + + beforeEach(() => { + wrapper = shallowMount(WorkPackage, { + localVue, + propsData: { + workpackage: wp, + }, + }) + }) + it('shows work packages information', async () => { + const workPackages = wrapper.find(selectors.wpItemSelector) + expect(workPackages.exists()).toBeTruthy() + expect(workPackages.find(selectors.wpInfoSelector).text()).toBe(`${wp.displayId} - ${wp.project}`) + expect(workPackages.element).toMatchSnapshot() }) - expect(avatar.props('user')).toBeUndefined() }) }) diff --git a/tests/jest/components/tab/__snapshots__/SearchInput.spec.js.snap b/tests/jest/components/tab/__snapshots__/SearchInput.spec.js.snap index 195dec2f9..ad60d8ed2 100644 --- a/tests/jest/components/tab/__snapshots__/SearchInput.spec.js.snap +++ b/tests/jest/components/tab/__snapshots__/SearchInput.spec.js.snap @@ -50,6 +50,7 @@ exports[`SearchInput.vue work packages select search list should only use the op "isSmartPicker": false, "workpackage": { "assignee": "some assignee", + "displayId": "1", "fileId": 111, "id": 1, "picture": "http://localhost/apps/integration_openproject/api/v1/avatar?userId=&userName=some%20assignee", diff --git a/tests/jest/components/tab/__snapshots__/WorkPackage.spec.js.snap b/tests/jest/components/tab/__snapshots__/WorkPackage.spec.js.snap index 081f95faa..aa83a7078 100644 --- a/tests/jest/components/tab/__snapshots__/WorkPackage.spec.js.snap +++ b/tests/jest/components/tab/__snapshots__/WorkPackage.spec.js.snap @@ -1,10 +1,167 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`WorkPackage.vue shows work packages information 1`] = ` -VueWrapper { - "_emitted": {}, - "_emittedByOrder": [], - "isFunctionalComponent": undefined, - "selector": ".workpackage", -} +exports[`WorkPackage.vue new work package id shows work packages information 1`] = ` +
+
+
+
+ + in-progress + +
+
+ +
+ + WP-1 - test + +
+
+ +
+
+ + + task + + + + Organize work-packages + +
+
+ +
+
+
+ +
+ +
+ + test + +
+
+
+
+`; + +exports[`WorkPackage.vue old work package id shows work packages information 1`] = ` +
+
+
+
+ + in-progress + +
+
+ +
+ + #1 - test + +
+
+ +
+
+ + + task + + + + Organize work-packages + +
+
+ +
+
+
+ +
+ +
+ + test + +
+
+
+
`;