Skip to content

Commit

Permalink
refactor: Remove outdated global imports (#14262)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc authored Dec 6, 2022
1 parent f679ff4 commit 95b5266
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 150 deletions.
1 change: 0 additions & 1 deletion setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require('fake-indexeddb/auto');

require('src/script/util/test/mock/createObjectURLMock');
require('src/script/util/test/mock/cryptoMock');
require('src/script/util/test/mock/iconsMock');
require('src/script/util/test/mock/matchMediaMock');
require('src/script/util/test/mock/mediaDevicesMock');
require('src/script/util/test/mock/navigatorPermissionsMock');
Expand Down
2 changes: 2 additions & 0 deletions src/script/components/AppContainer/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {ClientType} from '@wireapp/api-client/lib/client/';
import {container} from 'tsyringe';

import {Configuration} from '../../Config';
import {setAppLocale} from '../../localization/Localizer';
import {App} from '../../main/app';
import {AppMain} from '../../page/AppMain';
import {APIClient} from '../../service/APIClientSingleton';
Expand All @@ -36,6 +37,7 @@ interface AppProps {
}

export const AppContainer: FC<AppProps> = ({config, clientType}) => {
setAppLocale();
const app = new App(container.resolve(Core), container.resolve(APIClient), config);
// Publishing application on the global scope for debug and testing purposes.
window.wire.app = app;
Expand Down
28 changes: 0 additions & 28 deletions src/script/components/icons.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/script/entity/Conversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ describe('Conversation', () => {
it('displays "Empty Conversation" if no other participants are in the conversation', () => {
conversation_et.type(CONVERSATION_TYPE.REGULAR);

expect(conversation_et.display_name()).toBe(window.z.string.conversationsEmptyConversation);
expect(conversation_et.display_name()).toBe('Group conversation');
});

it('displays a fallback if no user name has been set for a group conversation', () => {
Expand Down
11 changes: 2 additions & 9 deletions src/script/localization/Localizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ import {getParameter} from 'Util/UrlUtil';
import {URLParameter} from '../auth/URLParameter';
import {StorageKey} from '../storage/StorageKey';

window.z = window.z || {};

const strings = {
cs,
da,
Expand All @@ -74,10 +72,9 @@ const strings = {
uk,
};

window.z.string = strings;
setStrings(strings);

(function setAppLocale() {
export function setAppLocale() {
const queryParam = getParameter(URLParameter.LOCALE);
const currentBrowserLocale = navigator.language.slice(0, 2) as LocaleType;

Expand All @@ -91,8 +88,4 @@ setStrings(strings);
setDateLocale(locale);

document.getElementsByTagName('html')[0].setAttribute('lang', locale);

if (window.z.string[locale]) {
window.z.string = {...window.z.string, ...window.z.string[DEFAULT_LOCALE], ...window.z.string[locale]};
}
})();
}
17 changes: 0 additions & 17 deletions src/script/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {Context} from '@wireapp/api-client/lib/auth';
import {ClientClassification, ClientType} from '@wireapp/api-client/lib/client/';
import {amplify} from 'amplify';
import Dexie from 'dexie';
import ko from 'knockout';
import platform from 'platform';
import {container} from 'tsyringe';

Expand All @@ -41,7 +40,6 @@ import {TIME_IN_MILLIS} from 'Util/TimeUtil';
import {appendParameter} from 'Util/UrlUtil';
import {checkIndexedDb, createRandomUuid, supportsMLS} from 'Util/util';

import './globals';
import {migrateToQualifiedSessionIds} from './sessionIdMigrator';
import {SingleInstanceHandler} from './SingleInstanceHandler';

Expand Down Expand Up @@ -103,7 +101,6 @@ import {AppInitTimingsStep} from '../telemetry/app_init/AppInitTimingsStep';
import {serverTimeHandler} from '../time/serverTimeHandler';
import {EventTrackingRepository} from '../tracking/EventTrackingRepository';
import {WindowHandler} from '../ui/WindowHandler';
import * as UserPermission from '../user/UserPermission';
import {UserRepository} from '../user/UserRepository';
import {UserService} from '../user/UserService';
import {ViewModelRepositories} from '../view_model/MainViewModel';
Expand Down Expand Up @@ -191,8 +188,6 @@ export class App {
});
}

this._publishGlobals();

const onExtraInstanceStarted = () => this._redirectToLogin(SIGN_OUT_REASON.MULTIPLE_TABS);
this.singleInstanceHandler = new SingleInstanceHandler(onExtraInstanceStarted);

Expand Down Expand Up @@ -831,16 +826,4 @@ export class App {

doRedirect(signOutReason);
}

//##############################################################################
// Debugging
//##############################################################################

private _publishGlobals() {
window.z.userPermission = ko.observable({});
ko.pureComputed(() => {
const selfUser = this.repository.user['userState'].self();
return selfUser && selfUser.teamRole();
}).subscribe(role => window.z.userPermission(UserPermission.generatePermissionHelpers(role)));
}
}
35 changes: 0 additions & 35 deletions src/script/main/globals.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/script/util/LocalizerUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,3 @@ export const replaceLink = (href: string, className: string = '', uieName: strin
'/link': '</a>',
link: `<a href="${href}" data-uie-name="${uieName}" class="${className}" rel="nofollow noopener noreferrer" target="_blank">`,
});

window.t = LocalizerUtil.translate;
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
*
*/

import {User} from 'src/script/entity/User';
import 'src/script/localization/Localizer';
import {escapeRegex, getSelfName, getUserName, safeWindowOpen} from 'src/script/util/SanitizationUtil';
import {Declension, LocalizerUtil, setStrings} from 'Util/LocalizerUtil';
import {Declension, LocalizerUtil, t} from 'Util/LocalizerUtil';

describe('SanitizationUtil', () => {
beforeEach(() => {
setStrings({en: z.string});
});
import {escapeRegex, getSelfName, getUserName, safeWindowOpen} from './SanitizationUtil';

import {User} from '../entity/User';

describe('SanitizationUtil', () => {
describe('escapeRegex', () => {
it('will return escaped regex strings', () => {
const escapedRegex = escapeRegex(':)');
Expand All @@ -48,7 +45,7 @@ describe('SanitizationUtil', () => {
userEntity.isMe = true;
const escapedSelfName = getUserName(userEntity);

expect(escapedSelfName).toEqual('you');
expect(escapedSelfName).toEqual(t('conversationYouNominative'));
});
});

Expand All @@ -57,15 +54,15 @@ describe('SanitizationUtil', () => {
// eslint-disable-line
const escapedNominativeName = getSelfName(Declension.NOMINATIVE);

expect(escapedNominativeName).toEqual('you');
expect(escapedNominativeName).toEqual(t('conversationYouNominative'));

const unescapedNominativeName = getSelfName(Declension.NOMINATIVE, true);

expect(unescapedNominativeName).toEqual('you');
expect(unescapedNominativeName).toEqual(t('conversationYouNominative'));

const escapedDativeName = getSelfName(Declension.DATIVE);

expect(escapedDativeName).toEqual('you');
expect(escapedDativeName).toEqual(t('conversationYouDative'));

spyOn(LocalizerUtil, 'translate').and.returnValue('<script>you</script>');
const escapedAccusativeName = getSelfName(Declension.DATIVE);
Expand All @@ -84,7 +81,7 @@ describe('SanitizationUtil', () => {
focus: jest.fn(),
opener: 'remove me',
};
jest.spyOn(window, 'open').mockImplementation(() => mockedWindow);
jest.spyOn(window, 'open').mockImplementation(() => mockedWindow as any);
const newWindow = safeWindowOpen('https://wire.com/');

expect(newWindow.opener).toBeNull();
Expand Down
2 changes: 1 addition & 1 deletion src/script/util/SanitizationUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const getSelfName = (declension = Declension.NOMINATIVE, bypassSanitizati
return bypassSanitization ? selfName : escape(selfName);
};

export const getUserName = (userEntity: User, declension: string, bypassSanitization: boolean = false): string => {
export const getUserName = (userEntity: User, declension?: string, bypassSanitization: boolean = false): string => {
if (userEntity.isMe) {
return getSelfName(declension, bypassSanitization);
}
Expand Down
30 changes: 0 additions & 30 deletions src/script/util/test/mock/iconsMock.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/script/util/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*
*/

import {amplify} from 'amplify';

import {Runtime} from '@wireapp/commons';
import {WebAppEvents} from '@wireapp/webapp-events';

Expand All @@ -26,6 +28,7 @@ import {ROLE} from '../user/UserPermission';

export function exposeWrapperGlobals(): void {
if (Runtime.isDesktopApp()) {
window.amplify = amplify;
window.z ||= {};

window.z.event ||= {};
Expand Down
26 changes: 13 additions & 13 deletions test/unit_tests/notification/NotificationRepositorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ describe('NotificationRepository', () => {
expect(testFactory.notification_repository.showNotification).toHaveBeenCalledTimes(1);

const trigger = testFactory.notification_repository.createTrigger(message_et, null, conversation_et);
notification_content.options.body = z.string.notificationObfuscated;
notification_content.options.body = t('notificationObfuscated');
notification_content.options.data.messageType = _message.type;
notification_content.title = z.string.notificationObfuscatedTitle;
notification_content.title = t('notificationObfuscatedTitle');
notification_content.trigger = trigger;

const [firstResultArgs] = testFactory.notification_repository.showNotification.calls.first().args;
Expand All @@ -176,11 +176,11 @@ describe('NotificationRepository', () => {
const titleLength = NotificationRepository.CONFIG.TITLE_LENGTH;
const titleText = `${message_et.user().name()} in ${conversation_et.display_name()}`;

notification_content.options.body = z.string.notificationObfuscated;
notification_content.options.body = t('notificationObfuscated');
notification_content.title = truncate(titleText, titleLength, false);
} else {
notification_content.options.body = z.string.notificationObfuscated;
notification_content.title = z.string.notificationObfuscatedTitle;
notification_content.options.body = t('notificationObfuscated');
notification_content.title = t('notificationObfuscatedTitle');
}
notification_content.options.data.messageType = _message.type;

Expand Down Expand Up @@ -372,7 +372,7 @@ describe('NotificationRepository', () => {

describe('shows a well-formed call notification', () => {
describe('for an incoming call', () => {
const expected_body = z.string.notificationVoiceChannelActivate;
const expected_body = t('notificationVoiceChannelActivate');

beforeEach(() => {
message_et = new CallMessage();
Expand All @@ -391,7 +391,7 @@ describe('NotificationRepository', () => {
});

describe('for a missed call', () => {
const expected_body = z.string.notificationVoiceChannelDeactivate;
const expected_body = t('notificationVoiceChannelDeactivate');

beforeEach(() => {
message_et = new CallMessage();
Expand Down Expand Up @@ -451,7 +451,7 @@ describe('NotificationRepository', () => {
describe('for a picture', () => {
beforeEach(() => {
message_et.assets.push(new MediumImage());
expected_body = z.string.notificationAssetAdd;
expected_body = t('notificationAssetAdd');
});

it('in a 1:1 conversation', () => {
Expand Down Expand Up @@ -479,7 +479,7 @@ describe('NotificationRepository', () => {
describe('for a location', () => {
beforeEach(() => {
message_et.assets.push(new Location());
expected_body = z.string.notificationSharedLocation;
expected_body = t('notificationSharedLocation');
});

it('in a 1:1 conversation', () => {
Expand Down Expand Up @@ -685,30 +685,30 @@ describe('NotificationRepository', () => {
connectionEntity.status = 'pending';
message_et.memberMessageType = SystemMessageType.CONNECTION_REQUEST;

const expected_body = z.string.notificationConnectionRequest;
const expected_body = t('notificationConnectionRequest');
expect(expected_body).toBeDefined();
return verifyNotificationSystem(conversation_et, message_et, expected_body, expected_title);
});

it('if your connection request was accepted', () => {
message_et.memberMessageType = SystemMessageType.CONNECTION_ACCEPTED;

const expected_body = z.string.notificationConnectionAccepted;
const expected_body = t('notificationConnectionAccepted');
expect(expected_body).toBeDefined();
return verifyNotificationSystem(conversation_et, message_et, expected_body, expected_title);
});

it('if you are automatically connected', () => {
message_et.memberMessageType = SystemMessageType.CONNECTION_CONNECTED;

const expected_body = z.string.notificationConnectionConnected;
const expected_body = t('notificationConnectionConnected');
expect(expected_body).toBeDefined();
return verifyNotificationSystem(conversation_et, message_et, expected_body, expected_title);
});
});

describe('shows a well-formed ping notification', () => {
const expected_body = z.string.notificationPing;
const expected_body = t('notificationPing');

beforeAll(() => {
user_et = testFactory.user_repository.userMapper.mapUserFromJson(payload.users.get.one[0]);
Expand Down

0 comments on commit 95b5266

Please sign in to comment.