-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
70 lines (64 loc) · 2.18 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const { render } = require('@testing-library/react');
import { screen, configure, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
const { default: Home } = require('./pages');
const { default: TimeChart } = require('./pages/components/TimeChart');
const router = require('next/router');
describe('Assets', function () {
it('renders without crashing', () => {
render(<Home />);
expect(screen.getByText('ASSETS')).toBeInTheDocument();
});
it('should have cards with selection asset', () => {
const { container } = render(<Home />);
expect(container.querySelectorAll('.card-group')).toHaveLength(1);
expect(container.querySelectorAll('.card-group .card')).toHaveLength(3);
});
it('first card should have two buttons', () => {
const { container } = render(<Home />);
expect(
container.querySelector('.card ').querySelectorAll('button')
).toHaveLength(2);
});
it('view on map button should take me to google map page', () => {
render(<Home />);
//find all buttons with text "View on Map"
const buttons = screen.getAllByText('View on Map 🗺');
buttons.forEach((button) => {
expect(button).toBeInTheDocument();
});
//click on button calls router.push
buttons.forEach((button) => {
router.push = jest.fn();
fireEvent.click(button);
expect(router.push).toHaveBeenCalled();
});
});
it('card should have button with text View Signals', () => {
render(<Home />);
const buttons = screen.getAllByText('View Signals 📡');
expect(buttons).toHaveLength(3);
buttons.forEach((button) => {
expect(button).toBeInTheDocument();
router.push = jest.fn();
fireEvent.click(button);
expect(router.push).toHaveBeenCalledTimes(1);
});
});
});
describe('Signals', function () {
const signals = [
{
SignalName: 'Signal 1',
SignalMeasurement: [
[[1636299582230, 114.1636]],
[1636299690273, 114.3345],
[1636299763970, 114.1636],
],
},
];
it('should graph render without crash', () => {
render(<TimeChart signals={signals} />);
expect(screen.getByText(/Chart with 3 data points./i));
});
});