Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set app version as dev when building locally #1237

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/routes/Settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ describe('routes/Settings.tsx', () => {
Object.defineProperty(process, 'platform', {
value: originalPlatform,
});

// Restore the original node env value
Object.defineProperty(process, 'platform', {
value: originalPlatform,
});
});

describe('General', () => {
Expand Down Expand Up @@ -481,6 +486,68 @@ describe('routes/Settings.tsx', () => {
});

describe('Footer section', () => {
describe('app version', () => {
let originalEnv: NodeJS.ProcessEnv;

beforeEach(() => {
// Save the original node env state
originalEnv = process.env;
});

afterEach(() => {
// Restore the original node env state
process.env = originalEnv;
});

it('should show production app version', async () => {
process.env = {
...originalEnv,
NODE_ENV: 'production',
};

await act(async () => {
render(
<AppContext.Provider
value={{
auth: mockAuth,
settings: mockSettings,
}}
>
<MemoryRouter>
<SettingsRoute />
</MemoryRouter>
</AppContext.Provider>,
);
});

expect(screen.getByTitle('app-version')).toMatchSnapshot();
});

it('should show development app version', async () => {
process.env = {
...originalEnv,
NODE_ENV: 'development',
};

await act(async () => {
render(
<AppContext.Provider
value={{
auth: mockAuth,
settings: mockSettings,
}}
>
<MemoryRouter>
<SettingsRoute />
</MemoryRouter>
</AppContext.Provider>,
);
});

expect(screen.getByTitle('app-version')).toMatchSnapshot();
});
});

it('should open release notes', async () => {
const openExternalLinkMock = jest.spyOn(comms, 'openExternalLink');

Expand Down
11 changes: 8 additions & 3 deletions src/routes/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ export const SettingsRoute: FC = () => {

useEffect(() => {
(async () => {
const result = await getAppVersion();
setAppVersion(result);
console.log('process.env.NODE_ENV', process.env.NODE_ENV);
if (process.env.NODE_ENV === 'development') {
setAppVersion('dev');
} else {
const result = await getAppVersion();
setAppVersion(`v${result}`);
}
})();

ipcRenderer.on('gitify:update-theme', (_, updatedTheme: Theme) => {
Expand Down Expand Up @@ -283,7 +288,7 @@ export const SettingsRoute: FC = () => {
title="View release notes"
onClick={() => openGitifyReleaseNotes(appVersion)}
>
Gitify v{appVersion}
<span title="app-version">Gitify {appVersion}</span>
</button>
<div>
<button
Expand Down
26 changes: 24 additions & 2 deletions src/routes/__snapshots__/Settings.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/utils/links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('utils/links.ts', () => {
});

it('openGitifyReleaseNotes', () => {
openGitifyReleaseNotes('1.0.0');
openGitifyReleaseNotes('v1.0.0');
expect(comms.openExternalLink).toHaveBeenCalledWith(
'https://github.com/gitify-app/gitify/releases/tag/v1.0.0',
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function openGitifyRepository() {

export function openGitifyReleaseNotes(version: string) {
openExternalLink(
`https://github.com/${Constants.REPO_SLUG}/releases/tag/v${version}` as Link,
`https://github.com/${Constants.REPO_SLUG}/releases/tag/${version}` as Link,
);
}

Expand Down