[MM-58563] Load profiles on sidebar load irrespective of the current channel (#27992)
* [MM-58563] Load profiles on sidebar load irrespective of the current channel * Remove await --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
efbb70f3c8
Коммит
eafe056bea
@@ -96,22 +96,25 @@ describe('/components/data_prefetch', () => {
|
|||||||
expect(instance.prefetchPosts).toHaveBeenCalledWith('currentChannelId');
|
expect(instance.prefetchPosts).toHaveBeenCalledWith('currentChannelId');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should fetch profiles for sidebar on first channel load', async () => {
|
test('should fetch profiles for sidebar on sidebar load', async () => {
|
||||||
const props = defaultProps;
|
const props = {
|
||||||
|
...defaultProps,
|
||||||
|
sidebarLoaded: false,
|
||||||
|
};
|
||||||
const wrapper = shallow<DataPrefetch>(
|
const wrapper = shallow<DataPrefetch>(
|
||||||
<DataPrefetch {...props}/>,
|
<DataPrefetch {...props}/>,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(loadProfilesForSidebar).not.toHaveBeenCalled();
|
expect(loadProfilesForSidebar).not.toHaveBeenCalled();
|
||||||
|
|
||||||
// Change channels
|
// Finish loading the sidebar
|
||||||
wrapper.setProps({currentChannelId: 'currentChannelId'});
|
wrapper.setProps({sidebarLoaded: true});
|
||||||
await Promise.resolve(true);
|
await Promise.resolve(true);
|
||||||
|
|
||||||
expect(loadProfilesForSidebar).toHaveBeenCalledTimes(1);
|
expect(loadProfilesForSidebar).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
// Change channels again
|
// Reload the sidebar
|
||||||
wrapper.setProps({currentChannelId: 'anotherChannelId'});
|
wrapper.setProps({sidebarLoaded: true});
|
||||||
await Promise.resolve(true);
|
await Promise.resolve(true);
|
||||||
|
|
||||||
expect(loadProfilesForSidebar).toHaveBeenCalledTimes(1);
|
expect(loadProfilesForSidebar).toHaveBeenCalledTimes(1);
|
||||||
@@ -345,7 +348,7 @@ describe('/components/data_prefetch', () => {
|
|||||||
expect(props.actions.prefetchChannelPosts).toHaveBeenCalledWith('mentionChannel', undefined);
|
expect(props.actions.prefetchChannelPosts).toHaveBeenCalledWith('mentionChannel', undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should load profiles once the current channel and sidebar are both loaded', () => {
|
test('should load profiles once the sidebar is loaded irrespective of the current channel', () => {
|
||||||
const props = {
|
const props = {
|
||||||
...defaultProps,
|
...defaultProps,
|
||||||
currentChannelId: '',
|
currentChannelId: '',
|
||||||
@@ -374,36 +377,5 @@ describe('/components/data_prefetch', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(loadProfilesForSidebar).toHaveBeenCalled();
|
expect(loadProfilesForSidebar).toHaveBeenCalled();
|
||||||
|
|
||||||
jest.clearAllMocks();
|
|
||||||
|
|
||||||
// With sidebar loaded first
|
|
||||||
wrapper = shallow<DataPrefetch>(
|
|
||||||
<DataPrefetch {...props}/>,
|
|
||||||
);
|
|
||||||
wrapper.setProps({
|
|
||||||
sidebarLoaded: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(loadProfilesForSidebar).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
wrapper.setProps({
|
|
||||||
currentChannelId: 'channel',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(loadProfilesForSidebar).toHaveBeenCalled();
|
|
||||||
|
|
||||||
jest.clearAllMocks();
|
|
||||||
|
|
||||||
// With both loaded at once
|
|
||||||
wrapper = shallow<DataPrefetch>(
|
|
||||||
<DataPrefetch {...props}/>,
|
|
||||||
);
|
|
||||||
wrapper.setProps({
|
|
||||||
currentChannelId: 'channel',
|
|
||||||
sidebarLoaded: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(loadProfilesForSidebar).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -56,9 +56,12 @@ export default class DataPrefetch extends React.PureComponent<Props> {
|
|||||||
|
|
||||||
async componentDidUpdate(prevProps: Props) {
|
async componentDidUpdate(prevProps: Props) {
|
||||||
const {currentChannelId, prefetchQueueObj, sidebarLoaded} = this.props;
|
const {currentChannelId, prefetchQueueObj, sidebarLoaded} = this.props;
|
||||||
|
if (sidebarLoaded && !prevProps.sidebarLoaded) {
|
||||||
|
loadProfilesForSidebar();
|
||||||
|
}
|
||||||
|
|
||||||
if (currentChannelId && sidebarLoaded && (!prevProps.currentChannelId || !prevProps.sidebarLoaded)) {
|
if (currentChannelId && sidebarLoaded && (!prevProps.currentChannelId || !prevProps.sidebarLoaded)) {
|
||||||
queue.add(async () => this.prefetchPosts(currentChannelId));
|
queue.add(async () => this.prefetchPosts(currentChannelId));
|
||||||
await loadProfilesForSidebar();
|
|
||||||
this.prefetchData();
|
this.prefetchData();
|
||||||
} else if (prevProps.prefetchQueueObj !== prefetchQueueObj) {
|
} else if (prevProps.prefetchQueueObj !== prefetchQueueObj) {
|
||||||
clearTimeout(this.prefetchTimeout);
|
clearTimeout(this.prefetchTimeout);
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user