Skip to content

Commit e52df1b

Browse files
Copilotalexr00
andcommitted
Add test for sticky header functionality
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 79ab7d6 commit e52df1b

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { default as assert } from 'assert';
7+
import * as React from 'react';
8+
import { cleanup, render } from 'react-testing-library';
9+
import { createSandbox, SinonSandbox } from 'sinon';
10+
11+
import { PRContext, default as PullRequestContext } from '../../common/context';
12+
import { Overview } from '../overview';
13+
import { PullRequestBuilder } from './builder/pullRequest';
14+
15+
describe('Overview', function () {
16+
let sinon: SinonSandbox;
17+
18+
beforeEach(function () {
19+
sinon = createSandbox();
20+
});
21+
22+
afterEach(function () {
23+
cleanup();
24+
sinon.restore();
25+
});
26+
27+
it('renders the PR header with title', function () {
28+
const pr = new PullRequestBuilder().build();
29+
const context = new PRContext(pr);
30+
31+
const out = render(
32+
<PullRequestContext.Provider value={context}>
33+
<Overview {...pr} />
34+
</PullRequestContext.Provider>,
35+
);
36+
37+
assert(out.container.querySelector('.title'));
38+
assert(out.container.querySelector('.overview-title'));
39+
});
40+
41+
it('applies sticky class when scrolled', function () {
42+
const pr = new PullRequestBuilder().build();
43+
const context = new PRContext(pr);
44+
45+
const out = render(
46+
<PullRequestContext.Provider value={context}>
47+
<Overview {...pr} />
48+
</PullRequestContext.Provider>,
49+
);
50+
51+
const titleElement = out.container.querySelector('.title');
52+
assert(titleElement);
53+
54+
// Initial state should not have sticky class
55+
assert(!titleElement.classList.contains('sticky'));
56+
});
57+
});

0 commit comments

Comments
 (0)