11import { expect , test } from "@playwright/test" ;
22import { handleConsentPopup , waitFor } from "./util" ;
33
4- /**
5- * Changes the input for a given form section by updating the value in the input with the given value multiplier, and checks if the given value locator changes.
6- * Sometimes it shouldn't, so use 'shouldValueChange' to denote if a change is expected or not.
7- *
8- * @param page
9- * @param formSection
10- * @param value
11- * @param valueMultiplier
12- * @param shouldValueChange
13- */
14- async function updateInputs ( page , formSection , value , valueMultiplier = 3 , shouldValueChange = true ) {
15- const inputs = await ( formSection . locator ( "input" ) ) . all ( ) ;
16- const oldNcuEstimate = await value . textContent ( ) ;
17-
18- for ( let i = 0 ; i < inputs . length ; i ++ ) {
19- const input = inputs . at ( i ) ;
20- const type = await input . getAttribute ( "type" ) ;
21- if ( input && type === "number" ) {
22- const value = Number ( await input . inputValue ( ) ) ;
23- const newValue = value + ( value * valueMultiplier ) ; // Increase by some significant value
24- await input . fill ( newValue . toString ( ) ) ;
25- await page . keyboard . press ( 'Enter' ) ;
26- }
27- else if ( type === "checkbox" ) {
28- await input . check ( ) ;
29- }
30-
31- const newNcuEstimate = await value . textContent ( ) ;
32- if ( shouldValueChange ) {
33- expect ( newNcuEstimate ) . not . toBe ( oldNcuEstimate ) ;
34- }
35- else {
36- expect ( newNcuEstimate ) . toBe ( oldNcuEstimate )
37- }
38- }
39- }
40-
41- /**
42- * Returns a random number between the given min and max, inclusive.
43- *
44- * @param min
45- * @param max
46- * @returns
47- */
48- function getRandomNumber ( min , max ) {
49- // Enforce to be integer
50- min = Math . ceil ( min ) ;
51- max = Math . floor ( max ) ;
52- return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
53- }
54-
554test . describe ( "Testing for N4A calculator page" , ( ) => {
565 test . beforeEach ( async ( { page } ) => {
576 await page . goto ( "/nginxaas/azure/billing/usage-and-cost-estimator/" ) ;
@@ -69,82 +18,11 @@ test.describe("Testing for N4A calculator page", () => {
6918
7019 test ( "calculator values render" , async ( { page } ) => {
7120 // Conjunction - If outputs are rendered, it is safe to say the inputs are rendered.
21+ // NOT testing changing numbers will impact the total values as that should be the job of unit tests. This is just a smoke tests.
7222 const ncuEstimateValue = page . getByTestId ( "ncuEstimateValue" ) ;
7323 const totalValue = page . getByTestId ( "total-value" ) ;
7424
7525 expect ( await ncuEstimateValue . textContent ( ) ) . toBeTruthy ( ) ;
7626 expect ( await totalValue . textContent ( ) ) . toBeTruthy ( ) ;
7727 } ) ;
78-
79- test ( "inputs from 'Estimate NCU Usage' section change NCU Needed (happy)" , async ( { page } ) => {
80- const totalValue = page . getByTestId ( "total-value" ) ;
81- const oldTotalValue = await totalValue . textContent ( ) ;
82- const ncuEstimateValue = page . getByTestId ( "ncuEstimateValue" ) ;
83- const formSectionEstimateNCU = page . getByTestId ( "form-section-content-estimateNCUUsage" ) ;
84-
85- // Inputs from NCU box should adjust estimate
86- await updateInputs ( page , formSectionEstimateNCU , ncuEstimateValue , 80 ) ;
87-
88- // Check that total value changes
89- // Safe to say, if estimate NCU changes, so will the total monthly payment
90- const newTotalValue = await totalValue . textContent ( ) ;
91- expect ( newTotalValue ) . not . toBe ( oldTotalValue ) ;
92-
93- } ) ;
94-
95- test ( "inputs from 'Estimate NCU Usage' section change NCU Needed (unhappy 1)" , async ( { page } ) => {
96- const totalValue = page . getByTestId ( "total-value" ) ;
97- const oldTotalValue = await totalValue . textContent ( ) ;
98- const ncuEstimateValue = page . getByTestId ( "ncuEstimateValue" ) ;
99- const formSectionEstimateNCU = page . getByTestId ( "form-section-content-estimateNCUUsage" ) ;
100-
101- // Inputs from NCU box should adjust estimate
102- await updateInputs ( page , formSectionEstimateNCU , ncuEstimateValue , 0.1 , false ) ;
103-
104- // Check that total value doesn't changes
105- const newTotalValue = await totalValue . textContent ( ) ;
106- expect ( newTotalValue ) . toBe ( oldTotalValue ) ;
107- } ) ;
108-
109- test ( "inputs from 'Estimate NCU Usage' section change NCU Needed (unhappy 2)" , async ( { page } ) => {
110- const totalValue = page . getByTestId ( "total-value" ) ;
111- const oldTotalValue = await totalValue . textContent ( ) ;
112- const ncuEstimateValue = page . getByTestId ( "ncuEstimateValue" ) ;
113- const formSectionEstimateNCU = page . getByTestId ( "form-section-content-estimateNCUUsage" ) ;
114-
115- // Inputs from NCU box should adjust estimate
116- await updateInputs ( page , formSectionEstimateNCU , ncuEstimateValue , - 0.1 , false ) ;
117-
118- // Check that total value doesn't changes
119- const newTotalValue = await totalValue . textContent ( ) ;
120- expect ( newTotalValue ) . toBe ( oldTotalValue ) ;
121- } ) ;
122-
123- test ( "inputs from 'Estimate Monthly Cost' section change Total Monthly Payment" , async ( { page } ) => {
124- const totalValue = page . getByTestId ( "total-value" ) ;
125- const formSectionMonthlyCost = page . getByTestId ( "form-section-content-estimateMonthlyCost" ) ;
126-
127- await updateInputs ( page , formSectionMonthlyCost , totalValue ) ;
128- } ) ;
129-
130- test ( "'Listen Ports' input conditionally changes Total Monthly Payment" , async ( { page } ) => {
131- const listenPorts = page . getByTestId ( "input-numListenPorts" ) ;
132- const totalValue = page . getByTestId ( "total-value" ) ;
133- const oldTotalValue = await totalValue . textContent ( ) ;
134- const randomMaxValue = getRandomNumber ( 5 , 10 ) ; // Smaller max for performance reasons.
135-
136- for ( let i = 1 ; i <= randomMaxValue ; i ++ ) {
137- await listenPorts . fill ( i . toString ( ) ) ;
138- await page . keyboard . press ( 'Enter' ) ;
139-
140- // First 5 are included
141- const newTotalValue = await totalValue . textContent ( ) ;
142- if ( i <= 5 ) {
143- expect ( newTotalValue ) . toBe ( oldTotalValue ) ;
144- }
145- else {
146- expect ( newTotalValue ) . not . toBe ( oldTotalValue ) ;
147- }
148- }
149- } ) ;
15028} ) ;
0 commit comments