aboutsummaryrefslogtreecommitdiff
path: root/test/unit/specs
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/specs')
-rw-r--r--test/unit/specs/modules/statuses.spec.js76
-rw-r--r--test/unit/specs/services/matcher/matcher.spec.js6
-rw-r--r--test/unit/specs/services/notification_utils/notification_utils.spec.js78
-rw-r--r--test/unit/specs/services/theme_data/theme_data3.spec.js144
4 files changed, 189 insertions, 115 deletions
diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js
index a8d0e5a3..0d83a9f8 100644
--- a/test/unit/specs/modules/statuses.spec.js
+++ b/test/unit/specs/modules/statuses.spec.js
@@ -77,24 +77,6 @@ describe('Statuses module', () => {
expect(state.timelines.public.newStatusCount).to.equal(0)
})
- it('removes statuses by tag on deletion', () => {
- const state = defaultState()
- const status = makeMockStatus({ id: '1' })
- const otherStatus = makeMockStatus({ id: '3' })
- status.uri = 'xxx'
- 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'
-
- mutations.addNewStatuses(state, { statuses: [status, otherStatus], showImmediately: true, timeline: 'public' })
- mutations.addNewStatuses(state, { statuses: [deletion], showImmediately: true, timeline: 'public' })
-
- expect(state.allStatuses).to.eql([otherStatus])
- expect(state.timelines.public.statuses).to.eql([otherStatus])
- expect(state.timelines.public.visibleStatuses).to.eql([otherStatus])
- expect(state.timelines.public.maxId).to.eql('3')
- })
-
it('does not update the maxId when the noIdUpdate flag is set', () => {
const state = defaultState()
const status = makeMockStatus({ id: '1' })
@@ -315,62 +297,4 @@ describe('Statuses module', () => {
expect(state.timelines.user.userId).to.eql(123)
})
})
-
- describe('notifications', () => {
- 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' })
- mentionedStatus.attentions = [user]
- mentionedStatus.uri = 'xxx'
- otherStatus.attentions = [user]
-
- 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'
- const newNotificationSideEffects = () => {}
- mutations.addNewStatuses(state, { statuses: [status, otherStatus], user })
- mutations.addNewNotifications(
- state,
- {
- notifications: [{
- from_profile: { id: '2' },
- id: '998',
- type: 'mention',
- status: otherStatus,
- action: otherStatus,
- seen: false
- }],
- newNotificationSideEffects
- })
-
- expect(state.notifications.data.length).to.eql(1)
- mutations.addNewNotifications(
- state,
- {
- notifications: [{
- from_profile: { id: '2' },
- id: '999',
- type: 'mention',
- status: mentionedStatus,
- action: mentionedStatus,
- seen: false
- }],
- newNotificationSideEffects
- })
-
- mutations.addNewStatuses(state, { statuses: [mentionedStatus], user })
- expect(state.allStatuses.length).to.eql(3)
- expect(state.notifications.data.length).to.eql(2)
- expect(state.notifications.data[1].status).to.eql(mentionedStatus)
- expect(state.notifications.data[1].action).to.eql(mentionedStatus)
- expect(state.notifications.data[1].type).to.eql('mention')
-
- mutations.addNewStatuses(state, { statuses: [deletion], user })
- expect(state.allStatuses.length).to.eql(2)
- expect(state.notifications.data.length).to.eql(1)
- })
- })
})
diff --git a/test/unit/specs/services/matcher/matcher.spec.js b/test/unit/specs/services/matcher/matcher.spec.js
index 7a2494f0..c6e9719d 100644
--- a/test/unit/specs/services/matcher/matcher.spec.js
+++ b/test/unit/specs/services/matcher/matcher.spec.js
@@ -78,5 +78,11 @@ describe('MatcherService', () => {
expect(MatcherService.extractTagFromUrl(url)).to.eql(false)
})
+
+ it('should return tag name from non-ascii tags', () => {
+ const url = encodeURI('https://website.com/tag/喵喵喵')
+
+ expect(MatcherService.extractTagFromUrl(url)).to.eql('喵喵喵')
+ })
})
})
diff --git a/test/unit/specs/services/notification_utils/notification_utils.spec.js b/test/unit/specs/services/notification_utils/notification_utils.spec.js
index 00628d83..60db7380 100644
--- a/test/unit/specs/services/notification_utils/notification_utils.spec.js
+++ b/test/unit/specs/services/notification_utils/notification_utils.spec.js
@@ -5,28 +5,28 @@ describe('NotificationUtils', () => {
it('should return sorted notifications with configured types', () => {
const store = {
state: {
- statuses: {
- notifications: {
- data: [
- {
- id: 1,
- action: { id: '1' },
- type: 'like'
- },
- {
- id: 2,
- action: { id: '2' },
- type: 'mention'
- },
- {
- id: 3,
- action: { id: '3' },
- type: 'repeat'
- }
- ]
- }
- },
- config: {
+ notifications: {
+ data: [
+ {
+ id: 1,
+ action: { id: '1' },
+ type: 'like'
+ },
+ {
+ id: 2,
+ action: { id: '2' },
+ type: 'mention'
+ },
+ {
+ id: 3,
+ action: { id: '3' },
+ type: 'repeat'
+ }
+ ]
+ }
+ },
+ getters: {
+ mergedConfig: {
notificationVisibility: {
likes: true,
repeats: true,
@@ -55,23 +55,23 @@ describe('NotificationUtils', () => {
it('should return only notifications not marked as seen', () => {
const store = {
state: {
- statuses: {
- notifications: {
- data: [
- {
- action: { id: '1' },
- type: 'like',
- seen: false
- },
- {
- action: { id: '2' },
- type: 'mention',
- seen: true
- }
- ]
- }
- },
- config: {
+ notifications: {
+ data: [
+ {
+ action: { id: '1' },
+ type: 'like',
+ seen: false
+ },
+ {
+ action: { id: '2' },
+ type: 'mention',
+ seen: true
+ }
+ ]
+ }
+ },
+ getters: {
+ mergedConfig: {
notificationVisibility: {
likes: true,
repeats: true,
diff --git a/test/unit/specs/services/theme_data/theme_data3.spec.js b/test/unit/specs/services/theme_data/theme_data3.spec.js
new file mode 100644
index 00000000..bb8d785c
--- /dev/null
+++ b/test/unit/specs/services/theme_data/theme_data3.spec.js
@@ -0,0 +1,144 @@
+// import { topoSort } from 'src/services/theme_data/theme_data.service.js'
+import {
+ getAllPossibleCombinations
+} from 'src/services/theme_data/iss_utils.js'
+import {
+ init
+} from 'src/services/theme_data/theme_data_3.service.js'
+import {
+ basePaletteKeys
+} from 'src/services/theme_data/theme2_to_theme3.js'
+
+describe('Theme Data 3', () => {
+ describe('getAllPossibleCombinations', () => {
+ it('test simple 3 values case', () => {
+ const out = getAllPossibleCombinations([1, 2, 3]).map(x => x.sort((a, b) => a - b))
+ expect(out).to.eql([
+ [1], [2], [3],
+ [1, 2], [1, 3], [2, 3],
+ [1, 2, 3]
+ ])
+ })
+
+ it('test simple 4 values case', () => {
+ const out = getAllPossibleCombinations([1, 2, 3, 4]).map(x => x.sort((a, b) => a - b))
+ expect(out).to.eql([
+ [1], [2], [3], [4],
+ [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4],
+ [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4],
+ [1, 2, 3, 4]
+ ])
+ })
+
+ it('test massive 5 values case, using strings', () => {
+ const out = getAllPossibleCombinations(['a', 'b', 'c', 'd', 'e']).map(x => x.sort((a, b) => a - b))
+ expect(out).to.eql([
+ // 1
+ ['a'], ['b'], ['c'], ['d'], ['e'],
+ // 2
+ ['a', 'b'], ['a', 'c'], ['a', 'd'], ['a', 'e'],
+ ['b', 'c'], ['b', 'd'], ['b', 'e'],
+ ['c', 'd'], ['c', 'e'],
+ ['d', 'e'],
+ // 3
+ ['a', 'b', 'c'], ['a', 'b', 'd'], ['a', 'b', 'e'],
+ ['a', 'c', 'd'], ['a', 'c', 'e'],
+ ['a', 'd', 'e'],
+
+ ['b', 'c', 'd'], ['b', 'c', 'e'],
+ ['b', 'd', 'e'],
+
+ ['c', 'd', 'e'],
+ // 4
+ ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'e'],
+ ['a', 'b', 'd', 'e'],
+
+ ['a', 'c', 'd', 'e'],
+
+ ['b', 'c', 'd', 'e'],
+ // 5
+ ['a', 'b', 'c', 'd', 'e']
+ ])
+ })
+ })
+
+ describe('init', function () {
+ this.timeout(5000)
+
+ it('Test initialization without anything', () => {
+ const out = init([], '#DEADAF')
+
+ expect(out).to.have.property('eager')
+ expect(out).to.have.property('lazy')
+ expect(out).to.have.property('staticVars')
+
+ expect(out.lazy).to.be.an('array')
+ expect(out.lazy).to.have.lengthOf.above(1)
+ expect(out.eager).to.be.an('array')
+ expect(out.eager).to.have.lengthOf.above(1)
+ expect(out.staticVars).to.be.an('object')
+
+ // check backwards compat/generic stuff
+ basePaletteKeys.forEach(key => {
+ expect(out.staticVars).to.have.property(key)
+ })
+ })
+
+ it('Test initialization with a basic palette', () => {
+ const out = init([{
+ component: 'Root',
+ directives: {
+ '--bg': 'color | #008080',
+ '--fg': 'color | #00C0A0'
+ }
+ }], '#DEADAF')
+
+ expect(out.staticVars).to.have.property('bg').equal('#008080')
+ expect(out.staticVars).to.have.property('fg').equal('#00C0A0')
+
+ const panelRule = out.eager.filter(x => {
+ if (x.component !== 'Panel') return false
+ return true
+ })[0]
+
+ expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked', { r: 0, g: 128, b: 128 })
+ })
+
+ it('Test initialization with opacity', () => {
+ const out = init([{
+ component: 'Root',
+ directives: {
+ '--bg': 'color | #008080'
+ }
+ }, {
+ component: 'Panel',
+ directives: {
+ opacity: 0.5
+ }
+ }], '#DEADAF')
+
+ expect(out.staticVars).to.have.property('bg').equal('#008080')
+
+ const panelRule = out.eager.filter(x => {
+ if (x.component !== 'Panel') return false
+ return true
+ })[0]
+
+ expect(panelRule).to.have.nested.deep.property('dynamicVars.background', { r: 0, g: 128, b: 128, a: 0.5 })
+ expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked')
+ // Somewhat incorrect since we don't do gamma correction
+ // real expectancy should be this:
+ /*
+
+ expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.r').that.is.closeTo(147.0, 0.01)
+ expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.g').that.is.closeTo(143.2, 0.01)
+ expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.b').that.is.closeTo(144.0, 0.01)
+
+ */
+
+ expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.r').that.is.closeTo(88.8, 0.01)
+ expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.g').that.is.closeTo(133.2, 0.01)
+ expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.b').that.is.closeTo(134, 0.01)
+ })
+ })
+})