2023-12-01 16:47:54 +01:00
import { visit } from "@ember/test-helpers" ;
import { test } from "qunit" ;
2024-08-28 13:51:37 +02:00
import { acceptance } from "discourse/tests/helpers/qunit-helpers" ;
2025-02-06 16:45:00 +00:00
import { i18n } from "discourse-i18n" ;
2021-04-15 11:23:09 +04:00
acceptance ( "Data Explorer Plugin | List Queries" , function ( needs ) {
needs . user ( ) ;
needs . settings ( { data _explorer _enabled : true } ) ;
needs . pretender ( ( server , helper ) => {
server . get ( "/admin/plugins/explorer/groups.json" , ( ) => {
2025-06-04 21:40:29 +08:00
return helper . response ( [ ] ) ;
2021-04-15 11:23:09 +04:00
} ) ;
server . get ( "/admin/plugins/explorer/queries" , ( ) => {
return helper . response ( {
queries : [
{
id : - 5 ,
name : "Top 100 Active Topics" ,
description :
"based on the number of replies, it accepts a ‘ months_ago’ parameter, defaults to 1 to give results for the last calendar month." ,
username : "system" ,
group _ids : [ ] ,
last _run _at : "2021-02-08T15:37:49.188Z" ,
user _id : - 1 ,
} ,
{
id : - 6 ,
name : "Top 100 Likers" ,
description :
"returns the top 100 likers for a given monthly period ordered by like_count. It accepts a ‘ months_ago’ parameter, defaults to 1 to give results for the last calendar month." ,
username : "system" ,
group _ids : [ ] ,
last _run _at : "2021-02-11T08:29:59.337Z" ,
user _id : - 1 ,
} ,
] ,
} ) ;
} ) ;
} ) ;
2024-08-28 13:51:37 +02:00
test ( "renders the page with the list of queries" , async function ( assert ) {
2023-11-21 22:23:35 +01:00
await visit ( "/admin/plugins/explorer" ) ;
2021-04-15 11:23:09 +04:00
2024-08-28 13:51:37 +02:00
assert
. dom ( "div.query-list input.ember-text-field" )
. hasAttribute (
"placeholder" ,
2025-02-06 16:45:00 +00:00
i18n ( "explorer.search_placeholder" ) ,
2024-08-28 13:51:37 +02:00
"the search box was rendered"
) ;
2021-04-15 11:23:09 +04:00
2024-08-28 13:51:37 +02:00
assert
. dom ( "div.query-list button.btn-icon svg.d-icon-plus" )
. exists ( "the add query button was rendered" ) ;
2021-04-15 11:23:09 +04:00
2024-08-28 13:51:37 +02:00
assert
. dom ( "div.query-list button.btn-icon-text span.d-button-label" )
2025-02-06 16:45:00 +00:00
. hasText ( i18n ( "explorer.import.label" ) , "the import button was rendered" ) ;
2021-04-15 11:23:09 +04:00
2024-08-28 13:51:37 +02:00
assert
. dom ( "div.container table.recent-queries tbody tr" )
. exists ( { count : 2 } , "the list of queries was rendered" ) ;
2021-04-15 11:23:09 +04:00
2024-08-28 13:51:37 +02:00
assert
. dom ( "div.container table.recent-queries tbody tr:nth-child(1) td a" )
. hasText ( /^\s*Top 100 Likers/ , "The first query was rendered" ) ;
2021-04-15 11:23:09 +04:00
2024-08-28 13:51:37 +02:00
assert
. dom ( "div.container table.recent-queries tbody tr:nth-child(2) td a" )
. hasText ( /^\s*Top 100 Active Topics/ , "The second query was rendered" ) ;
2021-04-15 11:23:09 +04:00
} ) ;
} ) ;