2023-03-15 16:00:52 +00:00
/ * *
* Copyright ( c ) HashiCorp , Inc .
* SPDX - License - Identifier : MPL - 2.0
* /
2022-02-24 20:04:40 +00:00
import { module , test } from 'qunit' ;
import { setupRenderingTest } from 'ember-qunit' ;
import { render } from '@ember/test-helpers' ;
import { hbs } from 'ember-cli-htmlbars' ;
2023-01-27 02:21:12 +00:00
import { endOfMonth , formatRFC3339 } from 'date-fns' ;
2022-02-24 20:04:40 +00:00
import { click } from '@ember/test-helpers' ;
2023-01-27 02:21:12 +00:00
import subMonths from 'date-fns/subMonths' ;
2022-02-24 20:04:40 +00:00
module ( 'Integration | Component | clients/attribution' , function ( hooks ) {
setupRenderingTest ( hooks ) ;
hooks . beforeEach ( function ( ) {
2023-01-27 02:21:12 +00:00
this . set ( 'startTimestamp' , formatRFC3339 ( subMonths ( new Date ( ) , 6 ) ) ) ;
2022-02-24 20:04:40 +00:00
this . set ( 'timestamp' , formatRFC3339 ( new Date ( ) ) ) ;
this . set ( 'selectedNamespace' , null ) ;
this . set ( 'chartLegend' , [
{ label : 'entity clients' , key : 'entity_clients' } ,
{ label : 'non-entity clients' , key : 'non_entity_clients' } ,
] ) ;
this . set ( 'totalUsageCounts' , { clients : 15 , entity _clients : 10 , non _entity _clients : 5 } ) ;
2022-05-03 01:37:09 +00:00
this . set ( 'totalClientAttribution' , [
2022-02-24 20:04:40 +00:00
{ label : 'second' , clients : 10 , entity _clients : 7 , non _entity _clients : 3 } ,
{ label : 'first' , clients : 5 , entity _clients : 3 , non _entity _clients : 2 } ,
] ) ;
this . set ( 'totalMountsData' , { clients : 5 , entity _clients : 3 , non _entity _clients : 2 } ) ;
this . set ( 'namespaceMountsData' , [
{ label : 'auth1/' , clients : 3 , entity _clients : 2 , non _entity _clients : 1 } ,
{ label : 'auth2/' , clients : 2 , entity _clients : 1 , non _entity _clients : 1 } ,
] ) ;
} ) ;
test ( 'it renders empty state with no data' , async function ( assert ) {
await render ( hbs `
< div id = "modal-wormhole" > < / d i v >
2022-10-18 15:46:02 +00:00
< Clients : : Attribution @ chartLegend = { { this . chartLegend } } / >
2022-02-24 20:04:40 +00:00
` );
assert . dom ( '[data-test-component="empty-state"]' ) . exists ( ) ;
assert . dom ( '[data-test-empty-state-title]' ) . hasText ( 'No data found' ) ;
assert . dom ( '[data-test-attribution-description]' ) . hasText ( 'There is a problem gathering data' ) ;
assert . dom ( '[data-test-attribution-export-button]' ) . doesNotExist ( ) ;
assert . dom ( '[data-test-attribution-timestamp]' ) . doesNotHaveTextContaining ( 'Updated' ) ;
} ) ;
test ( 'it renders with data for namespaces' , async function ( assert ) {
await render ( hbs `
< div id = "modal-wormhole" > < / d i v >
< Clients : : Attribution
2022-10-18 15:46:02 +00:00
@ chartLegend = { { this . chartLegend } }
@ totalClientAttribution = { { this . totalClientAttribution } }
@ totalUsageCounts = { { this . totalUsageCounts } }
2023-01-27 02:21:12 +00:00
@ responseTimestamp = { { this . timestamp } }
@ startTimestamp = { { this . startTimestamp } }
@ endTimestamp = { { this . timestamp } }
2022-10-18 15:46:02 +00:00
@ selectedNamespace = { { this . selectedNamespace } }
2023-01-27 02:21:12 +00:00
@ isHistoricalMonth = { { false } }
2022-02-24 20:04:40 +00:00
/ >
` );
assert . dom ( '[data-test-component="empty-state"]' ) . doesNotExist ( ) ;
assert . dom ( '[data-test-horizontal-bar-chart]' ) . exists ( 'chart displays' ) ;
assert . dom ( '[data-test-attribution-export-button]' ) . exists ( ) ;
assert
. dom ( '[data-test-attribution-description]' )
. hasText (
'This data shows the top ten namespaces by client count and can be used to understand where clients are originating. Namespaces are identified by path. To see all namespaces, export this data.'
) ;
assert
. dom ( '[data-test-attribution-subtext]' )
. hasText (
'The total clients in the namespace for this date range. This number is useful for identifying overall usage volume.'
) ;
assert . dom ( '[data-test-top-attribution]' ) . includesText ( 'namespace' ) . includesText ( 'second' ) ;
2022-06-01 18:42:05 +00:00
assert . dom ( '[data-test-attribution-clients]' ) . includesText ( 'namespace' ) . includesText ( '10' ) ;
2022-02-24 20:04:40 +00:00
} ) ;
2023-01-27 02:21:12 +00:00
test ( 'it renders two charts and correct text for single, historical month' , async function ( assert ) {
this . start = formatRFC3339 ( subMonths ( new Date ( ) , 1 ) ) ;
this . end = formatRFC3339 ( subMonths ( endOfMonth ( new Date ( ) ) , 1 ) ) ;
2022-02-24 20:04:40 +00:00
await render ( hbs `
< div id = "modal-wormhole" > < / d i v >
< Clients : : Attribution
2022-10-18 15:46:02 +00:00
@ chartLegend = { { this . chartLegend } }
@ totalClientAttribution = { { this . totalClientAttribution } }
@ totalUsageCounts = { { this . totalUsageCounts } }
2023-01-27 02:21:12 +00:00
@ responseTimestamp = { { this . timestamp } }
@ startTimestamp = { { this . start } }
@ endTimestamp = { { this . end } }
2022-10-18 15:46:02 +00:00
@ selectedNamespace = { { this . selectedNamespace } }
2023-01-27 02:21:12 +00:00
@ isHistoricalMonth = { { true } }
2022-02-24 20:04:40 +00:00
/ >
` );
assert
2022-04-15 19:06:10 +00:00
. dom ( '[data-test-attribution-description]' )
. includesText (
'This data shows the top ten namespaces by client count and can be used to understand where clients are originating. Namespaces are identified by path. To see all namespaces, export this data.' ,
'renders correct auth attribution description'
) ;
assert
. dom ( '[data-test-chart-container="total-clients"] .chart-description' )
. includesText (
'The total clients in the namespace for this month. This number is useful for identifying overall usage volume.' ,
'renders total monthly namespace text'
) ;
assert
. dom ( '[data-test-chart-container="new-clients"] .chart-description' )
. includesText (
'The new clients in the namespace for this month. This aids in understanding which namespaces create and use new clients.' ,
'renders new monthly namespace text'
) ;
2022-02-24 20:04:40 +00:00
this . set ( 'selectedNamespace' , 'second' ) ;
2022-04-15 19:06:10 +00:00
2022-02-24 20:04:40 +00:00
assert
2022-04-15 19:06:10 +00:00
. dom ( '[data-test-attribution-description]' )
. includesText (
'This data shows the top ten authentication methods by client count within this namespace, and can be used to understand where clients are originating. Authentication methods are organized by path.' ,
'renders correct auth attribution description'
) ;
assert
. dom ( '[data-test-chart-container="total-clients"] .chart-description' )
. includesText (
'The total clients used by the auth method for this month. This number is useful for identifying overall usage volume.' ,
'renders total monthly auth method text'
) ;
assert
. dom ( '[data-test-chart-container="new-clients"] .chart-description' )
. includesText (
'The new clients used by the auth method for this month. This aids in understanding which auth methods create and use new clients.' ,
'renders new monthly auth method text'
) ;
2022-02-24 20:04:40 +00:00
} ) ;
2023-01-27 02:21:12 +00:00
test ( 'it renders single chart for current month' , async function ( assert ) {
await render ( hbs `
< div id = "modal-wormhole" > < / d i v >
< Clients : : Attribution
@ chartLegend = { { this . chartLegend } }
@ totalClientAttribution = { { this . totalClientAttribution } }
@ totalUsageCounts = { { this . totalUsageCounts } }
@ responseTimestamp = { { this . timestamp } }
@ startTimestamp = { { this . timestamp } }
@ endTimestamp = { { this . timestamp } }
@ selectedNamespace = { { this . selectedNamespace } }
@ isHistoricalMonth = { { false } }
/ >
` );
assert
. dom ( '[data-test-chart-container="single-chart"]' )
. exists ( 'renders single chart with total clients' ) ;
assert
. dom ( '[data-test-attribution-subtext]' )
. hasTextContaining ( 'this month' , 'renders total monthly namespace text' ) ;
} ) ;
test ( 'it renders single chart and correct text for for date range' , async function ( assert ) {
await render ( hbs `
< div id = "modal-wormhole" > < / d i v >
< Clients : : Attribution
@ chartLegend = { { this . chartLegend } }
@ totalClientAttribution = { { this . totalClientAttribution } }
@ totalUsageCounts = { { this . totalUsageCounts } }
@ responseTimestamp = { { this . timestamp } }
@ startTimestamp = { { this . startTimestamp } }
@ endTimestamp = { { this . timestamp } }
@ selectedNamespace = { { this . selectedNamespace } }
@ isHistoricalMonth = { { false } }
/ >
` );
assert
. dom ( '[data-test-chart-container="single-chart"]' )
. exists ( 'renders single chart with total clients' ) ;
assert
. dom ( '[data-test-attribution-subtext]' )
. hasTextContaining ( 'date range' , 'renders total monthly namespace text' ) ;
} ) ;
2022-02-24 20:04:40 +00:00
test ( 'it renders with data for selected namespace auth methods for a date range' , async function ( assert ) {
this . set ( 'selectedNamespace' , 'second' ) ;
await render ( hbs `
< div id = "modal-wormhole" > < / d i v >
< Clients : : Attribution
2022-10-18 15:46:02 +00:00
@ chartLegend = { { this . chartLegend } }
@ totalClientAttribution = { { this . namespaceMountsData } }
@ totalUsageCounts = { { this . totalUsageCounts } }
2023-01-27 02:21:12 +00:00
@ responseTimestamp = { { this . timestamp } }
@ startTimestamp = { { this . startTimestamp } }
@ endTimestamp = { { this . timestamp } }
2022-10-18 15:46:02 +00:00
@ selectedNamespace = { { this . selectedNamespace } }
2023-01-27 02:21:12 +00:00
@ isHistoricalMonth = { { this . isHistoricalMonth } }
2022-02-24 20:04:40 +00:00
/ >
` );
assert . dom ( '[data-test-component="empty-state"]' ) . doesNotExist ( ) ;
assert . dom ( '[data-test-horizontal-bar-chart]' ) . exists ( 'chart displays' ) ;
assert . dom ( '[data-test-attribution-export-button]' ) . exists ( ) ;
assert
. dom ( '[data-test-attribution-description]' )
. hasText (
'This data shows the top ten authentication methods by client count within this namespace, and can be used to understand where clients are originating. Authentication methods are organized by path.'
) ;
assert
. dom ( '[data-test-attribution-subtext]' )
. hasText (
'The total clients used by the auth method for this date range. This number is useful for identifying overall usage volume.'
) ;
assert . dom ( '[data-test-top-attribution]' ) . includesText ( 'auth method' ) . includesText ( 'auth1/' ) ;
2022-06-01 18:42:05 +00:00
assert . dom ( '[data-test-attribution-clients]' ) . includesText ( 'auth method' ) . includesText ( '3' ) ;
2022-02-24 20:04:40 +00:00
} ) ;
test ( 'it renders modal' , async function ( assert ) {
await render ( hbs `
< div id = "modal-wormhole" > < / d i v >
< Clients : : Attribution
2022-10-18 15:46:02 +00:00
@ chartLegend = { { this . chartLegend } }
@ totalClientAttribution = { { this . namespaceMountsData } }
2023-01-27 02:21:12 +00:00
@ responseTimestamp = { { this . timestamp } }
@ startTimestamp = "2022-06-01T23:00:11.050Z"
@ endTimestamp = "2022-12-01T23:00:11.050Z"
2022-02-24 20:04:40 +00:00
/ >
` );
await click ( '[data-test-attribution-export-button]' ) ;
assert . dom ( '.modal.is-active .title' ) . hasText ( 'Export attribution data' , 'modal appears to export csv' ) ;
2023-01-27 02:21:12 +00:00
assert . dom ( '.modal.is-active' ) . includesText ( 'June 2022 - December 2022' ) ;
2022-02-24 20:04:40 +00:00
} ) ;
} ) ;