1
1
import React from 'react' ;
2
2
import store from '../src/store' ;
3
3
import { Provider } from 'react-redux' ;
4
- import * as helper from '../src/helpers/commands' ;
4
+ //import useHelper, * as helper from '../src/helpers/commands';
5
+ import { useHelper } from "../src/helpers/commands"
5
6
import { describe , beforeEach , expect , test , jest } from '@jest/globals' ;
6
7
import Images from '../src/components/Images/Images' ;
7
8
import "@testing-library/jest-dom" ;
@@ -10,7 +11,10 @@ import {
10
11
render ,
11
12
screen ,
12
13
} from '@testing-library/react' ;
14
+ import { isJSDocSeeTag } from 'typescript' ;
15
+ import ReactDOM from "react-dom" ;
13
16
17
+ /* ----- fake data ------ */
14
18
const props = {
15
19
imagesList : [
16
20
{
@@ -26,75 +30,68 @@ const props = {
26
30
} ;
27
31
28
32
describe ( 'Images' , ( ) => {
33
+ const div = document . createElement ( "div" ) ;
29
34
beforeEach ( ( ) => {
30
- render (
35
+
36
+ render (
31
37
< Provider store = { store } >
32
- < Images { ... props } />
38
+ < Images imagesList = { props . imagesList [ 0 ] } />
33
39
</ Provider >
34
- )
40
+ ) ;
35
41
} ) ;
36
42
37
- // beforeEach(() => {
38
- // render(<Images {...props} />);
39
- // screen.debug();
40
- // });
41
- xdescribe ( "text rendering" , ( ) => {
42
- test ( "if image repsository text renders" , async ( ) => {
43
- //const text = screen.getByText('IMAGE REPOSITORY')
43
+ /* ----- heading ------ */
44
+ describe ( "Text renders on page" , ( ) => {
45
+ test ( "Image repository is present on screen" , async ( ) => {
46
+ const text = screen . getByText ( 'IMAGE REPOSITORY' )
44
47
expect ( screen . getByText ( "IMAGE REPOSITORY" ) ) . toBeInTheDocument ( ) ;
45
48
} ) ;
46
49
} )
47
50
48
51
/* ----- search bar ----- */
49
- xdescribe ( 'Seach bar testing' , ( ) => {
52
+ describe ( 'Seach bar testing' , ( ) => {
50
53
test ( 'Search accepts input' , async ( ) => {
51
54
const search = screen . getByRole ( 'textbox' ) ;
52
55
await fireEvent . change ( search , { target : { value : 'search' } } ) ;
53
56
expect ( search . value ) . toBe ( 'search' ) ;
54
57
} ) ;
55
58
} ) ;
56
59
57
- /* ----- button testing ------ */
58
-
59
- describe ( 'Run button on click' , ( ) => {
60
- test ( 'Fires run button functionality' , ( ) => {
61
- const runButton = screen . getByRole ( "button" , { name : "RUN" } ) ;
62
- fireEvent . click ( runButton ) ;
63
- // expect(pullButton).toBeCalled
64
- expect ( props . runIm ) . toBeCalled ;
65
- } ) ;
66
- } ) ;
67
-
68
-
69
- describe ( 'Remove button on click' , ( ) => {
70
- test ( 'Fires remove button functionality' , async ( ) => {
71
- const removeButton = screen . getByRole ( 'button' , { name : 'REMOVE' } ) ;
72
- await fireEvent . click ( removeButton ) ;
73
- expect ( removeButton ) . toBeCalled ;
74
- } ) ;
75
- } ) ;
76
-
77
- // currently gets stuck at window.runExec method --> reads undefined
60
+ /* ----- pull button click ------ */
78
61
describe ( 'pull button on click' , ( ) => {
79
62
test ( 'fires pull button functionality' , ( ) => {
80
- // const { container } = render(<Images {...props} />);
81
63
const pullButton = screen . getByRole ( 'button' , { name : 'PULL' } ) ;
82
64
fireEvent . click ( pullButton ) ;
83
65
expect ( pullButton ) . toBeCalled ;
84
66
expect ( Images . handleClick ) . toBeCalled ;
85
67
} ) ;
86
68
} ) ;
87
69
88
- describe ( 'Images' , ( ) => {
89
- test ( 'Renders an image if one is found' , ( ) => {
90
- const name = screen . getByText ( 'Redis' ) ;
91
- const id = screen . getByText ( '2718634043dc' ) ;
92
- const size = screen . getByText ( '111 MB' ) ;
93
- const tag = screen . getByText ( 16.4 ) ;
94
- expect ( name ) . toBeDefined ;
95
- expect ( id ) . toBeDefined ;
96
- expect ( size ) . toBeDefined ;
97
- expect ( tag ) . toBeDefined ;
70
+ /* ----- image cards render ------ */
71
+ describe ( 'Images Card Testing' , ( ) => {
72
+ //render(<Provider store={store}><Images imagesList={props.imagesList[0]} /></Provider>);
73
+ test ( "Run images button clicks" , ( ) => {
74
+ const runButton = screen . getByRole ( 'button' , { name : 'RUN' } ) ;
75
+ expect ( runButton ) . toBeInTheDocument ( )
76
+ fireEvent . click ( runButton ) ;
77
+ expect ( Images . runIm ) . toBeCalled ;
98
78
} ) ;
99
- } ) ;
100
- } ) ;
79
+ test ( 'Remove image button clicks' , ( ) => {
80
+ const removeButton = screen . getByRole ( 'button' , { name : 'REMOVE' } ) ;
81
+ expect ( removeButton ) . toBeInTheDocument ( )
82
+ fireEvent . click ( removeButton ) ;
83
+ expect ( Images . removeIm ) . toBeCalled ;
84
+ } )
85
+ test ( "Renders an image if one is found" , ( ) => {
86
+ const redisImage = screen . getByText ( / R e d i s / i) ;
87
+ const imageId = screen . getByText ( / I m a g e I D : 2 7 1 8 6 3 4 0 4 3 d c / i) ;
88
+ const imageSize = screen . getByText ( / I m a g e S i z e : 1 1 1 M B / i) ;
89
+ const imageTag = screen . getByText ( / 1 6 .4 / i) ;
90
+
91
+ expect ( redisImage ) . toBeInTheDocument ( ) ;
92
+ expect ( imageId ) . toBeInTheDocument ( ) ;
93
+ expect ( imageSize ) . toBeInTheDocument ( ) ;
94
+ expect ( imageTag ) . toBeInTheDocument ( ) ;
95
+ } ) ;
96
+ } ) ;
97
+ } ) ;
0 commit comments