Skip to content

Commit 84afd98

Browse files
committed
image tests working
1 parent d4db193 commit 84afd98

File tree

5 files changed

+115
-94
lines changed

5 files changed

+115
-94
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
indent: ['warn', 2],
2828
'no-unused-vars': ['off', { vars: 'local' }],
2929
'prefer-const': 'warn',
30-
quotes: ['warn', 'single'],
30+
'quotes': [2, 'single', { 'avoidEscape': true }],
3131
semi: ['warn', 'always'],
3232
'space-infix-ops': 'warn',
3333
'no-console': 'off',

__tests__/ContainersTab.test.js

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ContainersCard from "../src/components/ContainersCard/ContainersCard";
55
import { describe, beforeEach, expect, test, jest } from "@jest/globals";
66
import "@testing-library/jest-dom";
77
import { fireEvent, render, screen } from "@testing-library/react";
8+
import fetchMock from "jest-fetch-mock";
89
import store from "../src/store";
910

1011
const props = {
@@ -32,26 +33,57 @@ const props = {
3233
stop: jest.fn(),
3334
remove: jest.fn(),
3435
runStopped: jest.fn(),
36+
status: 'running'
3537
};
3638

39+
fetchMock.enableMocks();
40+
3741
describe("Containers", () => {
38-
beforeEach(() => {
39-
render(
40-
<Provider store={store}>
41-
<Containers {...props}/>
42-
</Provider>
43-
);
42+
test("Containers component should render", () => {
43+
render(
44+
<Provider store={store}>
45+
<Containers />
46+
</Provider>
47+
);
48+
});
49+
50+
describe('ContainersCard', () => {
51+
test('renders correctly', () => {
52+
render(
53+
<ContainersCard
54+
containerList={props.runningList}
55+
stopContainer={props.stop}
56+
runContainer={props.runStopped}
57+
removeContainer={props.remove}
58+
status={props.status}
59+
/>
60+
);
61+
});
4462
});
4563

4664
describe("Running List containers", () => {
65+
beforeEach(() => {
66+
render(<Provider store={store}>
67+
<Containers {...props} />
68+
</Provider>
69+
)
70+
render(
71+
<ContainersCard
72+
containerList={props.runningList}
73+
stopContainer={props.stop}
74+
runContainer={props.runStopped}
75+
removeContainer={props.remove}
76+
status={props.status}
77+
/>
78+
);
79+
});
80+
4781
test("Should have render correct amount of running containers", () => {
48-
const runningContainers = screen.getByText("RUNNING CONTAINERS");
49-
50-
console.log(runningContainers);
82+
expect(screen.getByText(/1/i)).toBeInTheDocument();
5183
});
5284

5385
xtest("Name of container should properly display", () => {
54-
const h3 = screen.getAllByRole("heading", { level: 3 });
86+
const h3 = div.querySelectorAll(h3);
5587
const name = h3[0].innerHTML;
5688
expect(name).toEqual("blissful_matsumoto");
5789
});
@@ -65,10 +97,7 @@ describe("Containers", () => {
6597

6698
describe("Stopped List Containers", () => {
6799
xtest("Should have render correct amount of containers", () => {
68-
const exitedContainers = screen.getByText("EXITED CONTAINERS");
69-
expect(exitedContainers.nextSibling.innerText).toBe(
70-
`Count: ${props.stoppedList.length}`
71-
);
100+
expect(div.querySelectorAll("p")[1].textContent).toBe("Count: 1");
72101
});
73102

74103
xtest("Name of container should properly display", () => {

__tests__/ImageTab.test.js

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import store from '../src/store';
33
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"
56
import { describe, beforeEach, expect, test, jest } from '@jest/globals';
67
import Images from '../src/components/Images/Images';
78
import "@testing-library/jest-dom";
@@ -10,7 +11,10 @@ import {
1011
render,
1112
screen,
1213
} from '@testing-library/react';
14+
import { isJSDocSeeTag } from 'typescript';
15+
import ReactDOM from "react-dom";
1316

17+
/* ----- fake data ------ */
1418
const props = {
1519
imagesList: [
1620
{
@@ -26,75 +30,68 @@ const props = {
2630
};
2731

2832
describe('Images', () => {
33+
const div = document.createElement("div");
2934
beforeEach(() => {
30-
render(
35+
36+
render(
3137
<Provider store={store}>
32-
<Images {...props} />
38+
<Images imagesList={props.imagesList[0]} />
3339
</Provider>
34-
)
40+
);
3541
});
3642

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')
4447
expect(screen.getByText("IMAGE REPOSITORY")).toBeInTheDocument();
4548
});
4649
})
4750

4851
/* ----- search bar ----- */
49-
xdescribe('Seach bar testing', () => {
52+
describe('Seach bar testing', () => {
5053
test('Search accepts input', async () => {
5154
const search = screen.getByRole('textbox');
5255
await fireEvent.change(search, { target: { value: 'search' } });
5356
expect(search.value).toBe('search');
5457
});
5558
});
5659

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 ------ */
7861
describe('pull button on click', () => {
7962
test('fires pull button functionality', () => {
80-
// const { container } = render(<Images {...props} />);
8163
const pullButton = screen.getByRole('button', { name: 'PULL' });
8264
fireEvent.click(pullButton);
8365
expect(pullButton).toBeCalled;
8466
expect(Images.handleClick).toBeCalled;
8567
});
8668
});
8769

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;
9878
});
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(/Redis/i);
87+
const imageId = screen.getByText(/Image ID: 2718634043dc/i);
88+
const imageSize = screen.getByText(/Image Size: 111 MB/i);
89+
const imageTag = screen.getByText(/16.4/i);
90+
91+
expect(redisImage).toBeInTheDocument();
92+
expect(imageId).toBeInTheDocument();
93+
expect(imageSize).toBeInTheDocument();
94+
expect(imageTag).toBeInTheDocument();
95+
});
96+
});
97+
});

__tests__/MetricsTab.test.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
import React, { Component } from 'react';
22
import Metrics from '../src/components/Metrics/Metrics';
3-
import {
4-
describe,
5-
expect,
6-
test,
7-
beforeEach,
8-
afterEach,
9-
jest,
10-
} from '@jest/globals';
3+
import { describe, expect, test, beforeEach } from '@jest/globals';
114
import '@testing-library/jest-dom';
125
import { Provider } from 'react-redux';
136
import store from '../src/store';
14-
import { act } from 'react-test-renderer';
157
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
168
import fetchMock from 'jest-fetch-mock';
17-
import { async } from 'regenerator-runtime';
189

1910
fetchMock.enableMocks();
2011

0 commit comments

Comments
 (0)