Skip to content

Commit 9ddbc91

Browse files
committed
test(dialog): move component tests out of lib and cover more cases
- Move the Playwright component tests to tests/ct/ so they are outside the library's rootDir (they import fixtures outside lib, which broke the build and ts:check). - Add Share.setRecipientPermission / selectRecipientPreset unit tests. - Add SharePanel tab-bar tests (hidden once a recipient exists). - Rename the recipient remove action to "Remove participant" and add left padding to the recipient list. Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 620d734 commit 9ddbc91

9 files changed

Lines changed: 49 additions & 8 deletions

File tree

lib/dialog/api/share.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ vi.mock('./sharing.ts', () => ({
2222
updateShareProperty: vi.fn(),
2323
updateSharePermission: vi.fn(),
2424
selectSharePermissionPreset: vi.fn(),
25+
updateShareRecipientPermission: vi.fn(),
26+
selectShareRecipientPermissionPreset: vi.fn(),
2527
updateShareState: vi.fn(),
2628
searchRecipients: vi.fn(),
2729
deleteShare: vi.fn(),
@@ -119,6 +121,20 @@ describe('Share', () => {
119121
expect(mocked.updateSharePermission).toHaveBeenCalledWith('abc', 'C', false)
120122
})
121123

124+
it('setRecipientPermission forwards recipient identity, permission and flag', async () => {
125+
const instance = await makeShare()
126+
mocked.updateShareRecipientPermission.mockResolvedValue(share())
127+
await instance.setRecipientPermission('R', 'bob', 'C', true, 'inst')
128+
expect(mocked.updateShareRecipientPermission).toHaveBeenCalledWith('abc', 'R', 'bob', 'C', true, 'inst')
129+
})
130+
131+
it('selectRecipientPreset forwards recipient identity and preset', async () => {
132+
const instance = await makeShare()
133+
mocked.selectShareRecipientPermissionPreset.mockResolvedValue(share())
134+
await instance.selectRecipientPreset('R', 'bob', 'PresetX')
135+
expect(mocked.selectShareRecipientPermissionPreset).toHaveBeenCalledWith('abc', 'R', 'bob', 'PresetX', undefined)
136+
})
137+
122138
it('addSource forwards the class and value', async () => {
123139
const instance = await makeShare()
124140
mocked.addShareSource.mockResolvedValue(share())

lib/dialog/components/RecipientList.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ const recipients = computed(() => props.share.recipients.filter((recipient) => r
3333
display: flex;
3434
flex-direction: column;
3535
gap: calc(var(--default-grid-baseline) * 3);
36+
padding-inline-start: calc(var(--default-grid-baseline) * 2);
3637
}
3738
</style>

lib/dialog/components/RecipientRow.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<template #icon>
4141
<NcIconSvgWrapper :svg="IconDelete" :size="20" />
4242
</template>
43-
{{ t('Remove') }}
43+
{{ t('Remove participant') }}
4444
</NcActionButton>
4545
</NcActions>
4646

lib/dialog/components/SharePanel.spec.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { SharingShare } from '../types/api.ts'
88
import { flushPromises, shallowMount } from '@vue/test-utils'
99
import { beforeEach, describe, expect, it, vi } from 'vitest'
1010
import SharePanel from './SharePanel.vue'
11-
import { PROPERTY_EXPIRATION, PROPERTY_PASSWORD, RECIPIENT_TYPE_TOKEN, SOURCE_TYPE_NODE } from '../constants.ts'
11+
import { PROPERTY_EXPIRATION, PROPERTY_PASSWORD, RECIPIENT_TYPE_TOKEN, RECIPIENT_TYPE_USER, SOURCE_TYPE_NODE } from '../constants.ts'
1212
import { ShareDialogTab } from '../types/ui.ts'
1313

1414
const PRESET_VIEW = 'preset-view'
@@ -143,6 +143,30 @@ describe('SharePanel presets and permissions', () => {
143143
})
144144
})
145145

146+
describe('SharePanel tab bar', () => {
147+
const recipient = {
148+
class: RECIPIENT_TYPE_USER,
149+
value: 'bob',
150+
instance: null,
151+
display_name: 'Bob',
152+
icon: null,
153+
secret: { updatable: false },
154+
initiator: null,
155+
permission_preset: null,
156+
permissions: [],
157+
}
158+
159+
it('shows the share-type tabs when there are no recipients', () => {
160+
const { wrapper } = mountPanel()
161+
expect(wrapper.findComponent({ name: 'NcRadioGroup' }).exists()).toBe(true)
162+
})
163+
164+
it('hides the share-type tabs once a recipient exists', () => {
165+
const { wrapper } = mountPanel(schema({ recipients: [recipient] }))
166+
expect(wrapper.findComponent({ name: 'NcRadioGroup' }).exists()).toBe(false)
167+
})
168+
})
169+
146170
describe('SharePanel recipient sync', () => {
147171
it('adds a token recipient when opening on the Anyone tab', async () => {
148172
const { share } = mountPanel(schema(), { shareDialogTab: ShareDialogTab.Anyone })

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
"lint": "eslint",
4747
"lint:fix": "eslint --fix",
4848
"test": "vitest run",
49-
"test:ct": "playwright test -c playwright-ct.config.ts",
5049
"test:coverage": "vitest run --coverage",
50+
"test:ct": "playwright test -c playwright-ct.config.ts",
5151
"test:watch": "vitest run --watch",
5252
"ts:check": "vue-tsc --noEmit",
5353
"watch": "vite --mode development build --watch"

playwright-ct.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { defineConfig, devices } from '@playwright/experimental-ct-vue'
77

88
export default defineConfig({
9-
testDir: './lib',
9+
testDir: './tests/ct',
1010
// Component tests are named *.ct.ts so Vitest (which globs *.spec/*.test)
1111
// ignores them and only Playwright picks them up.
1212
testMatch: '**/*.ct.ts',

lib/dialog/components/PermissionEditor.ct.ts renamed to tests/ct/PermissionEditor.ct.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { expect, test } from '@playwright/experimental-ct-vue'
7-
import PermissionEditor from './PermissionEditor.vue'
7+
import PermissionEditor from '../../lib/dialog/components/PermissionEditor.vue'
88

99
const baseProps = {
1010
presetOptions: [{ value: 'View', label: 'Can view' }, { value: 'custom', label: 'Can…' }],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { expect, test } from '@playwright/experimental-ct-vue'
7-
import Fixture from '../../../tests/ct/fixtures/RecipientListFixture.vue'
7+
import Fixture from './fixtures/RecipientListFixture.vue'
88

99
test('renders a row per recipient, excluding the link (token)', async ({ mount }) => {
1010
const component = await mount(Fixture)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { expect, test } from '@playwright/experimental-ct-vue'
7-
import Fixture from '../../../tests/ct/fixtures/RecipientRowFixture.vue'
7+
import Fixture from './fixtures/RecipientRowFixture.vue'
88

99
test('shows the recipient name and a static preset subtitle', async ({ mount }) => {
1010
const component = await mount(Fixture)
@@ -20,7 +20,7 @@ test('removes the recipient from the menu', async ({ mount, page }) => {
2020
}
2121
const component = await mount(Fixture, { on: { removed: onRemoved } })
2222
await component.getByRole('button', { name: 'Recipient actions' }).click()
23-
await page.getByRole('menuitem', { name: 'Remove' }).click()
23+
await page.getByRole('menuitem', { name: 'Remove participant' }).click()
2424
expect(removed).toBe(true)
2525
})
2626

0 commit comments

Comments
 (0)