@@ -5,21 +5,13 @@ import ListAddTask from './ListAddTask';
55
66// Mock the context hooks
77const mockAddTask = vi . fn ( ) ;
8- const mockAddTag = vi . fn ( ) ;
98
109vi . mock ( '../../../context/TaskContext' , ( ) => ( {
1110 useTaskContext : ( ) => ( {
1211 addTask : mockAddTask
1312 } )
1413} ) ) ;
1514
16- vi . mock ( '../../../context/TagContext' , ( ) => ( {
17- useTagContext : ( ) => ( {
18- tags : [ 'work' , 'personal' , 'urgent' ] ,
19- addTag : mockAddTag
20- } )
21- } ) ) ;
22-
2315describe ( 'ListAddTask Component' , ( ) => {
2416 const mockOnCancel = vi . fn ( ) ;
2517 const mockListFilters = [
@@ -28,16 +20,14 @@ describe('ListAddTask Component', () => {
2820
2921 beforeEach ( ( ) => {
3022 mockAddTask . mockClear ( ) ;
31- mockAddTag . mockClear ( ) ;
3223 mockOnCancel . mockClear ( ) ;
3324 } ) ;
3425
3526 test ( 'renders the form correctly' , ( ) => {
3627 render ( < ListAddTask onCancel = { mockOnCancel } listFilters = { mockListFilters } /> ) ;
3728
38- expect ( screen . getByTestId ( 'list-add-task' ) ) . toBeInTheDocument ( ) ;
29+ expect ( screen . getByTestId ( 'list-add-task-form ' ) ) . toBeInTheDocument ( ) ;
3930 expect ( screen . getByTestId ( 'list-task-input' ) ) . toBeInTheDocument ( ) ;
40- expect ( screen . getByTestId ( 'list-tag-input' ) ) . toBeInTheDocument ( ) ;
4131 expect ( screen . getByTestId ( 'list-cancel-button' ) ) . toBeInTheDocument ( ) ;
4232 expect ( screen . getByTestId ( 'list-submit-button' ) ) . toBeInTheDocument ( ) ;
4333 } ) ;
@@ -51,63 +41,29 @@ describe('ListAddTask Component', () => {
5141 expect ( taskInput . value ) . toBe ( 'New Test Task' ) ;
5242 } ) ;
5343
54- test ( 'handles tag input change' , ( ) => {
55- render ( < ListAddTask onCancel = { mockOnCancel } listFilters = { mockListFilters } /> ) ;
56-
57- const tagInput = screen . getByTestId ( 'list-tag-input' ) ;
58- fireEvent . change ( tagInput , { target : { value : 'personal' } } ) ;
59-
60- expect ( tagInput . value ) . toBe ( 'personal' ) ;
61- } ) ;
62-
63- test ( 'includes tags from list filters by default' , ( ) => {
44+ test ( 'displays auto-applied tags from list filters' , ( ) => {
6445 render ( < ListAddTask onCancel = { mockOnCancel } listFilters = { mockListFilters } /> ) ;
6546
66- expect ( screen . getByTestId ( 'list-selected-tags' ) ) . toBeInTheDocument ( ) ;
67- expect ( screen . getByText ( 'work' ) ) . toBeInTheDocument ( ) ;
47+ expect ( screen . getByTestId ( 'auto-applied-tags' ) ) . toBeInTheDocument ( ) ;
48+ expect ( screen . getByText ( / w i l l b e t a g g e d w i t h / i) ) . toBeInTheDocument ( ) ;
49+ expect ( screen . getByText ( / w o r k / i) ) . toBeInTheDocument ( ) ;
6850 } ) ;
6951
70- test ( 'adds a tag when Enter key is pressed' , ( ) => {
71- render ( < ListAddTask onCancel = { mockOnCancel } listFilters = { mockListFilters } /> ) ;
72-
73- const tagInput = screen . getByTestId ( 'list-tag-input' ) ;
74- fireEvent . change ( tagInput , { target : { value : 'new-tag' } } ) ;
75- fireEvent . keyDown ( tagInput , { key : 'Enter' } ) ;
76-
77- expect ( screen . getByText ( 'new-tag' ) ) . toBeInTheDocument ( ) ;
78- expect ( tagInput . value ) . toBe ( '' ) ;
79- } ) ;
80-
81- test ( 'removes a tag when remove button is clicked' , ( ) => {
82- render ( < ListAddTask onCancel = { mockOnCancel } listFilters = { mockListFilters } /> ) ;
83-
84- const tagToRemove = screen . getByText ( 'work' ) ;
85- const removeButton = screen . getByTestId ( 'list-remove-tag-work' ) ;
86- fireEvent . click ( removeButton ) ;
87-
88- expect ( screen . queryByText ( 'work' ) ) . not . toBeInTheDocument ( ) ;
89- } ) ;
90-
91- test ( 'submits the form with task and tags' , ( ) => {
52+ test ( 'submits the form with task and tags from list filters' , ( ) => {
9253 render ( < ListAddTask onCancel = { mockOnCancel } listFilters = { mockListFilters } /> ) ;
9354
9455 // Fill in task
9556 const taskInput = screen . getByTestId ( 'list-task-input' ) ;
9657 fireEvent . change ( taskInput , { target : { value : 'Submit Test Task' } } ) ;
9758
98- // Add another tag
99- const tagInput = screen . getByTestId ( 'list-tag-input' ) ;
100- fireEvent . change ( tagInput , { target : { value : 'urgent' } } ) ;
101- fireEvent . keyDown ( tagInput , { key : 'Enter' } ) ;
102-
10359 // Submit the form
10460 const submitButton = screen . getByTestId ( 'list-submit-button' ) ;
10561 fireEvent . click ( submitButton ) ;
10662
10763 expect ( mockAddTask ) . toHaveBeenCalledWith ( {
10864 text : 'Submit Test Task' ,
10965 isCompleted : false ,
110- tags : [ 'work' , 'urgent' ]
66+ tags : [ 'work' ]
11167 } ) ;
11268 expect ( mockOnCancel ) . toHaveBeenCalled ( ) ;
11369 } ) ;
0 commit comments