Skip to content

Commit

Permalink
Merge pull request #10239 from owncloud/modal-refactor-followup
Browse files Browse the repository at this point in the history
modal refactor follow-up
  • Loading branch information
kulmann authored Jan 2, 2024
2 parents b805978 + 9e13e1b commit 5377b0a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog/unreleased/change-creating-modals
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ BREAKING CHANGE for developers: The way how to work with modals has been reworke
For more details on how to use the modal please see the linked PR down below.

https://github.com/owncloud/web/pull/10212
https://github.com/owncloud/web/pull/10239
https://github.com/owncloud/web/issues/10095
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default defineComponent({
const onConfirm = async () => {
if (unref(isFormInvalid)) {
return Promise.reject(new Promise((reject) => reject('')))
return Promise.reject()
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default defineComponent({
const onConfirm = async () => {
if (unref(isFormInvalid)) {
return Promise.reject(new Promise((reject) => reject('')))
return Promise.reject()
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default defineComponent({
// Human-readable error message is provided, for example when password is on banned list
if (e.statusCode === 400) {
errorMessage.value = $gettext(e.message)
return Promise.reject(new Promise((reject) => reject('')))
return Promise.reject()
}
store.dispatch('showErrorMessage', {
Expand Down
6 changes: 3 additions & 3 deletions packages/web-pkg/src/components/CreateLinkModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ export default defineComponent({
if (!unref(selectedRoleIsInternal)) {
if (unref(passwordEnforced) && !unref(password).value) {
password.error = $gettext('Password must not be empty')
return Promise.reject(new Promise((reject) => reject('')))
return Promise.reject()
}
if (!passwordPolicy.check(unref(password).value)) {
return Promise.reject(new Promise((reject) => reject('')))
return Promise.reject()
}
}
Expand Down Expand Up @@ -322,7 +322,7 @@ export default defineComponent({
if (userFacingErrors.length) {
password.error = $gettext(userFacingErrors[0].message)
return Promise.reject(new Promise((reject) => reject('')))
return Promise.reject()
}
if (props.callbackFn) {
Expand Down
17 changes: 13 additions & 4 deletions packages/web-pkg/tests/unit/composables/piniaStores/modals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('useModals', () => {
})

describe('method "dispatchModal"', () => {
it('adds a modal to the stack of modals', () => {
it('adds a modal to the stack of modals and sets it active', () => {
getWrapper({
setup: (instance) => {
const data = { title: 'test' }
Expand All @@ -17,6 +17,9 @@ describe('useModals', () => {
expect(modal.id).toBeDefined()
expect(modal.title).toEqual(data.title)
expect(instance.activeModal).toEqual(modal)

const modal2 = instance.dispatchModal(data)
expect(instance.activeModal).toEqual(modal2)
}
})
})
Expand All @@ -34,12 +37,18 @@ describe('useModals', () => {
})
})
describe('method "removeModal"', () => {
it('removes an existing modal', () => {
it('removes an existing modal and sets another existing modal active', () => {
getWrapper({
setup: (instance) => {
const modal = instance.dispatchModal({ title: 'test' })
instance.removeModal(modal.id)
expect(instance.modals.length).toBe(0)
const modal2 = instance.dispatchModal({ title: 'test2' })

expect(instance.modals.length).toBe(2)
expect(instance.activeModal).toEqual(modal2)

instance.removeModal(modal2.id)
expect(instance.modals.length).toBe(1)
expect(instance.activeModal).toEqual(modal)
}
})
})
Expand Down

0 comments on commit 5377b0a

Please sign in to comment.