Skip to content

Commit 71087a2

Browse files
feat(header): mark Research Edition builds (#941)
* feat(header): mark Research Edition builds * test(header): cover build flag rendering path
1 parent d4bfd6f commit 71087a2

11 files changed

Lines changed: 82 additions & 1 deletion

File tree

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"globals": {
5757
"PRODUCTION": false,
5858
"AW_SERVER_URL": false,
59-
"COMMIT_HASH": false
59+
"COMMIT_HASH": false,
60+
"AW_RESEARCH_EDITION": false
6061
},
6162
"overrides": [
6263
{

src/components/Header.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ div(:class="{'fixed-top-padding': fixedTopMenu}")
66
b-navbar-brand(to="/" style="background-color: transparent;")
77
img.aligh-middle(src="/logo.png" style="height: 1.5em;")
88
span.ml-2.align-middle(style="font-size: 1em; color: #000;") {{ $t('app.name') }}
9+
b-badge.ml-2.align-middle(v-if="researchEdition" variant="info" data-testid="research-edition-badge") {{ $t('app.researchEdition') }}
910

1011
b-navbar-toggle(target="nav-collapse")
1112

@@ -47,6 +48,7 @@ div(:class="{'fixed-top-padding': fixedTopMenu}")
4748
b-navbar-brand(to="/" style="background-color: transparent;")
4849
img.ml-0.aligh-middle(src="/logo.png" style="height: 1.5em;")
4950
span.ml-2.align-middle(style="font-size: 1.0em; color: #000;") {{ $t('app.name') }}
51+
b-badge.ml-2.align-middle(v-if="researchEdition" variant="info" data-testid="research-edition-badge") {{ $t('app.researchEdition') }}
5052

5153
b-navbar-nav.ml-auto
5254
b-nav-item-dropdown
@@ -137,6 +139,7 @@ export default {
137139
return {
138140
activityViews: null,
139141
fixedTopMenu: this.$isAndroid,
142+
researchEdition: typeof AW_RESEARCH_EDITION !== 'undefined' && AW_RESEARCH_EDITION,
140143
};
141144
},
142145
computed: {

src/globals.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
declare const PRODUCTION: boolean;
66
declare const AW_SERVER_URL: string;
77
declare const COMMIT_HASH: string;
8+
declare const AW_RESEARCH_EDITION: boolean;
89
// JSON-encoded preset category sets shipped by this build (empty string if none).
910
// See src/util/presetCategories.ts
1011
declare const AW_PRESET_CATEGORY_SETS: string;

src/i18n/locales/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default {
22
app: {
33
name: 'ActivityWatch',
4+
researchEdition: 'Research Edition',
45
},
56
nav: {
67
activity: 'Aktivität',

src/i18n/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default {
22
app: {
33
name: 'ActivityWatch',
4+
researchEdition: 'Research Edition',
45
},
56
nav: {
67
activity: 'Activity',

src/i18n/locales/ru.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default {
22
app: {
33
name: 'ActivityWatch',
4+
researchEdition: 'Research Edition',
45
},
56
nav: {
67
activity: 'Активность',

src/i18n/locales/uk.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default {
22
app: {
33
name: 'ActivityWatch',
4+
researchEdition: 'Research Edition',
45
},
56
nav: {
67
activity: 'Активність',

src/i18n/locales/zh-CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export default {
33
app: {
44
name: 'ActivityWatch',
5+
researchEdition: 'Research Edition',
56
},
67
nav: {
78
activity: '活动',

test/unit/Header.test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { shallowMount } from '@vue/test-utils';
2+
import { createPinia, setActivePinia } from 'pinia';
3+
import Header from '~/components/Header.vue';
4+
5+
const mockEnsureLoaded = jest.fn().mockResolvedValue(undefined);
6+
const passthroughStub = { template: '<div><slot /></div>' };
7+
8+
jest.mock('~/stores/buckets', () => ({
9+
useBucketsStore: () => ({
10+
ensureLoaded: mockEnsureLoaded,
11+
buckets: [],
12+
}),
13+
}));
14+
15+
describe('Header research edition badge', () => {
16+
afterEach(() => {
17+
delete global.AW_RESEARCH_EDITION;
18+
});
19+
20+
beforeEach(() => {
21+
setActivePinia(createPinia());
22+
mockEnsureLoaded.mockClear();
23+
});
24+
25+
function mountHeader(buildFlag) {
26+
if (buildFlag === undefined) {
27+
delete global.AW_RESEARCH_EDITION;
28+
} else {
29+
global.AW_RESEARCH_EDITION = buildFlag;
30+
}
31+
32+
return shallowMount(Header, {
33+
mocks: {
34+
$isAndroid: false,
35+
$t: key => key,
36+
},
37+
stubs: {
38+
'b-navbar': passthroughStub,
39+
'b-navbar-nav': passthroughStub,
40+
'b-navbar-brand': passthroughStub,
41+
'b-navbar-toggle': passthroughStub,
42+
'b-collapse': passthroughStub,
43+
'b-nav-item': passthroughStub,
44+
'b-nav-item-dropdown': passthroughStub,
45+
'b-dropdown-item': passthroughStub,
46+
'b-badge': passthroughStub,
47+
icon: passthroughStub,
48+
},
49+
});
50+
}
51+
52+
test('renders a badge in both brand sites for research builds', () => {
53+
const wrapper = mountHeader(true);
54+
55+
expect(wrapper.findAll('[data-testid="research-edition-badge"]')).toHaveLength(2);
56+
});
57+
58+
test('renders no badge for standard builds', () => {
59+
const wrapper = mountHeader(false);
60+
61+
expect(wrapper.findAll('[data-testid="research-edition-badge"]')).toHaveLength(0);
62+
});
63+
64+
test('renders no badge when the build flag is absent', () => {
65+
const wrapper = mountHeader(undefined);
66+
67+
expect(wrapper.findAll('[data-testid="research-edition-badge"]')).toHaveLength(0);
68+
});
69+
});

vite.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default defineConfig(({ mode }) => {
9191
PRODUCTION,
9292
AW_SERVER_URL: process.env.AW_SERVER_URL,
9393
COMMIT_HASH: process.env.COMMIT_HASH,
94+
AW_RESEARCH_EDITION: process.env.AW_RESEARCH_EDITION === 'true',
9495
// Optional JSON preset category sets shipped by this build (see src/util/presetCategories.ts)
9596
AW_PRESET_CATEGORY_SETS: JSON.stringify(process.env.AW_PRESET_CATEGORY_SETS || ''),
9697
'process.env.VUE_APP_ON_ANDROID': process.env.VUE_APP_ON_ANDROID,

0 commit comments

Comments
 (0)