Upgrade underscore.js

This commit is contained in:
Tim Zallmann 2018-05-07 09:08:43 +00:00 committed by Filipa Lacerda
parent f460e2dc0f
commit 958e9f0986
6 changed files with 42 additions and 31 deletions

View file

@ -100,9 +100,10 @@ export default {
fetchSearchedProjects(searchQuery) { fetchSearchedProjects(searchQuery) {
this.searchQuery = searchQuery; this.searchQuery = searchQuery;
this.toggleLoader(true); this.toggleLoader(true);
this.service.getSearchedProjects(this.searchQuery) this.service
.getSearchedProjects(this.searchQuery)
.then(res => res.json()) .then(res => res.json())
.then((results) => { .then(results => {
this.toggleSearchProjectsList(true); this.toggleSearchProjectsList(true);
this.store.setSearchedProjects(results); this.store.setSearchedProjects(results);
}) })

View file

@ -50,7 +50,7 @@ export default class ProjectsService {
} else { } else {
// Check if project is already present in frequents list // Check if project is already present in frequents list
// When found, update metadata of it. // When found, update metadata of it.
storedFrequentProjects = JSON.parse(storedRawProjects).map((projectItem) => { storedFrequentProjects = JSON.parse(storedRawProjects).map(projectItem => {
if (projectItem.id === project.id) { if (projectItem.id === project.id) {
matchFound = true; matchFound = true;
const diff = Math.abs(project.lastAccessedOn - projectItem.lastAccessedOn) / HOUR_IN_MS; const diff = Math.abs(project.lastAccessedOn - projectItem.lastAccessedOn) / HOUR_IN_MS;
@ -104,13 +104,17 @@ export default class ProjectsService {
return []; return [];
} }
if (bp.getBreakpointSize() === 'sm' || if (bp.getBreakpointSize() === 'sm' || bp.getBreakpointSize() === 'xs') {
bp.getBreakpointSize() === 'xs') {
frequentProjectsCount = FREQUENT_PROJECTS.LIST_COUNT_MOBILE; frequentProjectsCount = FREQUENT_PROJECTS.LIST_COUNT_MOBILE;
} }
const frequentProjects = storedFrequentProjects const frequentProjects = storedFrequentProjects.filter(
.filter(project => project.frequency >= FREQUENT_PROJECTS.ELIGIBLE_FREQUENCY); project => project.frequency >= FREQUENT_PROJECTS.ELIGIBLE_FREQUENCY,
);
if (!frequentProjects || frequentProjects.length === 0) {
return [];
}
// Sort all frequent projects in decending order of frequency // Sort all frequent projects in decending order of frequency
// and then by lastAccessedOn with recent most first // and then by lastAccessedOn with recent most first

View file

@ -0,0 +1,5 @@
---
title: Upgrade underscore.js to 1.9.0
merge_request: 18578
author:
type: other

View file

@ -80,7 +80,7 @@
"three-orbit-controls": "^82.1.0", "three-orbit-controls": "^82.1.0",
"three-stl-loader": "^1.0.4", "three-stl-loader": "^1.0.4",
"timeago.js": "^3.0.2", "timeago.js": "^3.0.2",
"underscore": "^1.8.3", "underscore": "^1.9.0",
"url-loader": "^0.6.2", "url-loader": "^0.6.2",
"visibilityjs": "^1.2.4", "visibilityjs": "^1.2.4",
"vue": "^2.5.16", "vue": "^2.5.16",

View file

@ -23,17 +23,18 @@ const createComponent = () => {
}); });
}; };
const returnServicePromise = (data, failed) => new Promise((resolve, reject) => { const returnServicePromise = (data, failed) =>
if (failed) { new Promise((resolve, reject) => {
reject(data); if (failed) {
} else { reject(data);
resolve({ } else {
json() { resolve({
return data; json() {
}, return data;
}); },
} });
}); }
});
describe('AppComponent', () => { describe('AppComponent', () => {
describe('computed', () => { describe('computed', () => {
@ -185,7 +186,7 @@ describe('AppComponent', () => {
describe('fetchSearchedProjects', () => { describe('fetchSearchedProjects', () => {
const searchQuery = 'test'; const searchQuery = 'test';
it('should perform search with provided search query', (done) => { it('should perform search with provided search query', done => {
const mockData = [mockRawProject]; const mockData = [mockRawProject];
spyOn(vm, 'toggleLoader'); spyOn(vm, 'toggleLoader');
spyOn(vm, 'toggleSearchProjectsList'); spyOn(vm, 'toggleSearchProjectsList');
@ -203,7 +204,7 @@ describe('AppComponent', () => {
}, 0); }, 0);
}); });
it('should update props for showing search failure', (done) => { it('should update props for showing search failure', done => {
spyOn(vm, 'toggleSearchProjectsList'); spyOn(vm, 'toggleSearchProjectsList');
spyOn(vm.service, 'getSearchedProjects').and.returnValue(returnServicePromise({}, true)); spyOn(vm.service, 'getSearchedProjects').and.returnValue(returnServicePromise({}, true));
@ -219,7 +220,7 @@ describe('AppComponent', () => {
}); });
describe('logCurrentProjectAccess', () => { describe('logCurrentProjectAccess', () => {
it('should log current project access via service', (done) => { it('should log current project access via service', done => {
spyOn(vm.service, 'logProjectAccess'); spyOn(vm.service, 'logProjectAccess');
vm.currentProject = mockProject; vm.currentProject = mockProject;
@ -257,7 +258,7 @@ describe('AppComponent', () => {
}); });
describe('created', () => { describe('created', () => {
it('should bind event listeners on eventHub', (done) => { it('should bind event listeners on eventHub', done => {
spyOn(eventHub, '$on'); spyOn(eventHub, '$on');
createComponent().$mount(); createComponent().$mount();
@ -273,7 +274,7 @@ describe('AppComponent', () => {
}); });
describe('beforeDestroy', () => { describe('beforeDestroy', () => {
it('should unbind event listeners on eventHub', (done) => { it('should unbind event listeners on eventHub', done => {
const vm = createComponent(); const vm = createComponent();
spyOn(eventHub, '$off'); spyOn(eventHub, '$off');
@ -305,7 +306,7 @@ describe('AppComponent', () => {
expect(vm.$el.querySelector('.search-input-container')).toBeDefined(); expect(vm.$el.querySelector('.search-input-container')).toBeDefined();
}); });
it('should render loading animation', (done) => { it('should render loading animation', done => {
vm.toggleLoader(true); vm.toggleLoader(true);
Vue.nextTick(() => { Vue.nextTick(() => {
const loadingEl = vm.$el.querySelector('.loading-animation'); const loadingEl = vm.$el.querySelector('.loading-animation');
@ -317,7 +318,7 @@ describe('AppComponent', () => {
}); });
}); });
it('should render frequent projects list header', (done) => { it('should render frequent projects list header', done => {
vm.toggleFrequentProjectsList(true); vm.toggleFrequentProjectsList(true);
Vue.nextTick(() => { Vue.nextTick(() => {
const sectionHeaderEl = vm.$el.querySelector('.section-header'); const sectionHeaderEl = vm.$el.querySelector('.section-header');
@ -328,7 +329,7 @@ describe('AppComponent', () => {
}); });
}); });
it('should render frequent projects list', (done) => { it('should render frequent projects list', done => {
vm.toggleFrequentProjectsList(true); vm.toggleFrequentProjectsList(true);
Vue.nextTick(() => { Vue.nextTick(() => {
expect(vm.$el.querySelector('.projects-list-frequent-container')).toBeDefined(); expect(vm.$el.querySelector('.projects-list-frequent-container')).toBeDefined();
@ -336,7 +337,7 @@ describe('AppComponent', () => {
}); });
}); });
it('should render searched projects list', (done) => { it('should render searched projects list', done => {
vm.toggleSearchProjectsList(true); vm.toggleSearchProjectsList(true);
Vue.nextTick(() => { Vue.nextTick(() => {
expect(vm.$el.querySelector('.section-header')).toBe(null); expect(vm.$el.querySelector('.section-header')).toBe(null);

View file

@ -8091,9 +8091,9 @@ undefsafe@^2.0.1:
dependencies: dependencies:
debug "^2.2.0" debug "^2.2.0"
underscore@^1.8.3: underscore@^1.9.0:
version "1.8.3" version "1.9.0"
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022" resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.9.0.tgz#31dbb314cfcc88f169cd3692d9149d81a00a73e4"
underscore@~1.7.0: underscore@~1.7.0:
version "1.7.0" version "1.7.0"