Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
community
pount
pount-front
Commits
c5ab4d41
Commit
c5ab4d41
authored
Oct 11, 2021
by
Jean Rabreau
Browse files
🐛
project template patch, update current stored template
parent
73a0bff7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/store/template.js
View file @
c5ab4d41
...
...
@@ -35,12 +35,12 @@ import i18n from '@/plugins/vue-i18n'
* @property {string} id
* @property {string} name
* @property {number} scope
* @property {Object} creator
* @property {Object} project
* @property {Object
| null
} creator
* @property {Object}
[
project
]
* @property {UsfField[]} fields
* @property {Object} messages
* @property {String} createdAt
* @property {String} updatedAt
* @property {String}
[
createdAt
]
* @property {String}
[
updatedAt
]
*/
/**
...
...
@@ -107,10 +107,10 @@ const Template = {
id
:
''
,
name
:
''
,
scope
:
TEMPLATE_SCOPE
.
SET
,
fields
:
[
{}
],
creator
:
''
,
fields
:
[],
creator
:
null
,
messages
:
{
default
:
'
fr
'
,
default
Locale
:
'
fr
'
,
locales
:
{
fr
:
{}
}
...
...
@@ -156,10 +156,6 @@ const Template = {
ADD_PROJECT_TEMPLATE
(
state
,
template
)
{
state
.
projectList
=
[
...
state
.
projectList
,
template
]
},
UPDATE_PROJECT_TEMPLATE
(
state
,
template
)
{
const
templateIndex
=
state
.
projectList
.
findIndex
(
t
=>
t
.
id
===
template
.
id
)
state
.
projectList
.
splice
(
templateIndex
,
1
,
template
)
},
},
actions
:
{
/**
...
...
@@ -311,12 +307,7 @@ const Template = {
privateFields
:
getPrivateFields
(
templatePatch
.
fields
)
})
.
then
(
response
=>
{
const
template
=
response
.
data
if
(
template
.
scope
===
TEMPLATE_SCOPE
.
SET
)
{
commit
(
'
SET_CURRENT
'
,
response
.
data
)
}
else
if
(
template
.
scope
===
TEMPLATE_SCOPE
.
PROJECT
)
{
commit
(
'
UPDATE_PROJECT_TEMPLATE
'
,
template
)
}
commit
(
'
SET_CURRENT
'
,
response
.
data
)
return
dispatch
(
'
dialog/displayInfo
'
,
i18n
.
t
(
'
template.updated
'
),
...
...
tests/unit/store/template.spec.js
View file @
c5ab4d41
...
...
@@ -45,21 +45,33 @@ describe('store/template', () => {
const
axiosError
=
new
Error
(
'
failed
'
)
beforeEach
(()
=>
{
store
.
state
.
template
=
{
/**
* @type {PountTemplate}
*/
current
:
{
id
:
''
,
name
:
''
,
scope
:
TEMPLATE_SCOPE
.
SET
,
fields
:
[
{}
],
creator
:
''
,
fields
:
[],
creator
:
null
,
messages
:
{
default
:
'
fr
'
,
default
Locale
:
'
fr
'
,
locales
:
{
fr
:
{}
}
}
},
/**
* @type {PountTemplate[]}
*/
publicList
:
[],
/**
* @type {PountTemplate[]}
*/
projectList
:
[],
/**
* @type {PountTemplate[]}
*/
templateList
:
[],
}
store
.
state
.
project
.
current
.
id
=
projectId
...
...
@@ -279,23 +291,12 @@ describe('store/template', () => {
'
patch data check
'
)
})
it
(
'
should update current template
, if scope is SET
'
,
async
()
=>
{
it
(
'
should update current template
'
,
async
()
=>
{
store
.
state
.
template
.
current
=
{
...
retrieveTemplate
,
name
:
'
previous name
'
}
authStub
.
patch
.
returns
(
Promise
.
resolve
({
data
:
retrieveTemplate
}))
await
store
.
dispatch
(
'
template/updateTemplate
'
,
{
id
:
''
,
...
patchData
})
expect
(
store
.
getters
[
'
template/current
'
].
name
).
to
.
equal
(
'
patched
'
)
})
it
(
'
should update project template, if scope is PROJECT
'
,
async
()
=>
{
store
.
state
.
template
.
projectList
=
[
{
id
:
'
3637
'
,
name
:
'
thunaplate
'
},
{
id
:
'
118218
'
,
name
:
'
complate
'
},
{
...
retrieveTemplate
,
name
:
'
previous name
'
},
{
id
:
'
007
'
,
name
:
'
goldplate
'
},
]
authStub
.
patch
.
returns
(
Promise
.
resolve
({
data
:
{
...
retrieveTemplate
,
scope
:
TEMPLATE_SCOPE
.
PROJECT
}}))
await
store
.
dispatch
(
'
template/updateTemplate
'
,
{
id
:
''
,
...
patchData
})
expect
(
store
.
getters
[
'
template/projectList
'
][
2
].
name
).
to
.
equal
(
'
patched
'
)
})
it
(
'
should notify explicit error
'
,
async
()
=>
{
authStub
.
patch
.
returns
(
Promise
.
reject
(
axiosError
))
await
store
.
dispatch
(
'
template/updateTemplate
'
,
{
id
:
''
,
...
patchData
})
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment