Skip to content

Commit d4f8828

Browse files
committed
test(gui): added tests for delta jobs functionality
Signed-off-by: Manuel Zedel <[email protected]>
1 parent ebbfaf2 commit d4f8828

File tree

4 files changed

+341
-109
lines changed

4 files changed

+341
-109
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright 2025 Northern.tech AS
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
import { prettyDOM, screen, waitFor } from '@testing-library/react';
15+
import userEvent from '@testing-library/user-event';
16+
import { vi } from 'vitest';
17+
18+
import { defaultState, undefineds } from '../../../../tests/mockData';
19+
import { render } from '../../../../tests/setupTests';
20+
import { DeltaProgress } from './DeltaGeneration';
21+
22+
const preloadedState = {
23+
...defaultState,
24+
app: {
25+
...defaultState.app,
26+
features: {
27+
...defaultState.app.features,
28+
isEnterprise: true
29+
}
30+
},
31+
releases: {
32+
...defaultState.releases,
33+
deltaJobs: {},
34+
deltaJobsList: {
35+
jobIds: [],
36+
total: 0,
37+
sort: { key: 'started', direction: 'desc' },
38+
page: 1,
39+
perPage: 20
40+
}
41+
}
42+
};
43+
44+
const preloadedStateWithJobs = {
45+
...preloadedState,
46+
releases: {
47+
...preloadedState.releases,
48+
deltaJobs: {
49+
'delta-job-1': {
50+
id: 'delta-job-1',
51+
to_release: 'mender-demo-artifact-3.3.1',
52+
from_release: 'mender-demo-artifact-3.2.1',
53+
device_types_compatible: ['qemux86-64'],
54+
started: '2022-07-11T20:49:00.000Z',
55+
status: 'success'
56+
},
57+
'delta-job-2': {
58+
id: 'delta-job-2',
59+
to_release: 'mender-demo-artifact-3.3.1',
60+
from_release: 'mender-demo-artifact-3.3.0',
61+
device_types_compatible: ['raspberrypi0w', 'raspberrypi0-wifi', 'raspberrypi3', 'raspberrypi4'],
62+
started: '2022-07-11T20:49:00.000Z',
63+
status: 'failed'
64+
}
65+
},
66+
deltaJobsList: {
67+
...preloadedState.releases.deltaJobsList,
68+
jobIds: ['delta-job-1', 'delta-job-2'],
69+
total: 2
70+
}
71+
}
72+
};
73+
74+
describe('DeltaProgress Component', () => {
75+
it('renders correctly', async () => {
76+
const { baseElement } = render(<DeltaProgress />);
77+
const view = prettyDOM(baseElement.firstChild, 100000, { highlight: false })
78+
.replace(/(:?aria-labelledby|id)=":.*:"/g, '')
79+
.replace(/\\/g, '');
80+
expect(view).toMatchSnapshot();
81+
expect(view).toEqual(expect.not.stringMatching(undefineds));
82+
});
83+
84+
it('shows enterprise upgrade notification for non-enterprise users', async () => {
85+
render(<DeltaProgress />);
86+
await expect(screen.getByText(/This feature is not available on your plan/i)).toBeInTheDocument();
87+
await expect(screen.getByText(/Upgrade/i)).toBeInTheDocument();
88+
});
89+
90+
it('shows empty state', async () => {
91+
render(<DeltaProgress />, { preloadedState });
92+
await waitFor(() => expect(screen.getByText(/No Delta Artifacts have been generated in the last 30 days/i)).toBeInTheDocument());
93+
});
94+
95+
it('shows different status indicators correctly', async () => {
96+
const ui = <DeltaProgress />;
97+
render(ui, { preloadedState: preloadedStateWithJobs });
98+
await waitFor(() => expect(screen.queryByText('Delta Artifact information')).not.toBeInTheDocument());
99+
await expect(screen.queryByText(/Success/i)).toBeVisible();
100+
await expect(screen.getByText(/Failed/i)).toBeVisible();
101+
await expect(screen.getAllByRole('progressbar')).toHaveLength(2);
102+
});
103+
});
104+
105+
describe('DeltaGenerationDetailsDrawer', () => {
106+
it('shows job details', async () => {
107+
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
108+
render(<DeltaProgress />, { preloadedState: preloadedStateWithJobs });
109+
await user.click(screen.getByText(/success/i));
110+
await waitFor(() => expect(screen.queryByText('Delta Artifact information')).toBeInTheDocument());
111+
});
112+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`DeltaProgress Component > renders correctly 1`] = `
4+
"<div>
5+
<div
6+
class="dashboard-placeholder "
7+
style="display: grid; place-content: center;"
8+
>
9+
<div>
10+
This feature is not available on your plan.
11+
<a
12+
data-discover="true"
13+
href="/subscription"
14+
>
15+
Upgrade
16+
</a>
17+
to enable it
18+
</div>
19+
</div>
20+
</div>"
21+
`;

0 commit comments

Comments
 (0)