11import Vue from 'vue' ;
2- import Vuex from 'vuex' ;
2+ import Vuex , { Store } from 'vuex' ;
33import VueRouter from 'vue-router' ;
44import { render , screen , waitFor } from '@testing-library/vue' ;
55import { configure } from '@testing-library/dom' ;
@@ -11,6 +11,7 @@ Vue.use(VueRouter);
1111
1212configure ( { testIdAttribute : 'data-test' } ) ;
1313
14+ // ---- Mocks and helpers ---------------------------------------------------
1415const loginMock = jest . fn ( ) ;
1516
1617const makeRouter = ( query = { } ) => {
@@ -20,15 +21,19 @@ const makeRouter = (query = {}) => {
2021 { path : '/signin' , name : 'SignIn' , component : AccountsMain } ,
2122 { path : '/forgot' , name : 'ForgotPassword' , component : { render : h => h ( 'div' ) } } ,
2223 { path : '/create' , name : 'Create' , component : { render : h => h ( 'div' ) } } ,
23- { path : '/account-not-activated' , name : 'AccountNotActivated' , component : { render : h => h ( 'div' ) } } ,
24+ {
25+ path : '/account-not-activated' ,
26+ name : 'AccountNotActivated' ,
27+ component : { render : h => h ( 'div' ) } ,
28+ } ,
2429 ] ,
2530 } ) ;
2631 router . replace ( { path : '/signin' , query } ) ;
2732 return router ;
2833} ;
2934
3035const makeStore = ( overrides = { } ) =>
31- new Vuex . Store ( {
36+ new Store ( {
3237 state : { connection : { online : true } , ...( overrides . state || { } ) } ,
3338 actions : {
3439 login : loginMock ,
@@ -62,6 +67,7 @@ const renderComponent = ({ query, store } = {}) => {
6267 return { router, ...utils } ;
6368} ;
6469
70+ // ---- Window location stub (for next= redirect) ---------------------------
6571const origLocation = window . location ;
6672beforeEach ( ( ) => {
6773 jest . clearAllMocks ( ) ;
@@ -71,15 +77,16 @@ afterAll(() => {
7177 window . location = origLocation ;
7278} ) ;
7379
74- describe ( 'AccountsMain (VTL)' , ( ) => {
75- test ( 'renders sign-in form' , ( ) => {
80+ // ---- Tests ---------------------------------------------------------------
81+ describe ( 'AccountsMain' , ( ) => {
82+ it ( 'renders sign-in form' , ( ) => {
7683 renderComponent ( { } ) ;
7784 expect ( screen . getByLabelText ( / e m a i l / i) ) . toBeInTheDocument ( ) ;
7885 expect ( screen . getByLabelText ( / p a s s w o r d / i) ) . toBeInTheDocument ( ) ;
7986 expect ( screen . getByRole ( 'button' , { name : / s i g n i n / i } ) ) . toBeInTheDocument ( ) ;
8087 } ) ;
8188
82- test ( 'submitting empty form blocks login and shows validation' , async ( ) => {
89+ it ( 'submitting empty form blocks login and shows validation' , async ( ) => {
8390 loginMock . mockResolvedValue ( ) ;
8491 renderComponent ( { } ) ;
8592 await userEvent . click ( screen . getByRole ( 'button' , { name : / s i g n i n / i } ) ) ;
@@ -88,7 +95,7 @@ describe('AccountsMain (VTL)', () => {
8895 expect ( msgs . length ) . toBeGreaterThanOrEqual ( 1 ) ;
8996 } ) ;
9097
91- test ( 'valid credentials call login' , async ( ) => {
98+ it ( 'valid credentials call login' , async ( ) => {
9299 loginMock . mockResolvedValue ( ) ;
93100 renderComponent ( { } ) ;
94101 await userEvent . type ( screen . getByLabelText ( / e m a i l / i) , '[email protected] ' ) ; @@ -97,7 +104,7 @@ describe('AccountsMain (VTL)', () => {
97104 await waitFor ( ( ) => expect ( loginMock ) . toHaveBeenCalled ( ) ) ;
98105 } ) ;
99106
100- test ( 'with ?next= shows banner and redirects after successful login' , async ( ) => {
107+ it ( 'with ?next= shows banner and redirects after successful login' , async ( ) => {
101108 loginMock . mockResolvedValue ( ) ;
102109 const nextUrl = '/test-next/' ;
103110 const { router } = renderComponent ( { query : { next : nextUrl } } ) ;
@@ -114,7 +121,7 @@ describe('AccountsMain (VTL)', () => {
114121 expect ( router . currentRoute . name ) . toBe ( 'SignIn' ) ;
115122 } ) ;
116123
117- test ( 'generic failure does not navigate' , async ( ) => {
124+ it ( 'generic failure does not navigate' , async ( ) => {
118125 loginMock . mockRejectedValue ( { response : { status : 500 } } ) ;
119126 const { router } = renderComponent ( { } ) ;
120127 await userEvent . type ( screen . getByLabelText ( / e m a i l / i) , '[email protected] ' ) ; @@ -125,7 +132,7 @@ describe('AccountsMain (VTL)', () => {
125132 expect ( router . currentRoute . name ) . toBe ( 'SignIn' ) ;
126133 } ) ;
127134
128- test ( '405 failure navigates to AccountNotActivated' , async ( ) => {
135+ it ( '405 failure navigates to AccountNotActivated' , async ( ) => {
129136 const store = {
130137 actions : { login : jest . fn ( ) . mockRejectedValue ( { response : { status : 405 } } ) } ,
131138 } ;
@@ -137,7 +144,7 @@ describe('AccountsMain (VTL)', () => {
137144 await waitFor ( ( ) => expect ( router . currentRoute . name ) . toBe ( 'AccountNotActivated' ) ) ;
138145 } ) ;
139146
140- test ( 'calls login with exact payload' , async ( ) => {
147+ it ( 'calls login with exact payload' , async ( ) => {
141148 loginMock . mockResolvedValue ( ) ;
142149 const nextUrl = '/test-next/' ;
143150 renderComponent ( { query : { next : nextUrl } } ) ;
@@ -159,4 +166,4 @@ describe('AccountsMain (VTL)', () => {
159166
160167 expect ( payload . next ) . toBe ( undefined ) ;
161168 } ) ;
162- } ) ;
169+ } ) ;
0 commit comments