2023-10-11 02:38:59 +08:00
import { click , visit } from "@ember/test-helpers" ;
import { test } from "qunit" ;
2022-06-21 08:07:21 +08:00
import topicFixtures from "discourse/tests/fixtures/topic" ;
import {
acceptance ,
2022-07-14 01:29:19 +08:00
query ,
2022-06-21 08:07:21 +08:00
selectText ,
} from "discourse/tests/helpers/qunit-helpers" ;
2023-10-11 02:38:59 +08:00
import { cloneJSON } from "discourse-common/lib/object" ;
2022-06-21 08:07:21 +08:00
acceptance ( "Local Dates - quoting" , function ( needs ) {
needs . user ( ) ;
needs . settings ( { discourse _local _dates _enabled : true } ) ;
needs . pretender ( ( server , helper ) => {
const topicResponse = cloneJSON ( topicFixtures [ "/t/280/1.json" ] ) ;
const firstPost = topicResponse . post _stream . posts [ 0 ] ;
2022-07-14 01:29:19 +08:00
firstPost . cooked += ` <div class='select-local-date-test'>This is a test <span data-date="2022-06-17" data-time="10:00:00" class="discourse-local-date cooked-date past" data-displayed-timezone="Australia/Perth" data-timezone="Australia/Brisbane" data-email-preview="2022-06-17T00:00:00Z UTC" aria-label="Brisbane Friday, June 17, 2022
2022-06-21 08:07:21 +08:00
< br / >
< svg class = 'fa d-icon d-icon-clock svg-icon svg-string'
xmlns = & quot ; http : //www.w3.org/2000/svg">
< use href = & quot ; # clock & quot ; / >
2022-07-14 01:29:19 +08:00
< / s v g > 1 0 : 0 0 A M , P a r i s F r i d a y , J u n e 1 7 , 2 0 2 2
2022-06-21 08:07:21 +08:00
< br / >
< svg class = 'fa d-icon d-icon-clock svg-icon svg-string'
xmlns = & quot ; http : //www.w3.org/2000/svg">
< use href = & quot ; # clock & quot ; / >
2022-07-14 01:29:19 +08:00
< / s v g > 2 : 0 0 A M , L o s A n g e l e s T h u r s d a y , J u n e 1 6 , 2 0 2 2
2022-06-21 08:07:21 +08:00
< br / >
< svg class = 'fa d-icon d-icon-clock svg-icon svg-string'
xmlns = & quot ; http : //www.w3.org/2000/svg">
< use href = & quot ; # clock & quot ; / >
< / s v g > 5 : 0 0 P M " d a t a - t i t l e = " T h i s i s a n e w t o p i c t o c h e c k o n c h a t q u o t e i s s u e s " >
2024-09-09 21:40:56 +08:00
< svg class = "fa d-icon d-icon-earth-americas svg-icon" xmlns = "http://www.w3.org/2000/svg" >
< use href = "#earth-americas" > < / u s e >
2022-06-21 08:07:21 +08:00
< / s v g >
< span class = "relative-time" > June 17 , 2022 8 : 00 AM ( Perth ) < / s p a n >
< / s p a n > < / d i v > ` ;
server . get ( "/t/280.json" , ( ) => helper . response ( topicResponse ) ) ;
server . get ( "/t/280/:post_number.json" , ( ) => {
helper . response ( topicResponse ) ;
} ) ;
} ) ;
test ( "quoting single local dates with basic options" , async function ( assert ) {
await visit ( "/t/internationalization-localization/280" ) ;
await selectText ( "#post_1 .select-local-date-test" ) ;
await click ( ".insert-quote" ) ;
assert . strictEqual (
2022-07-14 01:29:19 +08:00
query ( ".d-editor-input" ) . value . trim ( ) ,
2022-11-08 07:17:43 +08:00
` [quote= \" uwe_keim, post:1, topic:280 \" ]
2022-06-21 08:07:21 +08:00
This is a test [ date = 2022 - 06 - 17 time = 10 : 00 : 00 timezone = "Australia/Brisbane" displayedTimezone = "Australia/Perth" ]
[ / q u o t e ] ` ,
"converts the date to markdown with all options correctly"
) ;
} ) ;
} ) ;
acceptance ( "Local Dates - quoting range" , function ( needs ) {
needs . user ( ) ;
needs . settings ( { discourse _local _dates _enabled : true } ) ;
needs . pretender ( ( server , helper ) => {
const topicResponse = cloneJSON ( topicFixtures [ "/t/280/1.json" ] ) ;
const firstPost = topicResponse . post _stream . posts [ 0 ] ;
firstPost . cooked += ` <div class='select-local-date-test'><p dir="ltr">Some text <span data-date="2022-06-17" data-time="09:30:00" class="discourse-local-date cooked-date past" data-format="LL" data-range="true" data-timezones="Africa/Accra|Australia/Brisbane|Europe/Paris" data-timezone="Australia/Brisbane" data-email-preview="2022-06-16T23:30:00Z UTC" aria-label="Brisbane Friday, June 17, 2022 9:30 AM → Saturday, June 18, 2022 10:30 AM, Accra Thursday, June 16, 2022 11:30 PM → Saturday, June 18, 2022 12:30 AM, Paris Friday, June 17, 2022 1:30 AM → Saturday, June 18, 2022 2:30 AM" data-title="This is a new topic to check on chat quote issues">
2024-09-09 21:40:56 +08:00
< svg class = "fa d-icon d-icon-earth-americas svg-icon" xmlns = "http://www.w3.org/2000/svg" >
< use href = "#earth-americas" > < / u s e >
2022-06-21 08:07:21 +08:00
< / s v g >
< span class = "relative-time" > June 17 , 2022 < / s p a n >
< / s p a n > → < s p a n d a t a - d a t e = " 2 0 2 2 - 0 6 - 1 8 " d a t a - t i m e = " 1 0 : 3 0 : 0 0 " c l a s s = " d i s c o u r s e - l o c a l - d a t e c o o k e d - d a t e p a s t " d a t a - f o r m a t = " L L " d a t a - r a n g e = " t r u e " d a t a - t i m e z o n e s = " A f r i c a / A c c r a | A u s t r a l i a / B r i s b a n e | E u r o p e / P a r i s " d a t a - t i m e z o n e = " A u s t r a l i a / B r i s b a n e " d a t a - e m a i l - p r e v i e w = " 2 0 2 2 - 0 6 - 1 8 T 0 0 : 3 0 : 0 0 Z U T C " a r i a - l a b e l = " B r i s b a n e F r i d a y , J u n e 1 7 , 2 0 2 2 9 : 3 0 A M → S a t u r d a y , J u n e 1 8 , 2 0 2 2 1 0 : 3 0 A M , A c c r a T h u r s d a y , J u n e 1 6 , 2 0 2 2 1 1 : 3 0 P M → S a t u r d a y , J u n e 1 8 , 2 0 2 2 1 2 : 3 0 A M , P a r i s F r i d a y , J u n e 1 7 , 2 0 2 2 1 : 3 0 A M → S a t u r d a y , J u n e 1 8 , 2 0 2 2 2 : 3 0 A M " d a t a - t i t l e = " T h i s i s a n e w t o p i c t o c h e c k o n c h a t q u o t e i s s u e s " >
2024-09-09 21:40:56 +08:00
< svg class = "fa d-icon d-icon-earth-americas svg-icon" xmlns = "http://www.w3.org/2000/svg" >
< use href = "#earth-americas" > < / u s e >
2022-06-21 08:07:21 +08:00
< / s v g >
< span class = "relative-time" > June 18 , 2022 < / s p a n >
< / s p a n > < / p > < / d i v > ` ;
server . get ( "/t/280.json" , ( ) => helper . response ( topicResponse ) ) ;
server . get ( "/t/280/:post_number.json" , ( ) => {
helper . response ( topicResponse ) ;
} ) ;
} ) ;
test ( "quoting a range of local dates" , async function ( assert ) {
await visit ( "/t/internationalization-localization/280" ) ;
await selectText ( "#post_1 .select-local-date-test" ) ;
await click ( ".insert-quote" ) ;
assert . strictEqual (
2022-07-14 01:29:19 +08:00
query ( ".d-editor-input" ) . value . trim ( ) ,
2022-11-08 07:17:43 +08:00
` [quote= \" uwe_keim, post:1, topic:280 \" ]
2022-06-21 08:07:21 +08:00
Some text [ date - range from = 2022 - 06 - 17 T09 : 30 : 00 to = 2022 - 06 - 18 T10 : 30 : 00 format = "LL" timezone = "Australia/Brisbane" timezones = "Africa/Accra|Australia/Brisbane|Europe/Paris" ]
[ / q u o t e ] ` ,
"converts the date range to markdown with all options correctly"
) ;
} ) ;
} ) ;
2022-07-06 16:37:54 +08:00
acceptance (
"Local Dates - quoting with recurring and countdown" ,
function ( needs ) {
needs . user ( ) ;
needs . settings ( { discourse _local _dates _enabled : true } ) ;
2022-06-21 08:07:21 +08:00
2022-07-06 16:37:54 +08:00
needs . pretender ( ( server , helper ) => {
const topicResponse = cloneJSON ( topicFixtures [ "/t/280/1.json" ] ) ;
const firstPost = topicResponse . post _stream . posts [ 0 ] ;
firstPost . cooked += ` <div class='select-local-date-test'><p dir="ltr">Testing countdown <span data-date="2022-06-21" data-time="09:30:00" class="discourse-local-date cooked-date" data-format="LL" data-countdown="true" data-timezone="Australia/Brisbane" data-email-preview="2022-06-20T23:30:00Z UTC" aria-label="Brisbane Tuesday, June 21, 2022 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 9:30 AM, Paris Tuesday, June 21, 2022 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 1:30 AM, Los Angeles Monday, June 20, 2022 <br /><svg class='fa d-icon d-icon-clock svg-icon svg-string' xmlns="http://www.w3.org/2000/svg"><use href="#clock" /></svg> 4:30 PM" data-title="This is a new topic to check on chat quote issues">
2024-09-09 21:40:56 +08:00
< svg class = "fa d-icon d-icon-earth-americas svg-icon" xmlns = "http://www.w3.org/2000/svg" >
< use href = "#earth-americas" > < / u s e >
2022-06-21 08:07:21 +08:00
< / s v g >
< span class = "relative-time" > 21 hours < / s p a n >
< / s p a n > < / p >
< p dir = "ltr" > Testing recurring < span data - date = "2022-06-22" class = "discourse-local-date cooked-date" data - timezone = "Australia/Brisbane" data - recurring = "2.weeks" data - email - preview = "2022-06-21T14:00:00Z UTC" aria - label = "Brisbane Wednesday, June 22, 2022 12:00 AM → Thursday, June 23, 2022 12:00 AM, Paris Tuesday, June 21, 2022 4:00 PM → Wednesday, June 22, 2022 4:00 PM, Los Angeles Tuesday, June 21, 2022 7:00 AM → Wednesday, June 22, 2022 7:00 AM" data - title = "This is a new topic to check on chat quote issues" >
2024-09-09 21:40:56 +08:00
< svg class = "fa d-icon d-icon-earth-americas svg-icon" xmlns = "http://www.w3.org/2000/svg" >
< use href = "#earth-americas" > < / u s e >
2022-06-21 08:07:21 +08:00
< / s v g >
< span class = "relative-time" > Wednesday < / s p a n >
< / s p a n > < / p > < / d i v > ` ;
2022-07-06 16:37:54 +08:00
server . get ( "/t/280.json" , ( ) => helper . response ( topicResponse ) ) ;
server . get ( "/t/280/:post_number.json" , ( ) => {
helper . response ( topicResponse ) ;
} ) ;
2022-06-21 08:07:21 +08:00
} ) ;
2022-07-06 16:37:54 +08:00
test ( "quoting single local dates with recurring and countdown options" , async function ( assert ) {
await visit ( "/t/internationalization-localization/280" ) ;
await selectText ( "#post_1 .select-local-date-test" ) ;
await click ( ".insert-quote" ) ;
assert . strictEqual (
2022-07-14 01:29:19 +08:00
query ( ".d-editor-input" ) . value . trim ( ) ,
2022-11-08 07:17:43 +08:00
` [quote= \" uwe_keim, post:1, topic:280 \" ]
2022-06-21 08:07:21 +08:00
Testing countdown [ date = 2022 - 06 - 21 time = 09 : 30 : 00 format = "LL" timezone = "Australia/Brisbane" countdown = "true" ]
Testing recurring [ date = 2022 - 06 - 22 timezone = "Australia/Brisbane" recurring = "2.weeks" ]
[ / q u o t e ] ` ,
2022-07-06 16:37:54 +08:00
"converts the dates to markdown with all options correctly"
) ;
} ) ;
}
) ;