|
| 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