Skip to content

Commit f5f40e1

Browse files
ngunner15Nisarg VadgamaCopilot
authored
feat: #2001 cypress testing moisture content screen (#2109)
Co-authored-by: Nisarg Vadgama <nisarg.vadgama@bc.gov.ca> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 3c14317 commit f5f40e1

File tree

8 files changed

+242
-3
lines changed

8 files changed

+242
-3
lines changed

frontend/cypress.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default defineConfig({
3737
'**/21-create-a-class-seedlot-pli.cy.ts',
3838
'**/22-a-class-seedlot-reg-form-collection-interim.cy.ts',
3939
'**/23-a-class-seedlot-reg-form-ownership.cy.ts',
40-
'**/24-a-class-seedlot-reg-form-extraction.cy.ts'
40+
'**/24-a-class-seedlot-reg-form-extraction.cy.ts',
41+
'**/41-moisture-content.cy.ts'
4142
],
4243
chromeWebSecurity: false,
4344
retries: {

frontend/cypress/definitions.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,59 @@ export type SeedlotRegType = {
1212
export type SeedlotRegFixtureType = {
1313
[species: string]: SeedlotRegType
1414
};
15+
16+
export type MoistureContentType = {
17+
mc: {
18+
title: string,
19+
commentPlaceholder: string,
20+
testComment: string
21+
},
22+
table: {
23+
title: string,
24+
column1: string,
25+
column2: string,
26+
column3: string,
27+
column4: string,
28+
column5: string,
29+
column6: string,
30+
column7: string,
31+
containerErrorMsg: string,
32+
containerWeightErrorMsg: string,
33+
checkedBox: string,
34+
unCheckedBox: string,
35+
emptyTableMsg: string
36+
}
37+
};
38+
39+
export type ReplicateType = {
40+
riaKey: number;
41+
replicateNumber: number;
42+
containerId?: string;
43+
containerWeight?: number;
44+
freshSeed?: number;
45+
containerAndDryWeight?: number;
46+
dryWeight?: number;
47+
replicateAccInd?: number;
48+
replicateComment?: string;
49+
overrideReason?: string;
50+
};
51+
52+
export type SeedlotReplicateInfoType = {
53+
testCompleteInd: number,
54+
sampleDesc: string | null,
55+
moistureStatus: string | null,
56+
moisturePct: number,
57+
acceptResult: number,
58+
requestId: string,
59+
seedlotNumber: string,
60+
familyLotNumber: string | null,
61+
geneticClassCode: string,
62+
vegetationCode: string,
63+
activityType: string,
64+
testCategoryCode: string,
65+
riaComment: string | null,
66+
actualBeginDateTime: string,
67+
actualEndDateTime: string,
68+
standardActivityType: string,
69+
replicatesList: ReplicateType[]
70+
};
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { TYPE_DELAY } from '../../constants';
2+
import { mockMoistureContentApi } from '../../support/mockApiConsep';
3+
import { MoistureContentType, SeedlotReplicateInfoType } from '../../definitions';
4+
5+
describe('Moisture Content Screen page', () => {
6+
let mcData: MoistureContentType;
7+
let seedlotData: SeedlotReplicateInfoType;
8+
beforeEach(() => {
9+
cy.fixture('moisture-content').then((jsonData) => {
10+
mcData = jsonData;
11+
});
12+
cy.fixture('seedlot-replicate-info').then((jsonData) => {
13+
seedlotData = jsonData;
14+
});
15+
mockMoistureContentApi();
16+
cy.login();
17+
cy.visit('/consep/manual-moisture-content/514330');
18+
cy.url().should('contains', '/consep/manual-moisture-content/514330');
19+
});
20+
21+
it('should load and display manual moisture content page correctly', () => {
22+
// Check if the page title is displayed correctly
23+
cy.get('.consep-moisture-content-title')
24+
.find('h1')
25+
.contains(mcData.mc.title);
26+
27+
// Check if the table title is displayed correctly
28+
cy.get('.activity-result-actions-title')
29+
.find('h3')
30+
.contains(mcData.table.title);
31+
});
32+
33+
it('should display breadcrumbs correctly', () => {
34+
cy.get('.consep-moisture-content-breadcrumb')
35+
.find('li')
36+
.should('have.length', 3)
37+
.and('contain', 'CONSEP')
38+
.and('contain', 'Testing activities search')
39+
.and('contain', 'Testing list');
40+
});
41+
42+
it('should display Activity summary section correctly', () => {
43+
cy.get('.activity-summary')
44+
.find('.activity-summary-info-value')
45+
.eq(0)
46+
.should('have.text', seedlotData.activityType);
47+
48+
cy.get('.activity-summary')
49+
.find('.activity-summary-info-value')
50+
.eq(1)
51+
.should('have.text', seedlotData.seedlotNumber);
52+
53+
cy.get('.activity-summary')
54+
.find('.activity-summary-info-value')
55+
.eq(2)
56+
.should('have.text', seedlotData.requestId);
57+
58+
cy.get('.activity-summary')
59+
.find('.activity-summary-info-value')
60+
.eq(3)
61+
.should('have.text', `${seedlotData.vegetationCode} | ${seedlotData.geneticClassCode}`);
62+
63+
cy.get('.activity-summary')
64+
.find('.activity-summary-info-value')
65+
.eq(4)
66+
.should('have.text', seedlotData.moisturePct);
67+
});
68+
69+
it('should check comment box', () => {
70+
// Check if the comment input exists
71+
cy.get('#moisture-content-comments').should('be.visible');
72+
73+
// Type a comment
74+
cy.get('#moisture-content-comments')
75+
.clear()
76+
.type(mcData.mc.testComment, { delay: TYPE_DELAY })
77+
.blur()
78+
.should('have.value', mcData.mc.testComment);
79+
});
80+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"clientNumber": "00012797",
3+
"clientName": "MINISTRY OF FORESTS",
4+
"legalFirstName": null,
5+
"legalMiddleName": null,
6+
"clientStatusCode": "ACT",
7+
"clientTypeCode": "F",
8+
"acronym": "MOF"
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"mc": {
3+
"title": "Moisture content oven for lot",
4+
"commentPlaceholder": "",
5+
"testComment": "This is a test comment"
6+
},
7+
"table": {
8+
"title": "Activity results per replicate",
9+
"column1": "Replicate",
10+
"column2": "Container #",
11+
"column3": "Container weight",
12+
"column4": "Fresh seed",
13+
"column5": "Cont + Dry seed",
14+
"column6": "Dry weight",
15+
"column7": "MC value (%)",
16+
"containerErrorMsg": "Must be no more than 4 characters",
17+
"containerWeightErrorMsg": "Must be between 0 and 1000",
18+
"checkedBox": "CheckBoxIcon",
19+
"unCheckedBox": "CheckBoxOutlineBlankIcon",
20+
"emptyTableMsg": "No data found"
21+
}
22+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"testCompleteInd": 0,
3+
"sampleDesc": null,
4+
"moistureStatus": null,
5+
"moisturePct": 86.5,
6+
"acceptResult": 0,
7+
"requestId": "SSP20000093",
8+
"seedlotNumber": "60662",
9+
"familyLotNumber": null,
10+
"geneticClassCode": "A",
11+
"vegetationCode": "FDC",
12+
"activityType": "MC",
13+
"testCategoryCode": "STD",
14+
"riaComment": null,
15+
"actualBeginDateTime": "2025-06-09T07:00:00",
16+
"actualEndDateTime": "2025-06-25T07:00:00",
17+
"standardActivityType": "MC",
18+
"replicatesList": [
19+
{
20+
"riaKey": 514330,
21+
"replicateNumber": 1,
22+
"containerId": "33",
23+
"containerWeight": 22,
24+
"freshSeed": 33,
25+
"containerAndDryWeight": 44,
26+
"dryWeight": 22,
27+
"replicateAccInd": 1,
28+
"replicateComment": null,
29+
"overrideReason": null
30+
},
31+
{
32+
"riaKey": 514330,
33+
"replicateNumber": 2,
34+
"containerId": "444",
35+
"containerWeight": 5,
36+
"freshSeed": 45,
37+
"containerAndDryWeight": 220,
38+
"dryWeight": 10,
39+
"replicateAccInd": 1,
40+
"replicateComment": null,
41+
"overrideReason": null
42+
},
43+
{
44+
"riaKey": 514330,
45+
"replicateNumber": 3,
46+
"containerId": "15",
47+
"containerWeight": 30,
48+
"freshSeed": 30,
49+
"containerAndDryWeight": 419,
50+
"dryWeight": 11,
51+
"replicateAccInd": 1,
52+
"replicateComment": null,
53+
"overrideReason": null
54+
}
55+
]
56+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Sets up Cypress intercepts for moisture content cone and forest client APIs
3+
* with predefined fixture responses for testing purposes.
4+
*/
5+
export function mockMoistureContentApi() {
6+
cy.intercept(
7+
{ method: 'GET', url: '**/api/moisture-content-cone/514330' },
8+
{ statusCode: 200, fixture: 'seedlot-replicate-info.json' }
9+
).as('GET_moisture_content_cone');
10+
11+
cy.intercept(
12+
{ method: 'GET', url: '**/api/forest-clients/00012797' },
13+
{ statusCode: 200, fixture: 'forest-client.json' }
14+
).as('GET_forest_client');
15+
}

frontend/src/views/CONSEP/TestingActivities/MoistureContent/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ const MoistureContent = () => {
138138
useEffect(() => {
139139
if (testActivity?.replicatesList && testActivity.replicatesList.length > 0) {
140140
setReplicatesData(testActivity.replicatesList);
141-
} else {
141+
} else if (mcVariation) {
142142
setReplicatesData(initReplicatesList(riaKey ?? '', mcVariation.defaultNumberOfRows));
143143
}
144-
}, [testActivity, riaKey, mcVariation.defaultNumberOfRows]);
144+
}, [testActivity, riaKey, mcType]);
145145

146146
const handleAlert = (isSuccess: boolean, message: string) => {
147147
setAlert({ isSuccess, message });

0 commit comments

Comments
 (0)