Skip to content

Commit

Permalink
Merge pull request #4695 from thematters/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 authored Jul 30, 2024
2 parents 64c52fb + 828efa5 commit 0286fca
Show file tree
Hide file tree
Showing 43 changed files with 570 additions and 58 deletions.
3 changes: 3 additions & 0 deletions lang/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,9 @@
"kCp8A9": {
"defaultMessage": "After resignation, you will not be able to manage tags."
},
"kEDrXh": {
"defaultMessage": "liked your collection"
},
"kHMa3H": {
"defaultMessage": "The new password and confirmation password do not match."
},
Expand Down
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,9 @@
"kCp8A9": {
"defaultMessage": "After resignation, you will not be able to manage tags."
},
"kEDrXh": {
"defaultMessage": "liked your collection"
},
"kHMa3H": {
"defaultMessage": "The new password and confirmation password do not match."
},
Expand Down
3 changes: 3 additions & 0 deletions lang/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,9 @@
"kCp8A9": {
"defaultMessage": "如果辞去权限,你将无法继续管理标签。"
},
"kEDrXh": {
"defaultMessage": "喜欢你的选集"
},
"kHMa3H": {
"defaultMessage": "密码不一致"
},
Expand Down
3 changes: 3 additions & 0 deletions lang/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,9 @@
"kCp8A9": {
"defaultMessage": "如果辭去權限,你將無法繼續管理標籤。"
},
"kEDrXh": {
"defaultMessage": "喜歡你的選集"
},
"kHMa3H": {
"defaultMessage": "密碼不一致"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matters-web",
"version": "5.4.0",
"version": "5.4.1",
"description": "codebase of Matters' website",
"author": "Matters <[email protected]>",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions src/common/enums/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export enum TEST_ID {
NOTICE_CRYPTO_WALLET_AIRDROP = 'notice/crypto-wallet-airdrop',
NOTICE_CRYPTO_WALLET_CONNECTED = 'notice/crypto-wallet-connected',
NOTICE_OFFICIAL_ANNOUNCEMENT = 'notice/official-announcement',
NOTICE_COLLECTION_TITLE = 'notice/collection/title',
// me
ME_WALLET_TRANSACTIONS_ITEM = 'me/wallet/transactions/item',
ME_WALLET_TRANSACTIONS_ITEM_AMOUNT = 'me/wallet/transactions/item/amount',
Expand Down
164 changes: 164 additions & 0 deletions src/common/utils/text/notice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { describe, expect, it } from 'vitest'

import { UserLanguage } from '~/gql/graphql'

import { truncateNoticeTitle } from './notice'

describe.concurrent('utils/text/collection/truncateNoticeTitle', () => {
describe('for Chinese', () => {
it('should truncate the title to the specified maximum number of words', () => {
const title = '这是一个标题这是一个标题这是一个标题'
const maxLength = 3
const expected = '这是一...'
const result = truncateNoticeTitle(title, {
locale: UserLanguage.ZhHans,
maxLength,
})
// Assert
expect(result).toEqual(expected)
})

it('should return the title as is if it has fewer words than the maximum', () => {
const title = '这是一个标题'
const maxLength = 7
const result = truncateNoticeTitle(title, {
locale: UserLanguage.ZhHans,
maxLength,
})
// Assert
expect(result).toEqual(title)
})

it('should return the title for the default length of 10 words', () => {
const title = '这是一个标题这是一个标题这是一个标题'
const expected = '这是一个标题这是一个...'
const result = truncateNoticeTitle(title, { locale: UserLanguage.ZhHans })
// Assert
expect(result).toEqual(expected)
})
})

describe('for English', () => {
it('should return the title as is if it has fewer words than the maximum', () => {
const title = 'The birds are chirping and the sun is shining'
const maxLength = 50
const result = truncateNoticeTitle(title, {
locale: UserLanguage.En,
maxLength,
})
// Assert
expect(result).toEqual(title)
})

it('should truncate the title to the specified maximum number of words', () => {
const title = 'The birds are chirping and the sun is shining'
const maxLength = 27
const expected = 'The birds are chirping and...'
const result = truncateNoticeTitle(title, {
locale: UserLanguage.En,
maxLength,
})
// Assert
expect(result).toEqual(expected)
})
})

describe('for English with tagged users', () => {
it('should truncate characters to under 10 words for english', () => {
expect(
truncateNoticeTitle('This is a very long sentence.', {
includeAtSign: true,
})
).toBe('This is a...')
expect(
truncateNoticeTitle('Hello, world.', { includeAtSign: true })
).toBe('Hello,...')
})

it('should truncate if over 10 characters with tagged users and remaining length is 0 while having english characters', () => {
expect(
truncateNoticeTitle('This is a craaaazy article here! @user1 @user2', {
includeAtSign: true,
})
).toBe('This is a...@user1 @user2')
})
})

describe('for Chinese with tagged users', () => {
it('should not truncate if under 10 characters', () => {
expect(
truncateNoticeTitle('這篇文章真的很厲害!', {
locale: UserLanguage.ZhHant,
maxLength: 10,
includeAtSign: true,
})
).toBe('這篇文章真的很厲害!')
expect(
truncateNoticeTitle('很厲害!', {
locale: UserLanguage.ZhHant,
maxLength: 10,
includeAtSign: true,
})
).toBe('很厲害!')
})

it('should truncate if over 10 characters', () => {
expect(
truncateNoticeTitle('這篇文章真的很厲害,大家應該都來看一下!', {
locale: UserLanguage.ZhHant,
maxLength: 10,
includeAtSign: true,
})
).toBe('這篇文章真的很厲害,...')
})

it('should truncate when the title is over 10 characters and the mentions are at the end', () => {
expect(
truncateNoticeTitle(
'這篇文章真的很厲害,大家應該都來看一下 @user1 @user2',
{ locale: UserLanguage.ZhHant, maxLength: 10, includeAtSign: true }
)
).toBe('這篇文章真的很厲害,...@user1 @user2')
expect(
truncateNoticeTitle(
'這篇文章真的很厲害,大家應該都來看一下! @user1 @user2',
{ locale: UserLanguage.ZhHant, maxLength: 10, includeAtSign: true }
)
).toBe('這篇文章真的很厲害,...@user1 @user2')
expect(
truncateNoticeTitle('這是一個時刻!!!!!!!@jj', {
locale: UserLanguage.ZhHant,
maxLength: 10,
includeAtSign: true,
})
).toBe('這是一個時刻!!!!...@jj')
})

it('should truncate if over 10 characters with tagged users in the middle or the beginning', () => {
expect(
truncateNoticeTitle('我和 @zhangsan 在台北一起去吃吃吃!', {
locale: UserLanguage.ZhHans,
maxLength: 10,
includeAtSign: true,
})
).toBe('我和 @zhangsan 在台北一起去...')
expect(
truncateNoticeTitle('@zhangsan 和我在台北一起去吃吃吃!', {
locale: UserLanguage.ZhHans,
maxLength: 10,
includeAtSign: true,
})
).toBe('@zhangsan 和我在台北一起去吃...')
})

it('should truncate characters to when the mention is a bit spread out', () => {
expect(
truncateNoticeTitle('我和 @zhangsan 還有 @yp 在台北一起去吃吃吃!', {
locale: UserLanguage.ZhHans,
maxLength: 10,
includeAtSign: true,
})
).toBe('我和 @zhangsan 還有 @yp 在台...')
})
})
})
Loading

0 comments on commit 0286fca

Please sign in to comment.