Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
adf5f83e
Commit
adf5f83e
authored
May 08, 2020
by
Roman Kuba
Committed by
Natalia Tepluhina
May 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small Refactor of router_spec.js
- Removed unnecessary code - Explicitly get a fresh instance in every spec
parent
ea307cd5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
43 deletions
+123
-43
app/assets/javascripts/design_management/pages/design/index.vue
...sets/javascripts/design_management/pages/design/index.vue
+14
-0
app/assets/javascripts/design_management/utils/tracking.js
app/assets/javascripts/design_management/utils/tracking.js
+22
-0
spec/frontend/design_management/router_spec.js
spec/frontend/design_management/router_spec.js
+36
-43
spec/frontend/design_management/utils/tracking_spec.js
spec/frontend/design_management/utils/tracking_spec.js
+51
-0
No files found.
app/assets/javascripts/design_management/pages/design/index.vue
View file @
adf5f83e
...
...
@@ -35,6 +35,7 @@ import {
UPDATE_NOTE_ERROR
,
designDeletionError
,
}
from
'
../../utils/error_messages
'
;
import
{
trackDesignDetailView
}
from
'
../../utils/tracking
'
;
import
{
DESIGNS_ROUTE_NAME
}
from
'
../../router/constants
'
;
export
default
{
...
...
@@ -257,8 +258,21 @@ export default {
query
:
this
.
$route
.
query
,
});
},
trackEvent
()
{
trackDesignDetailView
(
'
issue-design-collection
'
,
this
.
$route
.
query
.
version
||
this
.
latestVersionId
,
this
.
isLatestVersion
,
);
},
},
beforeRouteEnter
(
to
,
from
,
next
)
{
next
(
vm
=>
{
vm
.
trackEvent
();
});
},
beforeRouteUpdate
(
to
,
from
,
next
)
{
this
.
trackEvent
();
this
.
closeCommentForm
();
next
();
},
...
...
app/assets/javascripts/design_management/utils/tracking.js
0 → 100644
View file @
adf5f83e
import
Tracking
from
'
~/tracking
'
;
function
assembleDesignPayload
(
payloadArr
)
{
return
{
value
:
{
'
internal-object-refrerer
'
:
payloadArr
[
0
],
'
version-number
'
:
payloadArr
[
1
],
'
current-version
'
:
payloadArr
[
2
],
},
};
}
// Tracking Constants
const
DESIGN_TRACKING_PAGE_NAME
=
'
projects:issues:design
'
;
// eslint-disable-next-line import/prefer-default-export
export
function
trackDesignDetailView
(
refrerer
=
''
,
designVersion
=
1
,
latestVersion
=
false
)
{
Tracking
.
event
(
DESIGN_TRACKING_PAGE_NAME
,
'
design_viewed
'
,
{
label
:
'
design_viewed
'
,
...
assembleDesignPayload
([
refrerer
,
designVersion
,
latestVersion
]),
});
}
spec/frontend/design_management/router_spec.js
View file @
adf5f83e
import
{
mount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
{
nextTick
}
from
'
vue
'
;
import
VueRouter
from
'
vue-router
'
;
import
App
from
'
~/design_management/components/app.vue
'
;
import
Designs
from
'
~/design_management/pages/index.vue
'
;
...
...
@@ -11,74 +12,66 @@ import {
}
from
'
~/design_management/router/constants
'
;
import
'
~/commons/bootstrap
'
;
jest
.
mock
(
'
mousetrap
'
,
()
=>
({
bind
:
jest
.
fn
(),
unbind
:
jest
.
fn
(),
}));
describe
(
'
Design management router
'
,
()
=>
{
let
vm
;
let
router
;
function
factory
()
{
const
localVue
=
createLocalVue
();
localVue
.
use
(
VueRouter
);
function
factory
(
routeArg
)
{
const
localVue
=
createLocalVue
();
localVue
.
use
(
VueRouter
);
window
.
gon
=
{
sprite_icons
:
''
};
window
.
gon
=
{
sprite_icons
:
''
};
router
=
createRouter
(
'
/
'
);
const
router
=
createRouter
(
'
/
'
);
if
(
routeArg
!==
undefined
)
{
router
.
push
(
routeArg
);
}
vm
=
mount
(
App
,
{
localVue
,
router
,
mocks
:
{
$apollo
:
{
queries
:
{
designs
:
{
loading
:
true
},
design
:
{
loading
:
true
},
permissions
:
{
loading
:
true
},
},
return
mount
(
App
,
{
localVue
,
router
,
mocks
:
{
$apollo
:
{
queries
:
{
designs
:
{
loading
:
true
},
design
:
{
loading
:
true
},
permissions
:
{
loading
:
true
},
},
},
});
}
beforeEach
(()
=>
{
factory
();
},
});
}
afterEach
(()
=>
{
vm
.
destroy
();
jest
.
mock
(
'
mousetrap
'
,
()
=>
({
bind
:
jest
.
fn
(),
unbind
:
jest
.
fn
(),
}));
router
.
app
.
$destroy
();
describe
(
'
Design management router
'
,
()
=>
{
afterEach
(()
=>
{
window
.
location
.
hash
=
''
;
});
describe
.
each
([[
'
/
'
],
[{
name
:
ROOT_ROUTE_NAME
}]])(
'
root route
'
,
push
Arg
=>
{
describe
.
each
([[
'
/
'
],
[{
name
:
ROOT_ROUTE_NAME
}]])(
'
root route
'
,
route
Arg
=>
{
it
(
'
pushes home component
'
,
()
=>
{
router
.
push
(
push
Arg
);
const
wrapper
=
factory
(
route
Arg
);
expect
(
vm
.
find
(
Designs
).
exists
()).
toBe
(
true
);
expect
(
wrapper
.
find
(
Designs
).
exists
()).
toBe
(
true
);
});
});
describe
.
each
([[
'
/designs
'
],
[{
name
:
DESIGNS_ROUTE_NAME
}]])(
'
designs route
'
,
push
Arg
=>
{
describe
.
each
([[
'
/designs
'
],
[{
name
:
DESIGNS_ROUTE_NAME
}]])(
'
designs route
'
,
route
Arg
=>
{
it
(
'
pushes designs root component
'
,
()
=>
{
router
.
push
(
push
Arg
);
const
wrapper
=
factory
(
route
Arg
);
expect
(
vm
.
find
(
Designs
).
exists
()).
toBe
(
true
);
expect
(
wrapper
.
find
(
Designs
).
exists
()).
toBe
(
true
);
});
});
describe
.
each
([[
'
/designs/1
'
],
[{
name
:
DESIGN_ROUTE_NAME
,
params
:
{
id
:
'
1
'
}
}]])(
'
designs detail route
'
,
push
Arg
=>
{
route
Arg
=>
{
it
(
'
pushes designs detail component
'
,
()
=>
{
router
.
push
(
push
Arg
);
const
wrapper
=
factory
(
route
Arg
);
return
vm
.
vm
.
$
nextTick
().
then
(()
=>
{
const
detail
=
vm
.
find
(
DesignDetail
);
return
nextTick
().
then
(()
=>
{
const
detail
=
wrapper
.
find
(
DesignDetail
);
expect
(
detail
.
exists
()).
toBe
(
true
);
expect
(
detail
.
props
(
'
id
'
)).
toEqual
(
'
1
'
);
});
...
...
spec/frontend/design_management/utils/tracking_spec.js
0 → 100644
View file @
adf5f83e
import
{
mockTracking
}
from
'
helpers/tracking_helper
'
;
import
{
trackDesignDetailView
}
from
'
~/design_management/utils/tracking
'
;
function
getTrackingSpy
(
key
)
{
return
mockTracking
(
key
,
undefined
,
jest
.
spyOn
);
}
describe
(
'
Tracking Events
'
,
()
=>
{
describe
(
'
trackDesignDetailView
'
,
()
=>
{
const
eventKey
=
'
projects:issues:design
'
;
const
eventName
=
'
design_viewed
'
;
it
(
'
trackDesignDetailView fires a tracking event when called
'
,
()
=>
{
const
trackingSpy
=
getTrackingSpy
(
eventKey
);
trackDesignDetailView
();
expect
(
trackingSpy
).
toHaveBeenCalledWith
(
eventKey
,
eventName
,
expect
.
objectContaining
({
label
:
eventName
,
value
:
{
'
internal-object-refrerer
'
:
''
,
'
version-number
'
:
1
,
'
current-version
'
:
false
,
},
}),
);
});
it
(
'
trackDesignDetailView allows to customize the value payload
'
,
()
=>
{
const
trackingSpy
=
getTrackingSpy
(
eventKey
);
trackDesignDetailView
(
'
from-a-test
'
,
100
,
true
);
expect
(
trackingSpy
).
toHaveBeenCalledWith
(
eventKey
,
eventName
,
expect
.
objectContaining
({
label
:
eventName
,
value
:
{
'
internal-object-refrerer
'
:
'
from-a-test
'
,
'
version-number
'
:
100
,
'
current-version
'
:
true
,
},
}),
);
});
});
});
Write
Preview
Markdown
is supported
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