Skip to content

Commit

Permalink
chore: Fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanmaity1234 committed Jun 2, 2024
1 parent 3b93a96 commit 9fb18f6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ fileignoreconfig:
- filename: doc/light-theme/workflow.png
checksum: 4918fce935cb85039d75ea8e67376564d562ba40fd439650cd53f8111e825c4b
- filename: frontend/__tests__/components/DashboardHeader.test.js
checksum: 4e859cd02e915646e515215c463a3020dc0f67b9ee5638bd11bdd40ae03822d0
checksum: f078245a300fbbbc7221072350068e707a825003dd7ac9205c225c4ce0a62e72
- filename: frontend/__tests__/components/GridCell.test.js
checksum: da612be8c8f89b10ad0c64830040b8cb51cc0aac237616c311994d0371d8c8c6
- filename: frontend/__tests__/components/LoginPage.test.js
checksum: 0847b77daef01c0f6aeffe41b3fe220dea85acb732ad51b94ca79516d4ac8d26
checksum: 31ed54ab84d53d73f9dac6779cdec2d79ec6bbf7adf93e30daa85695c20941b2
- filename: frontend/__tests__/components/__snapshots__/LoginPage.test.js.snap
checksum: 67fa67a5e34cc0b9dffa942d8a0d3a680ba3a2c02b8ae5a3627d097ff254dfc8
- filename: frontend/mock-data/data.json
Expand Down
13 changes: 10 additions & 3 deletions frontend/__tests__/components/DashboardHeader.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { describe, it, expect, vi, afterEach } from 'vitest';
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';
import DashboardHeader from '@/components/DashboardHeader';
import { getVersion } from '@/services/utils';
import { mountWithWrapper } from '../test-utils';

describe('<DashboardHeader />', () => {
vi.mock('@/services/utils', () => {
return {
getVersion: vi.fn().mockReturnValue('3.1.0')
getVersion: vi.fn()
};
});

afterEach(vi.clearAllMocks);
beforeEach(() => {
getVersion.mockReturnValue('3.1.0');
});

afterEach(() => {
vi.clearAllMocks();
vi.resetAllMocks();
});

it.each([
['Workflow Jobs'], ['Exposed Secrets'], ['Code Standard Violations']
Expand Down
5 changes: 4 additions & 1 deletion frontend/__tests__/components/LoginPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ describe('<LoginPage />', () => {
}
});

afterEach(vi.clearAllMocks);
afterEach(() => {
vi.clearAllMocks();
vi.resetAllMocks();
});

it('should render spinner while fetching config', async () => {
fetchConfig.mockResolvedValueOnce({
Expand Down
10 changes: 6 additions & 4 deletions frontend/__tests__/components/WorkflowDashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ describe('<WorkflowDashboard />', () => {
getVersion.mockReturnValueOnce('3.3.0');
});

afterEach(vi.clearAllMocks);
afterEach(() => {
vi.clearAllMocks();
vi.resetAllMocks();
});

it('should render spinner while fetching data', async () => {
fetchCctrayJson.mockReturnValue(promiseWithResolvers().promise);

const workflowDashboardWrapper = mountWithWrapper(WorkflowDashboard);

await vi.waitUntil(() => workflowDashboardWrapper.findComponent(Spinner).exists());

expect(workflowDashboardWrapper.html()).toMatchSnapshot();
});

it('should render dashboard once data is fetched', async () => {
Expand Down Expand Up @@ -337,7 +338,7 @@ describe('<WorkflowDashboard />', () => {
vi.spyOn(preferences, 'showHealthyBuilds', 'get').mockReturnValueOnce(true);
vi.spyOn(preferences, 'enableMaxIdleTimeOptimization', 'get').mockReturnValueOnce(true);
vi.spyOn(preferences, 'maxIdleTime', 'get').mockReturnValueOnce(10);
vi.spyOn(preferences, 'showBuildsDueToTriggeredEvents', 'get').mockReturnValueOnce(['repository_dispatch']);
vi.spyOn(preferences, 'showBuildsDueToTriggeredEvents', 'get').mockReturnValue(['repository_dispatch']);
vi.spyOn(preferences, 'hiddenElements', 'get').mockReturnValueOnce({ });

fetchCctrayJson.mockResolvedValueOnce([jobDetails1, jobDetails2]);
Expand Down Expand Up @@ -395,6 +396,7 @@ describe('<WorkflowDashboard />', () => {
vi.spyOn(preferences, 'enableMaxIdleTimeOptimization', 'get').mockReturnValueOnce(false);
vi.spyOn(preferences, 'showBuildsDueToTriggeredEvents', 'get').mockReturnValueOnce([]);
vi.spyOn(preferences, 'hiddenElements', 'get').mockReturnValueOnce({ });
vi.spyOn(preferences, 'maxIdleTime', 'get').mockReturnValueOnce(0);

fetchCctrayJson.mockResolvedValue([jobDetails1]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,52 +1027,3 @@ exports[`<WorkflowDashboard /> > should render dashboard with all job details 1`
</div>
</div>
`;

exports[`<WorkflowDashboard /> > should render spinner while fetching data 1`] = `
<div class="v-application v-theme--light v-layout v-layout--full-height v-locale--is-ltr">
<div class="v-application__wrap">
<div class="v-container v-container--fluid v-locale--is-ltr" id="workflows-dashboard">
<header class="v-toolbar v-toolbar--density-default elevation-5 v-theme--light v-locale--is-ltr v-app-bar" style="top: 0px; z-index: 1004; transform: translateY(0px); position: fixed; left: 0px; width: calc(100% - 0px - 0px); transition: none;">
<!---->
<div class="v-toolbar__content" style="height: 64px;">
<!---->
<!---->
<div class="v-row v-row--no-gutters">
<div class="v-col v-col-10">
<div class="v-toolbar-title header-title text-center font-weight-bold pl-10 v-app-bar-title">
<div class="v-toolbar-title__placeholder">
<!---->
<span>Gitaction Board</span>
<span class="version">(v3.3.0)</span>
</div>
</div>
</div>
<div class="v-col v-col-2 d-inline-flex">
<div class="v-toolbar-title pr-4 text-right font-weight-bold align-center fill-height d-inline-flex flex-row-reverse mt-3 v-app-bar-title" id="sub-header">
<div class="v-toolbar-title__placeholder">
<!---->
Workflow Jobs
</div>
</div>
</div>
</div>
<!---->
</div>
<transition-stub appear="false" css="true" name="expand-transition" persisted="false">
<!---->
</transition-stub>
</header>
<div class="v-container v-locale--is-ltr justify-center fill-height spinner-container" id="spinner-container">
<div aria-valuemax="100" aria-valuemin="0" class="v-progress-circular v-progress-circular--indeterminate v-theme--light" role="progressbar" style="width: 128px; height: 128px; color: rgb(95, 141, 119); caret-color: #5f8d77;">
<svg style="transform: rotate(calc(-90deg + 0deg));" viewBox="0 0 44.13793103448276 44.13793103448276" xmlns="http://www.w3.org/2000/svg">
<circle class="v-progress-circular__underlay" cx="50%" cy="50%" fill="transparent" r="20" stroke-dasharray="125.66370614359172" stroke-dashoffset="0" stroke-width="4.137931034482759" />
<circle class="v-progress-circular__overlay" cx="50%" cy="50%" fill="transparent" r="20" stroke-dasharray="125.66370614359172" stroke-dashoffset="125.66370614359172px" stroke-width="4.137931034482759" />
</svg>
<!---->
</div>
</div>
<!--v-if-->
</div>
</div>
</div>
`;

0 comments on commit 9fb18f6

Please sign in to comment.