* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import userEvent from '@testing-library/user-event';
+import { addDays, formatISO, subDays } from 'date-fns';
import * as React from 'react';
import { getSystemUpgrades } from '../../../api/system';
import { UpdateUseCase } from '../../../components/upgrade/utils';
import { mockAppState, mockCurrentUser } from '../../../helpers/testMocks';
import { renderComponent } from '../../../helpers/testReactTestingUtils';
import { byRole } from '../../../helpers/testSelector';
+import { AppState } from '../../../types/appstate';
import { Permissions } from '../../../types/permissions';
import { CurrentUser } from '../../../types/users';
import { AppStateContext } from '../app-state/AppStateContext';
expect(ui.updateMessage.query()).not.toBeInTheDocument();
});
+it('should show error message if upgrades call failed and the version has reached eol', async () => {
+ jest.mocked(getSystemUpgrades).mockReturnValue(Promise.reject(new Error('error')));
+ renderUpdateNotification(undefined, undefined, {
+ versionEOL: formatISO(subDays(new Date(), 1), { representation: 'date' }),
+ });
+ expect(await ui.updateMessage.find()).toHaveTextContent(
+ `admin_notification.update.${UpdateUseCase.CurrentVersionInactive}`,
+ );
+ expect(ui.openDialogBtn.query()).not.toBeInTheDocument();
+});
+
+it('should not show the notification banner if there is no network connection and version has not reached the eol', () => {
+ jest.mocked(getSystemUpgrades).mockResolvedValue({
+ upgrades: [],
+ });
+ renderUpdateNotification(undefined, undefined, {
+ versionEOL: formatISO(addDays(new Date(), 1), { representation: 'date' }),
+ });
+ expect(ui.updateMessage.query()).not.toBeInTheDocument();
+});
+
+it('should show the error banner if there is no network connection and version has reached the eol', async () => {
+ jest.mocked(getSystemUpgrades).mockResolvedValue({
+ upgrades: [],
+ });
+ renderUpdateNotification(undefined, undefined, {
+ versionEOL: formatISO(subDays(new Date(), 1), { representation: 'date' }),
+ });
+ expect(await ui.updateMessage.find()).toHaveTextContent(
+ `admin_notification.update.${UpdateUseCase.CurrentVersionInactive}`,
+ );
+ expect(ui.openDialogBtn.query()).not.toBeInTheDocument();
+});
+
it('active / latest / patch', async () => {
jest.mocked(getSystemUpgrades).mockResolvedValue({
upgrades: [{ downloadUrl: '', version: '10.5.1' }],
installedVersionActive: true,
});
const user = userEvent.setup();
- renderUpdateNotification(undefined, undefined, '9.9.0');
+ renderUpdateNotification(undefined, undefined, { version: '9.9.0' });
expect(await ui.updateMessage.find()).toHaveTextContent(
`admin_notification.update.${UpdateUseCase.NewPatch}`,
);
installedVersionActive: true,
});
const user = userEvent.setup();
- renderUpdateNotification(undefined, undefined, '9.9.0');
+ renderUpdateNotification(undefined, undefined, { version: '9.9.0' });
expect(await ui.updateMessage.find()).toHaveTextContent(
`admin_notification.update.${UpdateUseCase.NewVersion}`,
);
installedVersionActive: true,
});
const user = userEvent.setup();
- renderUpdateNotification(undefined, undefined, '9.9.0');
+ renderUpdateNotification(undefined, undefined, { version: '9.9.0' });
expect(await ui.updateMessage.find()).toHaveTextContent(
`admin_notification.update.${UpdateUseCase.NewPatch}`,
);
installedVersionActive: true,
});
const user = userEvent.setup();
- renderUpdateNotification(undefined, undefined, '8.9.0');
+ renderUpdateNotification(undefined, undefined, { version: '8.9.0' });
expect(await ui.updateMessage.find()).toHaveTextContent(
`admin_notification.update.${UpdateUseCase.NewPatch}`,
);
installedVersionActive: true,
});
const user = userEvent.setup();
- renderUpdateNotification(undefined, undefined, '8.9.0');
+ renderUpdateNotification(undefined, undefined, { version: '8.9.0' });
expect(await ui.updateMessage.find()).toHaveTextContent(
`admin_notification.update.${UpdateUseCase.NewPatch}`,
);
installedVersionActive: false,
});
const user = userEvent.setup();
- renderUpdateNotification(undefined, undefined, '8.9.0');
+ renderUpdateNotification(undefined, undefined, { version: '8.9.0' });
expect(await ui.updateMessage.find()).toHaveTextContent(
`admin_notification.update.${UpdateUseCase.CurrentVersionInactive}`,
);
installedVersionActive: false,
});
const user = userEvent.setup();
- renderUpdateNotification(undefined, undefined, '8.9.0');
+ renderUpdateNotification(undefined, undefined, { version: '8.9.0' });
expect(await ui.updateMessage.find()).toHaveTextContent(
`admin_notification.update.${UpdateUseCase.CurrentVersionInactive}`,
);
installedVersionActive: false,
});
const user = userEvent.setup();
- renderUpdateNotification(undefined, undefined, '8.9.0');
+ renderUpdateNotification(undefined, undefined, { version: '8.9.0' });
expect(await ui.updateMessage.find()).toHaveTextContent(
`admin_notification.update.${UpdateUseCase.CurrentVersionInactive}`,
);
function renderUpdateNotification(
dissmissable: boolean = false,
user?: Partial<CurrentUser>,
- version: string = '10.5.0',
+ // versionEOL is a date in the past to be sure that it is not used when we have data from upgrades endpoint
+ appState: Partial<AppState> = { version: '10.5.0', versionEOL: '2020-01-01' },
) {
return renderComponent(
<CurrentUserContext.Provider
updateDismissedNotices: () => {},
}}
>
- <AppStateContext.Provider value={mockAppState({ version })}>
+ <AppStateContext.Provider value={mockAppState(appState)}>
<UpdateNotification dismissable={dissmissable} />
</AppStateContext.Provider>
</CurrentUserContext.Provider>,
import SystemUpgradeButton from '../../../components/upgrade/SystemUpgradeButton';
import { UpdateUseCase } from '../../../components/upgrade/utils';
import { translate } from '../../../helpers/l10n';
+import { isCurrentVersionEOLActive } from '../../../helpers/system';
import { hasGlobalPermission } from '../../../helpers/users';
import { useSystemUpgrades } from '../../../queries/system';
import { Permissions } from '../../../types/permissions';
isLoggedIn(currentUser) && hasGlobalPermission(currentUser, Permissions.Admin);
const regExpParsedVersion = VERSION_PARSER.exec(appState.version);
- const { data } = useSystemUpgrades({
+ const { data, isLoading } = useSystemUpgrades({
enabled: canUserSeeNotification && regExpParsedVersion !== null,
});
- if (
- !canUserSeeNotification ||
- regExpParsedVersion === null ||
- data === undefined ||
- isEmpty(data.upgrades)
- ) {
+ if (!canUserSeeNotification || regExpParsedVersion === null || isLoading) {
return null;
}
- const { upgrades, installedVersionActive, latestLTA } = data;
+ const { upgrades = [], installedVersionActive, latestLTA } = data ?? {};
+
+ let active = installedVersionActive;
+
+ if (installedVersionActive === undefined) {
+ active = isCurrentVersionEOLActive(appState.versionEOL);
+ }
+
+ if (active && isEmpty(upgrades)) {
+ return null;
+ }
const parsedVersion = regExpParsedVersion
.slice(1)
let useCase = UpdateUseCase.NewVersion;
- if (!installedVersionActive) {
+ if (!active) {
useCase = UpdateUseCase.CurrentVersionInactive;
} else if (
isPatchUpdate(parsedVersion, systemUpgrades) &&
- (isCurrentVersionLTA(parsedVersion, latestLTA) || !isMinorUpdate(parsedVersion, systemUpgrades))
+ ((latestLTA !== undefined && isCurrentVersionLTA(parsedVersion, latestLTA)) ||
+ !isMinorUpdate(parsedVersion, systemUpgrades))
) {
useCase = UpdateUseCase.NewPatch;
}
new Date(upgrade1.releaseDate ?? '').getTime(),
)[0];
- const dismissKey = useCase + latest.version;
+ const dismissKey = useCase + (latest?.version ?? appState.version);
return dismissable ? (
<DismissableAlert