Fix some frontend linting issues (#2495) [ci skip]
This commit is contained in:
parent
42606d3a49
commit
27ea00e152
7 changed files with 26 additions and 76 deletions
|
|
@ -22,9 +22,12 @@ module.exports = {
|
|||
},
|
||||
],
|
||||
'import/prefer-default-export': 'off',
|
||||
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
||||
},
|
||||
globals: {
|
||||
InstantClick: false,
|
||||
filterXSS: false,
|
||||
Pusher: false,
|
||||
algoliasearch: false,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ global.document.head.innerHTML =
|
|||
"<meta name='environment' content='test' />";
|
||||
|
||||
const mockIndex = {
|
||||
search: (query, options) =>
|
||||
new Promise((resolve, reject) => {
|
||||
search: (query, _options) =>
|
||||
new Promise((resolve, _reject) => {
|
||||
process.nextTick(() => {
|
||||
const searchResults = {
|
||||
gi: {
|
||||
|
|
@ -56,7 +56,7 @@ const mockIndex = {
|
|||
}),
|
||||
};
|
||||
const client = {
|
||||
initIndex: index => mockIndex,
|
||||
initIndex: _index => mockIndex,
|
||||
};
|
||||
|
||||
export default jest.fn().mockImplementation((id, key) => client);
|
||||
export default jest.fn().mockImplementation((_id, _key) => client);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ const mockIndex = {
|
|||
}),
|
||||
};
|
||||
const client = {
|
||||
initIndex: index => mockIndex, // eslint-ignore-line
|
||||
initIndex: _index => mockIndex, // eslint-ignore-line
|
||||
};
|
||||
|
||||
export default jest.fn().mockImplementation((id, key) => client); // eslint-ignore-line
|
||||
export default jest.fn().mockImplementation((_id_, _key) => client); // eslint-ignore-line
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ export function getChannels(
|
|||
paginationNumber,
|
||||
additionalFilters,
|
||||
successCb,
|
||||
failureCb,
|
||||
_failureCb,
|
||||
) {
|
||||
const client = algoliasearch(props.algoliaId, props.algoliaKey);
|
||||
const index = client.initIndex(props.algoliaIndex);
|
||||
|
|
@ -90,7 +90,7 @@ export function getChannels(
|
|||
},
|
||||
...additionalFilters,
|
||||
};
|
||||
index.search(query, filters).then(function(content) {
|
||||
index.search(query, filters).then(content => {
|
||||
const channels = content.hits;
|
||||
if (
|
||||
retrievalID === null ||
|
||||
|
|
@ -98,7 +98,7 @@ export function getChannels(
|
|||
) {
|
||||
successCb(channels, query);
|
||||
} else {
|
||||
index.getObjects([`${retrievalID}`], function(err, content) {
|
||||
index.getObjects([`${retrievalID}`], (_err, _content) => {
|
||||
channels.unshift(content.results[0]);
|
||||
successCb(channels, query);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
import { getUserData } from '../getUserData';
|
||||
|
||||
describe('getUserData', () => {
|
||||
beforeEach(() => {
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.setAttribute('data-user', null);
|
||||
});
|
||||
|
||||
it('returns user data if available in document', async () => {
|
||||
document.body.setAttribute('data-user', '{}');
|
||||
const data = getUserData().then(d => d);
|
||||
expect(setInterval).toHaveBeenCalledTimes(1);
|
||||
expect(setInterval).toHaveBeenLastCalledWith(expect.any(Function), 5);
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(clearInterval).toHaveBeenCalledTimes(1);
|
||||
await expect(data).resolves.toEqual({});
|
||||
});
|
||||
|
||||
it('return error rejects if no user data is located', async () => {
|
||||
const data = getUserData().then(d => d);
|
||||
expect(setInterval).toHaveBeenCalledTimes(1);
|
||||
expect(setInterval).toHaveBeenLastCalledWith(expect.any(Function), 5);
|
||||
jest.advanceTimersByTime(200000);
|
||||
expect(clearInterval).toHaveBeenCalledTimes(1);
|
||||
await expect(data).rejects.toEqual("Couldn't find user data on page.");
|
||||
});
|
||||
});
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
export function getUserData() {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
let i = 0;
|
||||
const waitingOnUserData = setInterval(() => {
|
||||
let userData = null;
|
||||
const dataUserAttribute = document.body.getAttribute('data-user');
|
||||
if (dataUserAttribute && dataUserAttribute !== 'undefined' && dataUserAttribute !== undefined) {
|
||||
userData = JSON.parse(dataUserAttribute);
|
||||
}
|
||||
i += 1;
|
||||
if (userData) {
|
||||
clearInterval(waitingOnUserData);
|
||||
resolve(userData);
|
||||
} else if (i === 3000) {
|
||||
clearInterval(waitingOnUserData);
|
||||
reject("Couldn't find user data on page.");
|
||||
}
|
||||
}, 5);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
export default 'getUserData';
|
||||
|
|
@ -1,35 +1,35 @@
|
|||
// import Pusher from 'pusher-js';
|
||||
|
||||
export default function setupPusher(key, callbackObjects) {
|
||||
let pusher;
|
||||
return import('pusher-js')
|
||||
.then(({ }) => {
|
||||
if (window.pusher) {
|
||||
pusher = window.pusher
|
||||
} else {
|
||||
return import('pusher-js').then(_ => {
|
||||
const {
|
||||
pusher = new Pusher(key, {
|
||||
authEndpoint: '/pusher/auth',
|
||||
auth: {
|
||||
headers: {
|
||||
'X-CSRF-Token': window.csrfToken
|
||||
}
|
||||
'X-CSRF-Token': window.csrfToken,
|
||||
},
|
||||
},
|
||||
cluster: 'us2',
|
||||
encrypted: true,
|
||||
});
|
||||
window.pusher = pusher;
|
||||
}
|
||||
}),
|
||||
} = window;
|
||||
|
||||
window.pusher = pusher;
|
||||
|
||||
const channel = pusher.subscribe(callbackObjects.channelId.toString());
|
||||
channel.bind('message-created', callbackObjects.messageCreated);
|
||||
channel.bind('channel-cleared', callbackObjects.channelCleared);
|
||||
channel.bind('user-banned', callbackObjects.redactUserMessages);
|
||||
channel.bind('client-livecode', callbackObjects.liveCoding);
|
||||
channel.bind('client-initiatevideocall', callbackObjects.videoCallInitiated);
|
||||
channel.bind(
|
||||
'client-initiatevideocall',
|
||||
callbackObjects.videoCallInitiated,
|
||||
);
|
||||
channel.bind('client-endvideocall', callbackObjects.videoCallEnded);
|
||||
|
||||
|
||||
// channel.bind('pusher:subscription_succeeded', callbackObjects.channelSubscribed);
|
||||
channel.bind('pusher:subscription_error', callbackObjects.channelError);
|
||||
return channel;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue