Skip to content

Commit f605feb

Browse files
committed
Update NavBarMobile component and refactor tests
1 parent 2f0a520 commit f605feb

File tree

3 files changed

+48
-46
lines changed

3 files changed

+48
-46
lines changed

frontend/src/components/NavBarMobile.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ref } from 'vue';
2+
import { inject, ref } from 'vue';
33
import { useI18n } from 'vue-i18n';
44
import { useUserStore } from '@/stores/user-store';
55
import {
@@ -15,6 +15,7 @@ import {
1515
PhUserSquare,
1616
} from '@phosphor-icons/vue';
1717
import { PrimaryButton, UserAvatar } from '@thunderbirdops/services-ui';
18+
import { accountsTbProfileUrlKey } from '@/keys';
1819
1920
// component constants
2021
const userStore = useUserStore();
@@ -27,6 +28,8 @@ const navItems = [
2728
{ route: 'settings', i18nKey: 'settings', icon: PhGear },
2829
];
2930
31+
const accountsTbProfileUrl = inject(accountsTbProfileUrlKey);
32+
3033
const menuOpen = ref(false);
3134
const myLinkTooltip = ref(t('navBar.shareMyLink'));
3235
@@ -102,12 +105,12 @@ async function copyLink() {
102105
</summary>
103106

104107
<ul @click="onMenuClose">
105-
<router-link to="profile">
108+
<a :href="accountsTbProfileUrl">
106109
<li>
107110
<ph-user-square size="24" />
108111
{{ t('label.userProfile') }}
109112
</li>
110-
</router-link>
113+
</a>
111114
<router-link to="report-bug">
112115
<li>
113116
<ph-arrow-square-out size="24" />

frontend/test/components/NavBar.test.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import withSetup from '../utils/with-setup';
77
import { useUserStore } from '@/stores/user-store';
88
import { RouterLink } from 'vue-router';
99
import NavBar from '@/components/NavBar.vue';
10+
import { accountsTbProfileUrlKey } from '@/keys';
1011

1112

1213
describe('NavBar', () => {
1314
var app;
1415
var wrapper;
16+
const testAccountsTbProfileUrl = 'https://accounts.tb.pro/dashboard';
1517

1618
// list of route names that are also lang keys (format: label.<key>), used as nav items
1719
// these routes are added in addition to the routes already specified in NavBar.vue
@@ -23,6 +25,16 @@ describe('NavBar', () => {
2325
navItems: navItems,
2426
};
2527

28+
const getMountOptions = () => ({
29+
propsData: ourProps,
30+
global: {
31+
plugins: [i18ninstance, router],
32+
provide: {
33+
[accountsTbProfileUrlKey]: testAccountsTbProfileUrl,
34+
},
35+
},
36+
});
37+
2638
beforeEach(() => {
2739
app = withSetup();
2840
app.use(createTestingPinia());
@@ -33,12 +45,7 @@ describe('NavBar', () => {
3345
});
3446

3547
it('renders correctly when not logged in', () => {
36-
wrapper = mount(NavBar, {
37-
propsData: ourProps,
38-
global: {
39-
plugins: [i18ninstance, router],
40-
},
41-
});
48+
wrapper = mount(NavBar, getMountOptions());
4249

4350
// verify all expected router-link child components were rendered (only one when not signed in)
4451
const allRouterLinks = wrapper.findAllComponents(RouterLink);
@@ -56,26 +63,25 @@ describe('NavBar', () => {
5663
user.data.accessToken = 'abc';
5764
expect(user.authenticated).toBe(true);
5865

59-
wrapper = mount(NavBar, {
60-
propsData: ourProps,
61-
global: {
62-
plugins: [i18ninstance, router],
63-
},
64-
});
66+
wrapper = mount(NavBar, getMountOptions());
6567

6668
// verify all expected router-link child components were rendered when signed in
6769
const allRouterLinks = wrapper.findAllComponents(RouterLink);
6870
var foundLinks = [];
6971
for (let link of allRouterLinks) {
7072
foundLinks.push(link.props().to.name);
7173
}
72-
// we expect the routes we sent in above in ourProps navItems as well as the other routes in
73-
// NavBar.vue that appear when the user is signed in
74-
const expRoutes = navItems.concat(['dashboard', 'profile', 'report-bug', 'contact', 'logout']);
74+
// we expect the routes we sent in above in ourProps navItems as well as the dashboard route
75+
// from the logo link
76+
const expRoutes = navItems.concat(['dashboard']);
7577
expect(foundLinks.length).toBe(expRoutes.length);
7678
for (let expRoute of expRoutes) {
7779
expect(foundLinks, 'expected link component to be rendered').toContain(expRoute);
7880
}
81+
82+
// verify the anchor tag to accountsTbProfileUrl exists and has the correct href
83+
const profileAnchor = wrapper.find('a[href="' + testAccountsTbProfileUrl + '"]');
84+
expect(profileAnchor.exists(), 'expected anchor tag to accountsTbProfileUrl to be rendered').toBe(true);
7985
});
8086

8187
it('able to click the copy link button', async () => {
@@ -94,12 +100,7 @@ describe('NavBar', () => {
94100
user.myLink = 'https://stage.apt.mt/fakeuser/6e16a160/';
95101
expect(user.authenticated).toBe(true);
96102

97-
wrapper = mount(NavBar, {
98-
propsData: ourProps,
99-
global: {
100-
plugins: [i18ninstance, router],
101-
},
102-
});
103+
wrapper = mount(NavBar, getMountOptions());
103104

104105
// now click the copy link button and verify the link was written to the clipboard
105106
const copyLinkBtn = wrapper.find('.nav-copy-link-button');

frontend/test/components/NavBarMobile.test.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@ import withSetup from '../utils/with-setup';
77
import { useUserStore } from '@/stores/user-store';
88
import { RouterLink } from 'vue-router';
99
import NavBarMobile from '@/components/NavBarMobile.vue';
10+
import { accountsTbProfileUrlKey } from '@/keys';
1011

1112

1213
describe('NavBarMobile', () => {
1314
var app;
1415
var wrapper;
16+
const testAccountsTbProfileUrl = 'https://accounts.tb.pro/dashboard';
17+
18+
const getMountOptions = () => ({
19+
global: {
20+
plugins: [i18ninstance, router],
21+
provide: {
22+
[accountsTbProfileUrlKey]: testAccountsTbProfileUrl,
23+
},
24+
},
25+
});
1526

1627
beforeEach(() => {
1728
app = withSetup();
@@ -23,11 +34,7 @@ describe('NavBarMobile', () => {
2334
});
2435

2536
it('renders correctly when not logged in', () => {
26-
wrapper = mount(NavBarMobile, {
27-
global: {
28-
plugins: [i18ninstance, router],
29-
},
30-
});
37+
wrapper = mount(NavBarMobile, getMountOptions());
3138

3239
// verify all expected router-link child components were rendered (only one when not signed in)
3340
const allRouterLinks = wrapper.findAllComponents(RouterLink);
@@ -45,11 +52,7 @@ describe('NavBarMobile', () => {
4552
user.data.accessToken = 'abc';
4653
expect(user.authenticated).toBe(true);
4754

48-
wrapper = mount(NavBarMobile, {
49-
global: {
50-
plugins: [i18ninstance, router],
51-
},
52-
});
55+
wrapper = mount(NavBarMobile, getMountOptions());
5356

5457
// verify all expected router-link child components were rendered (only one when menu is closed)
5558
const allRouterLinks = wrapper.findAllComponents(RouterLink);
@@ -67,24 +70,19 @@ describe('NavBarMobile', () => {
6770
user.data.accessToken = 'abc';
6871
expect(user.authenticated).toBe(true);
6972

70-
wrapper = mount(NavBarMobile, {
71-
global: {
72-
plugins: [i18ninstance, router],
73-
},
74-
});
73+
wrapper = mount(NavBarMobile, getMountOptions());
7574

7675
// click to open/show the menu
7776
const menuButton = wrapper.find('button[aria-label="Open menu"]');
7877
await menuButton.trigger('click');
7978

8079
// verify all expected router-link child components were rendered when signed in and menu is now shown
8180
const expectedLinks = [
82-
'dashboard', // there are two dashboard rounter-link child components
81+
'dashboard', // there are two dashboard router-link child components
8382
'dashboard',
8483
'bookings',
8584
'availability',
8685
'settings',
87-
'profile',
8886
'report-bug',
8987
'contact',
9088
'logout'
@@ -103,6 +101,10 @@ describe('NavBarMobile', () => {
103101
for (let expLink of expectedLinks) {
104102
expect(foundLinks, 'expected link component to be rendered').toContain(expLink);
105103
}
104+
105+
// verify the anchor tag to accountsTbProfileUrl exists and has the correct href
106+
const profileAnchor = wrapper.find('a[href="' + testAccountsTbProfileUrl + '"]');
107+
expect(profileAnchor.exists(), 'expected anchor tag to accountsTbProfileUrl to be rendered').toBe(true);
106108
});
107109

108110
it('able to click the copy link button', async () => {
@@ -121,11 +123,7 @@ describe('NavBarMobile', () => {
121123
user.myLink = 'https://stage.apt.mt/fakeuser/6e16a160/';
122124
expect(user.authenticated).toBe(true);
123125

124-
wrapper = mount(NavBarMobile, {
125-
global: {
126-
plugins: [i18ninstance, router],
127-
},
128-
});
126+
wrapper = mount(NavBarMobile, getMountOptions());
129127

130128
// need to open the menu in order to access the copy link option
131129
const menuButton = wrapper.find('button[aria-label="Open menu"]');

0 commit comments

Comments
 (0)