Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
idatt2106_2024_03_frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Scrum_Team_3
idatt2106_2024_03_frontend
Commits
9f71d2a3
Commit
9f71d2a3
authored
11 months ago
by
Sverre Frogner Haugen
Browse files
Options
Downloads
Patches
Plain Diff
Added unit test to DropNav router navigation
parent
40951bc7
No related branches found
No related tags found
1 merge request
!58
Navigation unit tests
Pipeline
#280562
passed
11 months ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/__tests__/DropNav.spec.ts
+111
-1
111 additions, 1 deletion
src/components/__tests__/DropNav.spec.ts
src/components/navigation/DropNav.vue
+6
-6
6 additions, 6 deletions
src/components/navigation/DropNav.vue
with
117 additions
and
7 deletions
src/components/__tests__/DropNav.spec.ts
+
111
−
1
View file @
9f71d2a3
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
DropNav
from
'
@/components/navigation/DropNav.vue
'
;
import
{
describe
,
it
,
expect
}
from
'
vitest
'
import
{
describe
,
it
,
expect
,
vi
,
afterEach
,
beforeEach
}
from
'
vitest
'
afterEach
(()
=>
{
vi
.
clearAllMocks
})
const
mockRoutePush
=
vi
.
fn
()
beforeEach
(()
=>
{
vi
.
mock
(
'
vue-router
'
,
async
()
=>
{
return
{
RouterView
:
{},
useRouter
:
()
=>
{
return
{
push
:
mockRoutePush
}
}
}
})
})
describe
(
'
DropNavComponent
'
,
()
=>
{
it
(
'
navigates to home
'
,
async
()
=>
{
const
wrapper
=
shallowMount
(
DropNav
);
const
button
=
wrapper
.
find
(
'
[data-testid="home-button"]
'
);
await
button
.
trigger
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
expect
(
mockRoutePush
).
toHaveBeenCalled
()
expect
(
mockRoutePush
).
toHaveBeenCalledWith
(
'
/homepage/home
'
);
})
it
(
'
navigates to discover
'
,
async
()
=>
{
const
wrapper
=
shallowMount
(
DropNav
);
const
button
=
wrapper
.
find
(
'
[data-testid="discover-button"]
'
);
await
button
.
trigger
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
expect
(
mockRoutePush
).
toHaveBeenCalled
()
expect
(
mockRoutePush
).
toHaveBeenCalledWith
(
'
/homepage/discover
'
);
})
it
(
'
navigates to milestones
'
,
async
()
=>
{
const
wrapper
=
shallowMount
(
DropNav
);
const
button
=
wrapper
.
find
(
'
[data-testid="milestone-button"]
'
);
await
button
.
trigger
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
expect
(
mockRoutePush
).
toHaveBeenCalled
()
expect
(
mockRoutePush
).
toHaveBeenCalledWith
(
'
/homepage/milestone
'
);
})
it
(
'
navigates to challenges
'
,
async
()
=>
{
const
wrapper
=
shallowMount
(
DropNav
);
const
button
=
wrapper
.
find
(
'
[data-testid="challenge-button"]
'
);
await
button
.
trigger
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
expect
(
mockRoutePush
).
toHaveBeenCalled
()
expect
(
mockRoutePush
).
toHaveBeenCalledWith
(
'
/homepage/challenge
'
);
})
it
(
'
navigates to economy
'
,
async
()
=>
{
const
wrapper
=
shallowMount
(
DropNav
);
const
button
=
wrapper
.
find
(
'
[data-testid="economy-button"]
'
);
await
button
.
trigger
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
expect
(
mockRoutePush
).
toHaveBeenCalled
()
expect
(
mockRoutePush
).
toHaveBeenCalledWith
(
'
/homepage/economy
'
);
})
it
(
'
navigates to profile
'
,
async
()
=>
{
const
wrapper
=
shallowMount
(
DropNav
);
const
button
=
wrapper
.
find
(
'
[data-testid="profile-button"]
'
);
await
button
.
trigger
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
expect
(
mockRoutePush
).
toHaveBeenCalled
()
expect
(
mockRoutePush
).
toHaveBeenCalledWith
(
'
/homepage/profile
'
);
})
it
(
'
renders buttons with correct labels and icons
'
,
()
=>
{
const
wrapper
=
shallowMount
(
DropNav
);
...
...
This diff is collapsed.
Click to expand it.
src/components/navigation/DropNav.vue
+
6
−
6
View file @
9f71d2a3
...
...
@@ -14,27 +14,27 @@
<
template
>
<div
class=
"burger-menu-component"
>
<div
class=
"button-menu"
>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/home')"
>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/home')"
data-testid=
"home-button"
>
<img
src=
"/src/components/icons/navigation/house-chimney.svg"
alt=
"Home Icon"
class=
"icon"
>
<label
class=
"button-label"
>
Hjem
</label>
</button>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/discover')"
>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/discover')"
data-testid=
"discover-button"
>
<img
src=
"/src/components/icons/navigation/lightbulb-on.svg"
alt=
"Discover Icon"
class=
"icon"
>
<label
class=
"button-label"
>
Sparetips
</label>
</button>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/milestone')"
>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/milestone')"
data-testid=
"milestone-button"
>
<img
src=
"/src/components/icons/navigation/piggy-bank.svg"
alt=
"Milestone Icon"
class=
"icon"
>
<label
class=
"button-label"
>
Sparemål
</label>
</button>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/challenge')"
>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/challenge')"
data-testid=
"challenge-button"
>
<img
src=
"/src/components/icons/navigation/challenge.svg"
alt=
"Challenge Icon"
class=
"icon"
>
<label
class=
"button-label"
>
Utfordringer
</label>
</button>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/economy')"
>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/economy')"
data-testid=
"economy-button"
>
<img
src=
"/src/components/icons/navigation/economy.svg"
alt=
"Economy Icon"
class=
"icon"
>
<label
class=
"button-label"
>
Forbruk
</label>
</button>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/profile')"
>
<button
class=
"menu-button"
@
click=
"navigateTo('/homepage/profile')"
data-testid=
"profile-button"
>
<img
src=
"/src/components/icons/navigation/user.svg"
alt=
"Profile Icon"
class=
"icon"
>
<label
class=
"button-label"
>
Profil
</label>
</button>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment