@@ -7,116 +7,119 @@ import { object, email, string } from 'zod';
77import TpkLogin from ' @triptyk/ember-ui/components/prefabs/tpk-login' ;
88import loginPageObject from ' doc-app/tests/pages/tpk-login' ;
99
10- module (' Integration | Component | Prefabs | Tpk-login-prefab' , function (hooks ) {
11- setupRenderingTest (hooks );
12- setupIntl (hooks , ' fr-fr' );
13-
14- const loginSchema = object ({
15- email: email (),
16- password: string ().min (1 ),
17- });
18-
19- async function renderComponent(params ? : {
20- onSubmit? : (data : unknown , changeset : ImmerChangeset ) => void ;
21- initialValues? : { email: string ; password: string };
22- submitButtonText? : string ;
23- }) {
24- const onSubmit = params ?.onSubmit ?? (() => {});
25- const initialValues = params ?.initialValues ;
26- const submitButtonText = params ?.submitButtonText ;
27-
28- await render (
29- <template >
30- <TpkLogin
31- @ onSubmit ={{onSubmit }}
32- @ loginSchema ={{loginSchema }}
33- @ initialValues ={{initialValues }}
34- @ submitButtonText ={{submitButtonText }}
35- />
36- </template >
37- );
38- }
10+ module (
11+ ' Integration | Component | Prefabs | Tpk-login-prefab' ,
12+ function (hooks ) {
13+ setupRenderingTest (hooks );
14+ setupIntl (hooks , ' fr-fr' );
15+
16+ const loginSchema = object ({
17+ email: email (),
18+ password: string ().min (1 ),
19+ });
3920
40- test (' renders login form with email and password fields' , async function (assert ) {
41- await renderComponent ();
42- assert .dom (loginPageObject .scope ).exists ();
43- assert .dom (' [data-test-tpk-login-form-email]' ).exists ();
44- assert .dom (' [data-test-tpk-login-form-password]' ).exists ();
45- assert .dom (loginPageObject .submitButton .scope ).exists ();
46- });
47-
48- test (' displays default submit button text' , async function (assert ) {
49- await renderComponent ();
50- assert .strictEqual (loginPageObject .submitButton .text , ' Sign in' );
51- });
52-
53- test (' displays custom submit button text' , async function (assert ) {
54- await renderComponent ({ submitButtonText: ' Connexion' });
55- assert .strictEqual (loginPageObject .submitButton .text , ' Connexion' );
56- });
57-
58- test (' uses initial values when provided' , async function (assert ) {
59- await renderComponent ({
60- initialValues: {
61- email: ' test@example.com' ,
62- password: ' initialPassword' ,
63- },
21+ async function renderComponent(params ? : {
22+ onSubmit? : (data : unknown , changeset : ImmerChangeset ) => void ;
23+ initialValues? : { email: string ; password: string };
24+ submitButtonText? : string ;
25+ }) {
26+ const onSubmit = params ?.onSubmit ?? (() => {});
27+ const initialValues = params ?.initialValues ;
28+ const submitButtonText = params ?.submitButtonText ;
29+
30+ await render (
31+ <template >
32+ <TpkLogin
33+ @ onSubmit ={{onSubmit }}
34+ @ loginSchema ={{loginSchema }}
35+ @ initialValues ={{initialValues }}
36+ @ submitButtonText ={{submitButtonText }}
37+ />
38+ </template >
39+ );
40+ }
41+
42+ test (' renders login form with email and password fields' , async function (assert ) {
43+ await renderComponent ();
44+ assert .dom (loginPageObject .scope ).exists ();
45+ assert .dom (' [data-test-tpk-login-form-email]' ).exists ();
46+ assert .dom (' [data-test-tpk-login-form-password]' ).exists ();
47+ assert .dom (loginPageObject .submitButton .scope ).exists ();
6448 });
65- assert .strictEqual (loginPageObject .email .value , ' test@example.com' );
66- assert .strictEqual (loginPageObject .password .value , ' initialPassword' );
67- });
68-
69- test (' onSubmit is called with data and changeset when form is valid' , async function (assert ) {
70- let receivedData: unknown ;
71- let receivedChangeset: ImmerChangeset | undefined ;
72-
73- await renderComponent ({
74- onSubmit : (data , changeset ) => {
75- receivedData = data ;
76- receivedChangeset = changeset ;
77- assert .step (' onSubmit' );
78- },
49+
50+ test (' displays default submit button text' , async function (assert ) {
51+ await renderComponent ();
52+ assert .strictEqual (loginPageObject .submitButton .text , ' Sign in' );
7953 });
8054
81- await loginPageObject .email .fillIn (' test@example.com' );
82- await loginPageObject .password .fillIn (' password123' );
83- await loginPageObject .submitButton .click ();
55+ test (' displays custom submit button text' , async function (assert ) {
56+ await renderComponent ({ submitButtonText: ' Connexion' });
57+ assert .strictEqual (loginPageObject .submitButton .text , ' Connexion' );
58+ });
8459
85- assert .verifySteps ([' onSubmit' ]);
86- assert .deepEqual (receivedData , {
87- email: ' test@example.com' ,
88- password: ' password123' ,
60+ test (' uses initial values when provided' , async function (assert ) {
61+ await renderComponent ({
62+ initialValues: {
63+ email: ' test@example.com' ,
64+ password: ' initialPassword' ,
65+ },
66+ });
67+ assert .strictEqual (loginPageObject .email .value , ' test@example.com' );
68+ assert .strictEqual (loginPageObject .password .value , ' initialPassword' );
8969 });
90- assert .ok (receivedChangeset instanceof ImmerChangeset );
91- assert .strictEqual (receivedChangeset ?.get (' email' ), ' test@example.com' );
92- assert .strictEqual (receivedChangeset ?.get (' password' ), ' password123' );
93- });
94-
95- test (' onSubmit is not called when form is invalid' , async function (assert ) {
96- await renderComponent ({
97- onSubmit : () => {
98- assert .step (' onSubmit' );
99- },
70+
71+ test (' onSubmit is called with data and changeset when form is valid' , async function (assert ) {
72+ let receivedData: unknown ;
73+ let receivedChangeset: ImmerChangeset | undefined ;
74+
75+ await renderComponent ({
76+ onSubmit : (data , changeset ) => {
77+ receivedData = data ;
78+ receivedChangeset = changeset ;
79+ assert .step (' onSubmit' );
80+ },
81+ });
82+
83+ await loginPageObject .email .fillIn (' test@example.com' );
84+ await loginPageObject .password .fillIn (' password123' );
85+ await loginPageObject .submitButton .click ();
86+
87+ assert .verifySteps ([' onSubmit' ]);
88+ assert .deepEqual (receivedData , {
89+ email: ' test@example.com' ,
90+ password: ' password123' ,
91+ });
92+ assert .ok (receivedChangeset instanceof ImmerChangeset );
93+ assert .strictEqual (receivedChangeset ?.get (' email' ), ' test@example.com' );
94+ assert .strictEqual (receivedChangeset ?.get (' password' ), ' password123' );
10095 });
10196
102- await loginPageObject .email .fillIn (' invalid-email' );
103- await loginPageObject .password .fillIn (' password123' );
104- await loginPageObject .submitButton .click ();
97+ test (' onSubmit is not called when form is invalid' , async function (assert ) {
98+ await renderComponent ({
99+ onSubmit : () => {
100+ assert .step (' onSubmit' );
101+ },
102+ });
105103
106- assert .verifySteps ([]);
107- });
104+ await loginPageObject .email .fillIn (' invalid-email' );
105+ await loginPageObject .password .fillIn (' password123' );
106+ await loginPageObject .submitButton .click ();
108107
109- test (' onSubmit is not called when password is empty' , async function (assert ) {
110- await renderComponent ({
111- onSubmit : () => {
112- assert .step (' onSubmit' );
113- },
108+ assert .verifySteps ([]);
114109 });
115110
116- await loginPageObject .email .fillIn (' test@example.com' );
117- await loginPageObject .password .fillIn (' ' );
118- await loginPageObject .submitButton .click ();
111+ test (' onSubmit is not called when password is empty' , async function (assert ) {
112+ await renderComponent ({
113+ onSubmit : () => {
114+ assert .step (' onSubmit' );
115+ },
116+ });
119117
120- assert .verifySteps ([]);
121- });
122- });
118+ await loginPageObject .email .fillIn (' test@example.com' );
119+ await loginPageObject .password .fillIn (' ' );
120+ await loginPageObject .submitButton .click ();
121+
122+ assert .verifySteps ([]);
123+ });
124+ }
125+ );
0 commit comments