@@ -2,6 +2,8 @@ import { ROUTES } from 'shared/constants';
22import { Module , SubModule } from 'shared/models' ;
33import {
44 clickActionButton ,
5+ createMockLicensePeriod ,
6+ formatMockDateToLocaleString ,
57 getLinearLoader ,
68 getLoadingButtonLoadingIcon ,
79 getTestSelectorByModule ,
@@ -21,6 +23,8 @@ import {
2123 interceptFetchCompanyLicenseRequest ,
2224 interceptFetchCompanyRequest ,
2325 interceptFetchCompanySettingsRequest ,
26+ interceptFetchDepartmentsRequest ,
27+ interceptFetchEmployeesRequest ,
2428 interceptFetchProfileRequest ,
2529 interceptFetchSystemLicenseRequest ,
2630} from 'support/interceptors' ;
@@ -37,13 +41,9 @@ const testCompaLicenseFields = () => {
3741 'view-details-label-terms.notBefore' : 'Valid From' ,
3842 'view-details-value-terms.notBefore' : '9/1/2024' ,
3943 'view-details-label-terms.notAfter' : 'Valid To' ,
40- 'view-details-value-terms.notAfter' : '9/1/2025' ,
41- 'view-details-label-entitlements.maximumBranchCount' : 'Maximum Branch Count' ,
42- 'view-details-value-entitlements.maximumBranchCount' : '10' ,
43- 'view-details-label-entitlements.maximumEmployeeCount' : 'Maximum Employee Count' ,
44- 'view-details-value-entitlements.maximumEmployeeCount' : '100' ,
45- 'view-details-label-entitlements.maximumDepartmentCount' : 'Maximum Department Count' ,
46- 'view-details-value-entitlements.maximumDepartmentCount' : '20' ,
44+ 'view-details-label-entitlements.maximumBranchCount' : 'Branch usage: 1 of 10' ,
45+ 'view-details-label-entitlements.maximumEmployeeCount' : 'Employee usage: 1 of 100' ,
46+ 'view-details-label-entitlements.maximumDepartmentCount' : 'Department usage: 4 of 20' ,
4747 } ) ;
4848} ;
4949
@@ -73,7 +73,9 @@ describe('Company Management Tests', () => {
7373 interceptFetchClientRequest ( ) ;
7474 interceptFetchSystemLicenseRequest ( ) ;
7575 interceptFetchCompanyLicenseRequest ( ) ;
76- interceptFetchBranchesRequest ( { pageNumber : 1 , pageSize : 1 } , { alias : 'fetchOnboardingBranchesRequest' } ) ;
76+ interceptFetchBranchesRequest ( { pageNumber : 1 , pageSize : 1 } , { alias : 'fetchBranchesTotalRequest' } ) ;
77+ interceptFetchEmployeesRequest ( { pageNumber : 1 , pageSize : 1 } , { alias : 'fetchEmployeesTotalRequest' } ) ;
78+ interceptFetchDepartmentsRequest ( { pageNumber : 1 , pageSize : 1 } , { alias : 'fetchDepartmentsTotalRequest' } ) ;
7779 interceptFetchProfileRequest ( ) ;
7880 interceptFetchCompanyRequest ( ) ;
7981 interceptFetchCompanySettingsRequest ( ) ;
@@ -123,20 +125,86 @@ describe('Company Management Tests', () => {
123125 cy . visit ( ROUTES . viewCompany . path ) ;
124126 interceptFetchCompanyLicenseRequest ( ) ;
125127
128+ cy . wait ( '@fetchCompanyLicenseRequest' ) ;
129+
126130 testCompaLicenseFields ( ) ;
131+ getTestSelectorByModule (
132+ Module . companyManagement ,
133+ SubModule . companyLicenseViewDetails ,
134+ 'view-details-value-entitlements.maximumBranchCount'
135+ ) . should ( 'have.attr' , 'aria-valuenow' , '10' ) ;
136+ getTestSelectorByModule (
137+ Module . companyManagement ,
138+ SubModule . companyLicenseViewDetails ,
139+ 'view-details-value-entitlements.maximumEmployeeCount'
140+ ) . should ( 'have.attr' , 'aria-valuenow' , '1' ) ;
141+ getTestSelectorByModule (
142+ Module . companyManagement ,
143+ SubModule . companyLicenseViewDetails ,
144+ 'view-details-value-entitlements.maximumDepartmentCount'
145+ ) . should ( 'have.attr' , 'aria-valuenow' , '20' ) ;
146+ } ) ;
147+
148+ it ( 'should show branch usage over the allowed limit in license details' , ( ) => {
149+ cy . visit ( ROUTES . viewCompany . path ) ;
150+ interceptFetchCompanyLicenseRequest ( ) ;
151+ interceptFetchBranchesRequest (
152+ { pageNumber : 1 , pageSize : 1 } ,
153+ { alias : 'fetchBranchesTotalRequest' , fixture : 'branch/branches-multiple-page-one' }
154+ ) ;
155+
156+ cy . wait ( '@fetchCompanyLicenseRequest' ) ;
157+
158+ verifyTextFields ( Module . companyManagement , SubModule . companyLicenseViewDetails , {
159+ 'view-details-label-entitlements.maximumBranchCount' : 'Branch usage: 22 of 10' ,
160+ } ) ;
161+ getTestSelectorByModule (
162+ Module . companyManagement ,
163+ SubModule . companyLicenseViewDetails ,
164+ 'view-details-value-entitlements.maximumBranchCount'
165+ ) . should ( 'have.attr' , 'aria-valuenow' , '100' ) ;
166+ } ) ;
167+
168+ it ( 'should correctly mark the license as expiring or expired' , ( ) => {
169+ cy . visit ( ROUTES . viewCompany . path ) ;
170+
171+ const mockLicenseExpiring = createMockLicensePeriod ( 25 ) ;
172+ const mockNotAfterExpiring = formatMockDateToLocaleString ( mockLicenseExpiring . notAfter ) ;
173+ interceptFetchCompanyLicenseRequest ( mockLicenseExpiring ) ;
174+
175+ cy . wait ( '@fetchCompanyLicenseRequest' ) ;
176+
177+ verifyTextFields ( Module . companyManagement , SubModule . companyLicenseViewDetails , {
178+ 'view-details-value-terms.notAfter' : `${ mockNotAfterExpiring } (25 days left)` ,
179+ } ) ;
180+
181+ cy . visit ( ROUTES . viewCompany . path ) ;
182+
183+ const mockLicenseExpired = createMockLicensePeriod ( - 3 ) ;
184+ const mockNotAfterExpired = formatMockDateToLocaleString ( mockLicenseExpired . notAfter ) ;
185+ interceptFetchCompanyLicenseRequest ( mockLicenseExpired ) ;
186+
187+ cy . wait ( '@fetchCompanyLicenseRequest' ) ;
188+
189+ verifyTextFields ( Module . companyManagement , SubModule . companyLicenseViewDetails , {
190+ 'view-details-value-terms.notAfter' : `${ mockNotAfterExpired } (expired)` ,
191+ } ) ;
127192 } ) ;
128193
129- it ( 'should display a default template if the company license has not been uploaded' , ( ) => {
194+ it ( 'should display the empty template if the company license has not been uploaded' , ( ) => {
130195 cy . visit ( ROUTES . viewCompany . path ) ;
131196 interceptFetchCompanyLicenseFailedRequest ( ) ;
132197
133198 verifyTextFields ( Module . companyManagement , SubModule . companyLicenseViewDetails , {
134199 'view-details-header' : 'Company License Details' ,
135200 } ) ;
136201 testCompaLicenseFieldsNotExist ( ) ;
137- getTestSelectorByModule ( Module . companyManagement , SubModule . companyLicenseViewDetails , 'page-subtitle ' )
202+ getTestSelectorByModule ( Module . companyManagement , SubModule . companyLicenseViewDetails , 'page-title ' )
138203 . should ( 'exist' )
139204 . and ( 'have.text' , 'Company License has not been uploaded.' ) ;
205+ getTestSelectorByModule ( Module . companyManagement , SubModule . companyLicenseViewDetails , 'page-subtitle' )
206+ . should ( 'exist' )
207+ . and ( 'have.text' , 'Please go to the Company Onboarding and upload the License.' ) ;
140208 } ) ;
141209 } ) ;
142210 } ) ;
0 commit comments