Skip to content

Commit 0eadf17

Browse files
committed
fix(settings): adjust systemtags handling and tests
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 492bdb7 commit 0eadf17

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

apps/systemtags/src/components/SystemTagForm.vue

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
<div class="system-tag-form__group">
1818
<label for="system-tags-input">{{ t('systemtags', 'Search for a tag to edit') }}</label>
1919
<NcSelectTags
20-
v-model="selectedTag"
20+
:model-value="selectedTag"
2121
input-id="system-tags-input"
2222
:placeholder="t('systemtags', 'Collaborative tags …')"
2323
:fetch-tags="false"
2424
:options="tags"
2525
:multiple="false"
26-
passthru>
26+
label-outside
27+
@update:model-value="onSelectTag">
2728
<template #no-options>
2829
{{ t('systemtags', 'No tags to select') }}
2930
</template>
@@ -49,7 +50,8 @@
4950
:options="tagLevelOptions"
5051
:reduce="level => level.id"
5152
:clearable="false"
52-
:disabled="loading" />
53+
:disabled="loading"
54+
label-outside />
5355
</div>
5456

5557
<div class="system-tag-form__row">
@@ -85,11 +87,12 @@
8587
</template>
8688

8789
<script lang="ts">
90+
import type { PropType } from 'vue'
8891
import type { Tag, TagWithId } from '../types.js'
8992
9093
import { showSuccess } from '@nextcloud/dialogs'
9194
import { translate as t } from '@nextcloud/l10n'
92-
import Vue, { type PropType } from 'vue'
95+
import { defineComponent } from 'vue'
9396
import NcButton from '@nextcloud/vue/components/NcButton'
9497
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
9598
import NcSelect from '@nextcloud/vue/components/NcSelect'
@@ -135,10 +138,10 @@ function getTagLevel(userVisible: boolean, userAssignable: boolean): TagLevel {
135138
[[true, false].join(',')]: TagLevel.Restricted,
136139
[[false, false].join(',')]: TagLevel.Invisible,
137140
}
138-
return matchLevel[[userVisible, userAssignable].join(',')]
141+
return matchLevel[[userVisible, userAssignable].join(',')]!
139142
}
140143
141-
export default Vue.extend({
144+
export default defineComponent({
142145
name: 'SystemTagForm',
143146
144147
components: {
@@ -156,6 +159,12 @@ export default Vue.extend({
156159
},
157160
},
158161
162+
emits: [
163+
'tag:created',
164+
'tag:updated',
165+
'tag:deleted',
166+
],
167+
159168
data() {
160169
return {
161170
loading: false,
@@ -230,6 +239,11 @@ export default Vue.extend({
230239
methods: {
231240
t,
232241
242+
onSelectTag(tagId: number | null) {
243+
const tag = this.tags.find((search) => search.id === tagId) || null
244+
this.selectedTag = tag
245+
},
246+
233247
async handleSubmit() {
234248
if (this.isCreating) {
235249
await this.create()

cypress/e2e/systemtags/admin-settings.cy.ts

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,35 @@ const updatedTagName = 'bar'
1212

1313
describe('Create system tags', () => {
1414
before(() => {
15+
// delete any existing tags
16+
cy.runOccCommand('tag:list --output=json').then((output) => {
17+
Object.keys(JSON.parse(output.stdout)).forEach((id) => {
18+
cy.runOccCommand(`tag:delete ${id}`)
19+
})
20+
})
21+
22+
// login as admin and go to admin settings
1523
cy.login(admin)
1624
cy.visit('/settings/admin')
1725
})
1826

1927
it('Can create a tag', () => {
28+
cy.intercept('POST', '/remote.php/dav/systemtags').as('createTag')
2029
cy.get('input#system-tag-name').should('exist').and('have.value', '')
2130
cy.get('input#system-tag-name').type(tagName)
2231
cy.get('input#system-tag-name').should('have.value', tagName)
2332
// submit the form
2433
cy.get('input#system-tag-name').type('{enter}')
2534

35+
// wait for the tag to be created
36+
cy.wait('@createTag').its('response.statusCode').should('eq', 201)
37+
2638
// see that the created tag is in the list
2739
cy.get('input#system-tags-input').focus()
2840
cy.get('input#system-tags-input').invoke('attr', 'aria-controls').then((id) => {
29-
cy.get(`ul#${id}`).within(() => {
30-
cy.contains('li', tagName).should('exist')
31-
// ensure only one tag exists
32-
cy.get('li').should('have.length', 1)
33-
})
41+
cy.get(`ul#${id} li span[title="${tagName}"]`)
42+
.should('exist')
43+
.should('have.length', 1)
3444
})
3545
})
3646
})
@@ -42,12 +52,9 @@ describe('Update system tags', { testIsolation: false }, () => {
4252
})
4353

4454
it('select the tag', () => {
45-
// select the tag to edit
4655
cy.get('input#system-tags-input').focus()
4756
cy.get('input#system-tags-input').invoke('attr', 'aria-controls').then((id) => {
48-
cy.get(`ul#${id}`).within(() => {
49-
cy.contains('li', tagName).should('exist').click()
50-
})
57+
cy.get(`ul#${id} li span[title="${tagName}"]`).should('exist').click()
5158
})
5259
// see that the tag name matches the selected tag
5360
cy.get('input#system-tag-name').should('exist').and('have.value', tagName)
@@ -57,28 +64,27 @@ describe('Update system tags', { testIsolation: false }, () => {
5764
})
5865

5966
it('update the tag name and level', () => {
67+
cy.intercept('PROPPATCH', '/remote.php/dav/systemtags/*').as('updateTag')
6068
cy.get('input#system-tag-name').clear()
6169
cy.get('input#system-tag-name').type(updatedTagName)
6270
cy.get('input#system-tag-name').should('have.value', updatedTagName)
6371
// select the new tag level
6472
cy.get('input#system-tag-level').focus()
6573
cy.get('input#system-tag-level').invoke('attr', 'aria-controls').then((id) => {
66-
cy.get(`ul#${id}`).within(() => {
67-
cy.contains('li', 'Invisible').should('exist').click()
68-
})
74+
cy.get(`ul#${id} li span[title="Invisible"]`).should('exist').click()
6975
})
7076
// submit the form
7177
cy.get('input#system-tag-name').type('{enter}')
78+
// wait for the tag to be updated
79+
cy.wait('@updateTag').its('response.statusCode').should('eq', 207)
7280
})
7381

7482
it('see the tag was successfully updated', () => {
7583
cy.get('input#system-tags-input').focus()
7684
cy.get('input#system-tags-input').invoke('attr', 'aria-controls').then((id) => {
77-
cy.get(`ul#${id}`).within(() => {
78-
cy.contains('li', `${updatedTagName} (invisible)`).should('exist')
79-
// ensure only one tag exists
80-
cy.get('li').should('have.length', 1)
81-
})
85+
cy.get(`ul#${id} li span[title="${updatedTagName} (invisible)"]`)
86+
.should('exist')
87+
.should('have.length', 1)
8288
})
8389
})
8490
})
@@ -93,9 +99,7 @@ describe('Delete system tags', { testIsolation: false }, () => {
9399
// select the tag to edit
94100
cy.get('input#system-tags-input').focus()
95101
cy.get('input#system-tags-input').invoke('attr', 'aria-controls').then((id) => {
96-
cy.get(`ul#${id}`).within(() => {
97-
cy.contains('li', `${updatedTagName} (invisible)`).should('exist').click()
98-
})
102+
cy.get(`ul#${id} li span[title="${updatedTagName} (invisible)"]`).should('exist').click()
99103
})
100104
// see that the tag name matches the selected tag
101105
cy.get('input#system-tag-name').should('exist').and('have.value', updatedTagName)
@@ -105,17 +109,18 @@ describe('Delete system tags', { testIsolation: false }, () => {
105109
})
106110

107111
it('can delete the tag', () => {
112+
cy.intercept('DELETE', '/remote.php/dav/systemtags/*').as('deleteTag')
108113
cy.get('.system-tag-form__row').within(() => {
109114
cy.contains('button', 'Delete').should('be.enabled').click()
110115
})
116+
// wait for the tag to be deleted
117+
cy.wait('@deleteTag').its('response.statusCode').should('eq', 204)
111118
})
112119

113120
it('see that the deleted tag is not present', () => {
114121
cy.get('input#system-tags-input').focus()
115122
cy.get('input#system-tags-input').invoke('attr', 'aria-controls').then((id) => {
116-
cy.get(`ul#${id}`).within(() => {
117-
cy.contains('li', updatedTagName).should('not.exist')
118-
})
123+
cy.get(`ul#${id} li span[title="${updatedTagName}"]`).should('not.exist')
119124
})
120125
})
121126
})

0 commit comments

Comments
 (0)