Quick-Search: Added Quick-search in the topbar
Changed how and what we store in elastic to unify it with how we store things in mongodb so we can have more generic javascript code to render the data. Elastic changes: Added: Node.project.url Altered to store id instead of url Node.picture Made Post searchable ./manage.py elastic reset_index ./manage.py elastic reindex Thanks to Pablo and Sybren
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { Assets } from '../assets'
|
||||
import {} from ''
|
||||
import { Assets } from '../nodes/Assets'
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
@@ -8,11 +7,16 @@ describe('Assets', () => {
|
||||
let nodeDoc;
|
||||
let spyGet;
|
||||
beforeEach(()=>{
|
||||
// mock now to get a stable pretty printed created
|
||||
Date.now = jest.fn(() => new Date(Date.UTC(2018,
|
||||
10, //November! zero based month!
|
||||
28, 11, 46, 30)).valueOf()); // A Tuesday
|
||||
|
||||
nodeDoc = {
|
||||
_id: 'my-asset-id',
|
||||
name: 'My Asset',
|
||||
pretty_created: '2 hours ago',
|
||||
node_type: 'asset',
|
||||
_created: "Wed, 07 Nov 2018 16:35:09 GMT",
|
||||
project: {
|
||||
name: 'My Project',
|
||||
url: 'url-to-project'
|
||||
@@ -52,8 +56,9 @@ describe('Assets', () => {
|
||||
let $card = Assets.create$listItem(nodeDoc);
|
||||
jest.runAllTimers();
|
||||
expect($card.length).toEqual(1);
|
||||
expect($card.prop('tagName')).toEqual('A');
|
||||
expect($card.hasClass('card asset')).toBeTruthy();
|
||||
expect($card.prop('tagName')).toEqual('A'); // <a>
|
||||
expect($card.hasClass('asset')).toBeTruthy();
|
||||
expect($card.hasClass('card')).toBeTruthy();
|
||||
expect($card.attr('href')).toEqual('/nodes/my-asset-id/redir');
|
||||
expect($card.attr('title')).toEqual('My Asset');
|
||||
|
||||
@@ -77,14 +82,17 @@ describe('Assets', () => {
|
||||
|
||||
let $watched = $card.find('.card-label');
|
||||
expect($watched.length).toEqual(0);
|
||||
|
||||
expect($card.find(':contains(3 weeks ago)').length).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
test('node without picture', done => {
|
||||
let $card = Assets.create$listItem(nodeDoc);
|
||||
expect($card.length).toEqual(1);
|
||||
expect($card.prop('tagName')).toEqual('A');
|
||||
expect($card.hasClass('card asset')).toBeTruthy();
|
||||
expect($card.prop('tagName')).toEqual('A'); // <a>
|
||||
expect($card.hasClass('asset')).toBeTruthy();
|
||||
expect($card.hasClass('card')).toBeTruthy();
|
||||
expect($card.attr('href')).toEqual('/nodes/my-asset-id/redir');
|
||||
expect($card.attr('title')).toEqual('My Asset');
|
||||
|
||||
@@ -107,9 +115,10 @@ describe('Assets', () => {
|
||||
|
||||
let $watched = $card.find('.card-label');
|
||||
expect($watched.length).toEqual(0);
|
||||
|
||||
expect($card.find(':contains(3 weeks ago)').length).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
|
@@ -0,0 +1,48 @@
|
||||
import { Assets } from '../nodes/Assets'
|
||||
import { Users } from '../users/Users'
|
||||
import { Component } from '../init' // Component is initialized in init
|
||||
|
||||
describe('Component', () => {
|
||||
test('can create Users listItem', () => {
|
||||
let userDoc = {
|
||||
_id: 'my-user-id',
|
||||
username: 'My User Name',
|
||||
full_name: 'My full name',
|
||||
roles: ['admin', 'subscriber']
|
||||
};
|
||||
|
||||
let $user_actual = Component.create$listItem(userDoc);
|
||||
expect($user_actual.length).toBe(1);
|
||||
|
||||
let $user_reference = Users.create$listItem(userDoc);
|
||||
expect($user_actual).toEqual($user_reference);
|
||||
});
|
||||
|
||||
test('can create Asset listItem', () => {
|
||||
let nodeDoc = {
|
||||
_id: 'my-asset-id',
|
||||
name: 'My Asset',
|
||||
node_type: 'asset',
|
||||
project: {
|
||||
name: 'My Project',
|
||||
url: 'url-to-project'
|
||||
},
|
||||
properties: {
|
||||
content_type: 'image'
|
||||
}
|
||||
};
|
||||
|
||||
let $asset_actual = Component.create$listItem(nodeDoc);
|
||||
expect($asset_actual.length).toBe(1);
|
||||
|
||||
let $asset_reference = Assets.create$listItem(nodeDoc);
|
||||
expect($asset_actual).toEqual($asset_reference);
|
||||
});
|
||||
|
||||
test('fail to create unknown', () => {
|
||||
expect(()=>Component.create$listItem({})).toThrow('Can not create component using: {}')
|
||||
expect(()=>Component.create$listItem()).toThrow('Can not create component using: undefined')
|
||||
expect(()=>Component.create$listItem({strange: 'value'}))
|
||||
.toThrow('Can not create component using: {"strange":"value"}')
|
||||
});
|
||||
});
|
67
src/scripts/js/es6/common/templates/__tests__/utils.test.js
Normal file
67
src/scripts/js/es6/common/templates/__tests__/utils.test.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import { prettyDate } from '../utils'
|
||||
|
||||
describe('prettydate', () => {
|
||||
beforeEach(() => {
|
||||
Date.now = jest.fn(() => new Date(Date.UTC(2016,
|
||||
10, //November! zero based month!
|
||||
8, 11, 46, 30)).valueOf()); // A Tuesday
|
||||
});
|
||||
|
||||
test('bad input', () => {
|
||||
expect(prettyDate(undefined)).toBeUndefined();
|
||||
expect(prettyDate(null)).toBeUndefined();
|
||||
expect(prettyDate('my birthday')).toBeUndefined();
|
||||
});
|
||||
|
||||
test('past dates',() => {
|
||||
expect(pd({seconds: -5})).toBe('just now');
|
||||
expect(pd({minutes: -5})).toBe('5m ago')
|
||||
expect(pd({days: -7})).toBe('last Tuesday')
|
||||
expect(pd({days: -8})).toBe('1 week ago')
|
||||
expect(pd({days: -14})).toBe('2 weeks ago')
|
||||
expect(pd({days: -31})).toBe('8 Oct')
|
||||
expect(pd({days: -(31 + 366)})).toBe('8 Oct 2015')
|
||||
});
|
||||
|
||||
test('past dates with time',() => {
|
||||
expect(pd({seconds: -5, detailed: true})).toBe('just now');
|
||||
expect(pd({minutes: -5, detailed: true})).toBe('5m ago')
|
||||
expect(pd({days: -7, detailed: true})).toBe('last Tuesday at 11:46')
|
||||
expect(pd({days: -8, detailed: true})).toBe('1 week ago at 11:46')
|
||||
// summer time bellow
|
||||
expect(pd({days: -14, detailed: true})).toBe('2 weeks ago at 10:46')
|
||||
expect(pd({days: -31, detailed: true})).toBe('8 Oct at 10:46')
|
||||
expect(pd({days: -(31 + 366), detailed: true})).toBe('8 Oct 2015 at 10:46')
|
||||
});
|
||||
|
||||
test('future dates',() => {
|
||||
expect(pd({seconds: 5})).toBe('just now')
|
||||
expect(pd({minutes: 5})).toBe('in 5m')
|
||||
expect(pd({days: 7})).toBe('next Tuesday')
|
||||
expect(pd({days: 8})).toBe('in 1 week')
|
||||
expect(pd({days: 14})).toBe('in 2 weeks')
|
||||
expect(pd({days: 30})).toBe('8 Dec')
|
||||
expect(pd({days: 30 + 365})).toBe('8 Dec 2017')
|
||||
});
|
||||
|
||||
test('future dates',() => {
|
||||
expect(pd({seconds: 5, detailed: true})).toBe('just now')
|
||||
expect(pd({minutes: 5, detailed: true})).toBe('in 5m')
|
||||
expect(pd({days: 7, detailed: true})).toBe('next Tuesday at 11:46')
|
||||
expect(pd({days: 8, detailed: true})).toBe('in 1 week at 11:46')
|
||||
expect(pd({days: 14, detailed: true})).toBe('in 2 weeks at 11:46')
|
||||
expect(pd({days: 30, detailed: true})).toBe('8 Dec at 11:46')
|
||||
expect(pd({days: 30 + 365, detailed: true})).toBe('8 Dec 2017 at 11:46')
|
||||
});
|
||||
|
||||
function pd(params) {
|
||||
let theDate = new Date(Date.now());
|
||||
theDate.setFullYear(theDate.getFullYear() + (params['years'] || 0));
|
||||
theDate.setMonth(theDate.getMonth() + (params['months'] || 0));
|
||||
theDate.setDate(theDate.getDate() + (params['days'] || 0));
|
||||
theDate.setHours(theDate.getHours() + (params['hours'] || 0));
|
||||
theDate.setMinutes(theDate.getMinutes() + (params['minutes'] || 0));
|
||||
theDate.setSeconds(theDate.getSeconds() + (params['seconds'] || 0));
|
||||
return prettyDate(theDate, (params['detailed'] || false))
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user