diff options
| author | Henry Jameson <me@hjkos.com> | 2019-08-31 22:38:02 +0300 |
|---|---|---|
| committer | Henry Jameson <me@hjkos.com> | 2019-08-31 22:38:02 +0300 |
| commit | 18ec13d796c0928d09fa93de4117822d2e35502c (patch) | |
| tree | 1cfb4d68a246c604396bb64bbba3e69bdf4fe511 /test | |
| parent | b3e9a5a71819c7d3a4b35c5b6ad551785a7ba44f (diff) | |
| parent | 018a650166a5dce0878b696359a999ab67634cfc (diff) | |
Merge remote-tracking branch 'upstream/develop' into docs
* upstream/develop: (193 commits)
fix user avatar fallback logic
remove dead code
make bio textarea resizable vertically only
remove dead code
remove dead code
fix crazy watch logic in conversation
show three dot button only if needed
hide mute conversation button to guests
update keyBy
generate idObj at timeline level
fix pin showing logic in conversation
Show a message when JS is disabled
Initialize chat only if user is logged in and it wasn't initialized before
i18n/Update Japanese
i18n/Update pedantic Japanese
sync profile tab state with location query
refactor TabSwitcher
use better name of controlled prop
fix potential bug to render active tab in controlled way
remove unused param
...
Diffstat (limited to 'test')
| -rw-r--r-- | test/e2e/nightwatch.conf.js | 54 | ||||
| -rw-r--r-- | test/unit/karma.conf.js | 6 | ||||
| -rw-r--r-- | test/unit/specs/components/timeline.spec.js | 27 | ||||
| -rw-r--r-- | test/unit/specs/modules/statuses.spec.js | 62 | ||||
| -rw-r--r-- | test/unit/specs/modules/users.spec.js | 4 | ||||
| -rw-r--r-- | test/unit/specs/services/date_utils/date_utils.spec.js | 40 | ||||
| -rw-r--r-- | test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js | 23 | ||||
| -rw-r--r-- | test/unit/specs/services/file_size_format/file_size_format.spec.js | 66 | ||||
| -rw-r--r-- | test/unit/specs/services/status_parser/status_parses.spec.js | 4 | ||||
| -rw-r--r-- | test/unit/specs/services/version/version.service.spec.js | 11 |
10 files changed, 188 insertions, 109 deletions
diff --git a/test/e2e/nightwatch.conf.js b/test/e2e/nightwatch.conf.js index a5e55e90..2fc3af0b 100644 --- a/test/e2e/nightwatch.conf.js +++ b/test/e2e/nightwatch.conf.js @@ -3,43 +3,43 @@ var config = require('../../config') // http://nightwatchjs.org/guide#settings-file module.exports = { - "src_folders": ["test/e2e/specs"], - "output_folder": "test/e2e/reports", - "custom_assertions_path": ["test/e2e/custom-assertions"], + 'src_folders': ['test/e2e/specs'], + 'output_folder': 'test/e2e/reports', + 'custom_assertions_path': ['test/e2e/custom-assertions'], - "selenium": { - "start_process": true, - "server_path": "node_modules/selenium-server/lib/runner/selenium-server-standalone-2.53.1.jar", - "host": "127.0.0.1", - "port": 4444, - "cli_args": { - "webdriver.chrome.driver": require('chromedriver').path + 'selenium': { + 'start_process': true, + 'server_path': 'node_modules/selenium-server/lib/runner/selenium-server-standalone-2.53.1.jar', + 'host': '127.0.0.1', + 'port': 4444, + 'cli_args': { + 'webdriver.chrome.driver': require('chromedriver').path } }, - "test_settings": { - "default": { - "selenium_port": 4444, - "selenium_host": "localhost", - "silent": true, - "globals": { - "devServerURL": "http://localhost:" + (process.env.PORT || config.dev.port) + 'test_settings': { + 'default': { + 'selenium_port': 4444, + 'selenium_host': 'localhost', + 'silent': true, + 'globals': { + 'devServerURL': 'http://localhost:' + (process.env.PORT || config.dev.port) } }, - "chrome": { - "desiredCapabilities": { - "browserName": "chrome", - "javascriptEnabled": true, - "acceptSslCerts": true + 'chrome': { + 'desiredCapabilities': { + 'browserName': 'chrome', + 'javascriptEnabled': true, + 'acceptSslCerts': true } }, - "firefox": { - "desiredCapabilities": { - "browserName": "firefox", - "javascriptEnabled": true, - "acceptSslCerts": true + 'firefox': { + 'desiredCapabilities': { + 'browserName': 'firefox', + 'javascriptEnabled': true, + 'acceptSslCerts': true } } } diff --git a/test/unit/karma.conf.js b/test/unit/karma.conf.js index 8465523a..8af05c24 100644 --- a/test/unit/karma.conf.js +++ b/test/unit/karma.conf.js @@ -3,12 +3,12 @@ // we are also using it with karma-webpack // https://github.com/webpack/karma-webpack -var path = require('path') +// var path = require('path') var merge = require('webpack-merge') var baseConfig = require('../../build/webpack.base.conf') var utils = require('../../build/utils') var webpack = require('webpack') -var projectRoot = path.resolve(__dirname, '../../') +// var projectRoot = path.resolve(__dirname, '../../') var webpackConfig = merge(baseConfig, { // use inline sourcemap for karma-sourcemap-loader @@ -60,7 +60,7 @@ module.exports = function (config) { 'FirefoxHeadless': { base: 'Firefox', flags: [ - '-headless', + '-headless' ] } }, diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js new file mode 100644 index 00000000..0c8674a8 --- /dev/null +++ b/test/unit/specs/components/timeline.spec.js @@ -0,0 +1,27 @@ +import { getExcludedStatusIdsByPinning } from 'src/components/timeline/timeline.js' + +describe('Timeline', () => { + describe('getExcludedStatusIdsByPinning', () => { + const mockStatuses = (ids) => ids.map(id => ({ id })) + + it('should return only members of both pinnedStatusIds and ids of the given statuses', () => { + const statusIds = [1, 2, 3, 4] + const statuses = mockStatuses(statusIds) + const pinnedStatusIds = [1, 3, 5] + const result = getExcludedStatusIdsByPinning(statuses, pinnedStatusIds) + result.forEach(item => { + expect(item).to.be.oneOf(statusIds) + expect(item).to.be.oneOf(pinnedStatusIds) + }) + }) + + it('should return ids of pinned statuses not posted before any unpinned status', () => { + const pinnedStatusIdSet1 = ['PINNED1', 'PINNED2'] + const pinnedStatusIdSet2 = ['PINNED3', 'PINNED4'] + const pinnedStatusIds = [...pinnedStatusIdSet1, ...pinnedStatusIdSet2] + const statusIds = [...pinnedStatusIdSet1, 'UNPINNED1', ...pinnedStatusIdSet2] + const statuses = mockStatuses(statusIds) + expect(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)).to.eql(pinnedStatusIdSet1) + }) + }) +}) diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js index 0bbcb25a..f794997b 100644 --- a/test/unit/specs/modules/statuses.spec.js +++ b/test/unit/specs/modules/statuses.spec.js @@ -1,10 +1,10 @@ import { defaultState, mutations, prepareStatus } from '../../../../src/modules/statuses.js' // eslint-disable-next-line camelcase -const makeMockStatus = ({id, text, type = 'status'}) => { +const makeMockStatus = ({ id, text, type = 'status' }) => { return { id, - user: {id: '0'}, + user: { id: '0' }, name: 'status', text: text || `Text number ${id}`, fave_num: 0, @@ -17,7 +17,7 @@ const makeMockStatus = ({id, text, type = 'status'}) => { describe('Statuses module', () => { describe('prepareStatus', () => { it('sets deleted flag to false', () => { - const aStatus = makeMockStatus({id: '1', text: 'Hello oniichan'}) + const aStatus = makeMockStatus({ id: '1', text: 'Hello oniichan' }) expect(prepareStatus(aStatus).deleted).to.eq(false) }) }) @@ -25,7 +25,7 @@ describe('Statuses module', () => { describe('addNewStatuses', () => { it('adds the status to allStatuses and to the given timeline', () => { const state = defaultState() - const status = makeMockStatus({id: '1'}) + const status = makeMockStatus({ id: '1' }) mutations.addNewStatuses(state, { statuses: [status], timeline: 'public' }) @@ -37,7 +37,7 @@ describe('Statuses module', () => { it('counts the status as new if it has not been seen on this timeline', () => { const state = defaultState() - const status = makeMockStatus({id: '1'}) + const status = makeMockStatus({ id: '1' }) mutations.addNewStatuses(state, { statuses: [status], timeline: 'public' }) mutations.addNewStatuses(state, { statuses: [status], timeline: 'friends' }) @@ -55,7 +55,7 @@ describe('Statuses module', () => { it('add the statuses to allStatuses if no timeline is given', () => { const state = defaultState() - const status = makeMockStatus({id: '1'}) + const status = makeMockStatus({ id: '1' }) mutations.addNewStatuses(state, { statuses: [status] }) @@ -67,7 +67,7 @@ describe('Statuses module', () => { it('adds the status to allStatuses and to the given timeline, directly visible', () => { const state = defaultState() - const status = makeMockStatus({id: '1'}) + const status = makeMockStatus({ id: '1' }) mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' }) @@ -79,10 +79,10 @@ describe('Statuses module', () => { it('removes statuses by tag on deletion', () => { const state = defaultState() - const status = makeMockStatus({id: '1'}) - const otherStatus = makeMockStatus({id: '3'}) + const status = makeMockStatus({ id: '1' }) + const otherStatus = makeMockStatus({ id: '3' }) status.uri = 'xxx' - const deletion = makeMockStatus({id: '2', type: 'deletion'}) + const deletion = makeMockStatus({ id: '2', type: 'deletion' }) deletion.text = 'Dolus deleted notice {{tag:gs.smuglo.li,2016-11-18:noticeId=1038007:objectType=note}}.' deletion.uri = 'xxx' @@ -97,8 +97,8 @@ describe('Statuses module', () => { it('does not update the maxId when the noIdUpdate flag is set', () => { const state = defaultState() - const status = makeMockStatus({id: '1'}) - const secondStatus = makeMockStatus({id: '2'}) + const status = makeMockStatus({ id: '1' }) + const secondStatus = makeMockStatus({ id: '2' }) mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' }) expect(state.timelines.public.maxId).to.eql('1') @@ -111,10 +111,10 @@ describe('Statuses module', () => { it('keeps a descending by id order in timeline.visibleStatuses and timeline.statuses', () => { const state = defaultState() - const nonVisibleStatus = makeMockStatus({id: '1'}) - const status = makeMockStatus({id: '3'}) - const statusTwo = makeMockStatus({id: '2'}) - const statusThree = makeMockStatus({id: '4'}) + const nonVisibleStatus = makeMockStatus({ id: '1' }) + const status = makeMockStatus({ id: '3' }) + const statusTwo = makeMockStatus({ id: '2' }) + const statusThree = makeMockStatus({ id: '4' }) mutations.addNewStatuses(state, { statuses: [nonVisibleStatus], showImmediately: false, timeline: 'public' }) @@ -131,9 +131,9 @@ describe('Statuses module', () => { it('splits retweets from their status and links them', () => { const state = defaultState() - const status = makeMockStatus({id: '1'}) - const retweet = makeMockStatus({id: '2', type: 'retweet'}) - const modStatus = makeMockStatus({id: '1', text: 'something else'}) + const status = makeMockStatus({ id: '1' }) + const retweet = makeMockStatus({ id: '2', type: 'retweet' }) + const modStatus = makeMockStatus({ id: '1', text: 'something else' }) retweet.retweeted_status = status @@ -156,8 +156,8 @@ describe('Statuses module', () => { it('replaces existing statuses with the same id', () => { const state = defaultState() - const status = makeMockStatus({id: '1'}) - const modStatus = makeMockStatus({id: '1', text: 'something else'}) + const status = makeMockStatus({ id: '1' }) + const modStatus = makeMockStatus({ id: '1', text: 'something else' }) // Add original status mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' }) @@ -173,9 +173,9 @@ describe('Statuses module', () => { it('replaces existing statuses with the same id, coming from a retweet', () => { const state = defaultState() - const status = makeMockStatus({id: '1'}) - const modStatus = makeMockStatus({id: '1', text: 'something else'}) - const retweet = makeMockStatus({id: '2', type: 'retweet'}) + const status = makeMockStatus({ id: '1' }) + const modStatus = makeMockStatus({ id: '1', text: 'something else' }) + const retweet = makeMockStatus({ id: '2', type: 'retweet' }) retweet.retweeted_status = modStatus // Add original status @@ -194,7 +194,7 @@ describe('Statuses module', () => { it('handles favorite actions', () => { const state = defaultState() - const status = makeMockStatus({id: '1'}) + const status = makeMockStatus({ id: '1' }) const favorite = { id: '2', @@ -258,11 +258,11 @@ describe('Statuses module', () => { }) describe('clearTimeline', () => { - it('keeps userId when clearing user timeline', () => { + it('keeps userId when clearing user timeline when excludeUserId param is true', () => { const state = defaultState() state.timelines.user.userId = 123 - mutations.clearTimeline(state, { timeline: 'user' }) + mutations.clearTimeline(state, { timeline: 'user', excludeUserId: true }) expect(state.timelines.user.userId).to.eql(123) }) @@ -272,14 +272,14 @@ describe('Statuses module', () => { it('removes a notification when the notice gets removed', () => { const user = { id: '1' } const state = defaultState() - const status = makeMockStatus({id: '1'}) - const otherStatus = makeMockStatus({id: '3'}) - const mentionedStatus = makeMockStatus({id: '2'}) + const status = makeMockStatus({ id: '1' }) + const otherStatus = makeMockStatus({ id: '3' }) + const mentionedStatus = makeMockStatus({ id: '2' }) mentionedStatus.attentions = [user] mentionedStatus.uri = 'xxx' otherStatus.attentions = [user] - const deletion = makeMockStatus({id: '4', type: 'deletion'}) + const deletion = makeMockStatus({ id: '4', type: 'deletion' }) deletion.text = 'Dolus deleted notice {{tag:gs.smuglo.li,2016-11-18:noticeId=1038007:objectType=note}}.' deletion.uri = 'xxx' diff --git a/test/unit/specs/modules/users.spec.js b/test/unit/specs/modules/users.spec.js index c8bc0ae7..eeb7afef 100644 --- a/test/unit/specs/modules/users.spec.js +++ b/test/unit/specs/modules/users.spec.js @@ -24,11 +24,11 @@ describe('The users module', () => { const user = { id: '1', name: 'Guy' } mutations.addNewUsers(state, [user]) - mutations.setMuted(state, {user, muted: true}) + mutations.setMuted(state, { user, muted: true }) expect(user.muted).to.eql(true) - mutations.setMuted(state, {user, muted: false}) + mutations.setMuted(state, { user, muted: false }) expect(user.muted).to.eql(false) }) diff --git a/test/unit/specs/services/date_utils/date_utils.spec.js b/test/unit/specs/services/date_utils/date_utils.spec.js new file mode 100644 index 00000000..2d61dbac --- /dev/null +++ b/test/unit/specs/services/date_utils/date_utils.spec.js @@ -0,0 +1,40 @@ +import * as DateUtils from 'src/services/date_utils/date_utils.js' + +describe('DateUtils', () => { + describe('relativeTime', () => { + it('returns now with low enough amount of seconds', () => { + const futureTime = Date.now() + 20 * DateUtils.SECOND + const pastTime = Date.now() - 20 * DateUtils.SECOND + expect(DateUtils.relativeTime(futureTime, 30)).to.eql({ num: 0, key: 'time.now' }) + expect(DateUtils.relativeTime(pastTime, 30)).to.eql({ num: 0, key: 'time.now' }) + }) + + it('rounds down for past', () => { + const time = Date.now() - 1.8 * DateUtils.HOUR + expect(DateUtils.relativeTime(time)).to.eql({ num: 1, key: 'time.hour' }) + }) + + it('rounds up for future', () => { + const time = Date.now() + 1.8 * DateUtils.HOUR + expect(DateUtils.relativeTime(time)).to.eql({ num: 2, key: 'time.hours' }) + }) + + it('uses plural when necessary', () => { + const time = Date.now() - 3.8 * DateUtils.WEEK + expect(DateUtils.relativeTime(time)).to.eql({ num: 3, key: 'time.weeks' }) + }) + + it('works with date string', () => { + const time = Date.now() - 4 * DateUtils.MONTH + const dateString = new Date(time).toISOString() + expect(DateUtils.relativeTime(dateString)).to.eql({ num: 4, key: 'time.months' }) + }) + }) + + describe('relativeTimeShort', () => { + it('returns the short version of the same relative time', () => { + const time = Date.now() + 2 * DateUtils.YEAR + expect(DateUtils.relativeTimeShort(time)).to.eql({ num: 2, key: 'time.years_short' }) + }) + }) +}) diff --git a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js index 3d34c5cc..20e03cb0 100644 --- a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js +++ b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js @@ -163,12 +163,6 @@ const makeMockEmojiMasto = (overrides = [{}]) => { ] } -parseNotification -parseUser -parseStatus -makeMockStatusQvitter -makeMockUserQvitter - describe('API Entities normalizer', () => { describe('parseStatus', () => { describe('QVitter preprocessing', () => { @@ -206,15 +200,15 @@ describe('API Entities normalizer', () => { }) it('sets nsfw for statuses with the #nsfw tag', () => { - const safe = makeMockStatusQvitter({id: '1', text: 'Hello oniichan'}) - const nsfw = makeMockStatusQvitter({id: '1', text: 'Hello oniichan #nsfw'}) + const safe = makeMockStatusQvitter({ id: '1', text: 'Hello oniichan' }) + const nsfw = makeMockStatusQvitter({ id: '1', text: 'Hello oniichan #nsfw' }) expect(parseStatus(safe).nsfw).to.eq(false) expect(parseStatus(nsfw).nsfw).to.eq(true) }) it('leaves existing nsfw settings alone', () => { - const nsfw = makeMockStatusQvitter({id: '1', text: 'Hello oniichan #nsfw', nsfw: false}) + const nsfw = makeMockStatusQvitter({ id: '1', text: 'Hello oniichan #nsfw', nsfw: false }) expect(parseStatus(nsfw).nsfw).to.eq(false) }) @@ -282,6 +276,13 @@ describe('API Entities normalizer', () => { expect(parsedUser).to.have.property('description_html').that.contains('<img') }) + + it('adds hide_follows and hide_followers user settings', () => { + const user = makeMockUserMasto({ pleroma: { hide_followers: true, hide_follows: false } }) + + expect(parseUser(user)).to.have.property('hide_followers', true) + expect(parseUser(user)).to.have.property('hide_follows', false) + }) }) // We currently use QvitterAPI notifications only, and especially due to MastoAPI lacking is_seen, support for MastoAPI @@ -323,9 +324,9 @@ describe('API Entities normalizer', () => { describe('MastoAPI emoji adder', () => { const emojis = makeMockEmojiMasto() const imageHtml = '<img src="https://example.com/image.png" alt="image" title="image" class="emoji" />' - .replace(/"/g, '\'') + .replace(/"/g, '\'') const thinkHtml = '<img src="https://example.com/think.png" alt="thinking" title="thinking" class="emoji" />' - .replace(/"/g, '\'') + .replace(/"/g, '\'') it('correctly replaces shortcodes in supplied string', () => { const result = addEmojis('This post has :image: emoji and :thinking: emoji', emojis) diff --git a/test/unit/specs/services/file_size_format/file_size_format.spec.js b/test/unit/specs/services/file_size_format/file_size_format.spec.js index 0a5a82b7..e02ac379 100644 --- a/test/unit/specs/services/file_size_format/file_size_format.spec.js +++ b/test/unit/specs/services/file_size_format/file_size_format.spec.js @@ -1,34 +1,34 @@ - import fileSizeFormatService from '../../../../../src/services/file_size_format/file_size_format.js' - describe('fileSizeFormat', () => { - it('Formats file size', () => { - const values = [1, 1024, 1048576, 1073741824, 1099511627776] - const expected = [ - { - num: 1, - unit: 'B' - }, - { - num: 1, - unit: 'KiB' - }, - { - num: 1, - unit: 'MiB' - }, - { - num: 1, - unit: 'GiB' - }, - { - num: 1, - unit: 'TiB' - } - ] +import fileSizeFormatService from '../../../../../src/services/file_size_format/file_size_format.js' +describe('fileSizeFormat', () => { + it('Formats file size', () => { + const values = [1, 1024, 1048576, 1073741824, 1099511627776] + const expected = [ + { + num: 1, + unit: 'B' + }, + { + num: 1, + unit: 'KiB' + }, + { + num: 1, + unit: 'MiB' + }, + { + num: 1, + unit: 'GiB' + }, + { + num: 1, + unit: 'TiB' + } + ] - var res = [] - for (var value in values) { - res.push(fileSizeFormatService.fileSizeFormat(values[value])) - } - expect(res).to.eql(expected) - }) - }) + var res = [] + for (var value in values) { + res.push(fileSizeFormatService.fileSizeFormat(values[value])) + } + expect(res).to.eql(expected) + }) +}) diff --git a/test/unit/specs/services/status_parser/status_parses.spec.js b/test/unit/specs/services/status_parser/status_parses.spec.js index 65808d84..7afd5042 100644 --- a/test/unit/specs/services/status_parser/status_parses.spec.js +++ b/test/unit/specs/services/status_parser/status_parses.spec.js @@ -1,7 +1,7 @@ -const example = '<div class="status-content">@<a href="https://sealion.club/user/4" class="h-card mention" title="dewoo">dwmatiz</a> <a href="https://social.heldscal.la/file/3deb764ada10ce64a61b7a070b75dac45f86d2d5bf213bf18873da71d8714d86.png" title="https://social.heldscal.la/file/3deb764ada10ce64a61b7a070b75dac45f86d2d5bf213bf18873da71d8714d86.png" class="attachment" id="attachment-159853" rel="nofollow external">https://social.heldscal.la/attachment/159853</a></div>' - import { removeAttachmentLinks } from '../../../../../src/services/status_parser/status_parser.js' +const example = '<div class="status-content">@<a href="https://sealion.club/user/4" class="h-card mention" title="dewoo">dwmatiz</a> <a href="https://social.heldscal.la/file/3deb764ada10ce64a61b7a070b75dac45f86d2d5bf213bf18873da71d8714d86.png" title="https://social.heldscal.la/file/3deb764ada10ce64a61b7a070b75dac45f86d2d5bf213bf18873da71d8714d86.png" class="attachment" id="attachment-159853" rel="nofollow external">https://social.heldscal.la/attachment/159853</a></div>' + describe('statusParser.removeAttachmentLinks', () => { const exampleWithoutAttachmentLinks = '<div class="status-content">@<a href="https://sealion.club/user/4" class="h-card mention" title="dewoo">dwmatiz</a> </div>' diff --git a/test/unit/specs/services/version/version.service.spec.js b/test/unit/specs/services/version/version.service.spec.js new file mode 100644 index 00000000..519145ee --- /dev/null +++ b/test/unit/specs/services/version/version.service.spec.js @@ -0,0 +1,11 @@ +import { extractCommit } from 'src/services/version/version.service.js' + +describe('extractCommit', () => { + it('return short commit hash following "-g" characters', () => { + expect(extractCommit('1.0.0-45-g5e7aeebc')).to.eql('5e7aeebc') + }) + + it('return short commit hash without branch name', () => { + expect(extractCommit('1.0.0-45-g5e7aeebc-branch')).to.eql('5e7aeebc') + }) +}) |
