summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/shared/gr-user-suggestion-fix/gr-user-suggestion-fix_test.ts
blob: c97d23dc34fdffd6c16832e782018b0d85b8764e (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
 * @license
 * Copyright 2023 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import '../../../test/common-test-setup';
import './gr-user-suggestion-fix';
import {fixture, html, assert} from '@open-wc/testing';
import {GrUserSuggestionsFix} from './gr-user-suggestion-fix';
import {
  CommentModel,
  commentModelToken,
} from '../gr-comment-model/gr-comment-model';
import {wrapInProvider} from '../../../models/di-provider-element';
import {createComment} from '../../../test/test-data-generators';
import {getAppContext} from '../../../services/app-context';

suite('gr-user-suggestion-fix tests', () => {
  let element: GrUserSuggestionsFix;

  setup(async () => {
    const commentModel = new CommentModel(getAppContext().restApiService);
    commentModel.updateState({
      comment: createComment(),
    });
    element = (
      await fixture<GrUserSuggestionsFix>(
        wrapInProvider(
          html` <gr-user-suggestion-fix>Hello World</gr-user-suggestion-fix> `,
          commentModelToken,
          commentModel
        )
      )
    ).querySelector<GrUserSuggestionsFix>('gr-user-suggestion-fix')!;
    await element.updateComplete;
  });

  test('render', async () => {
    await element.updateComplete;

    assert.shadowDom.equal(
      element,
      /* HTML */ `<div class="header">
          <div class="title">
            <span>Suggested edit</span>
            <a
              href="/Documentation/user-suggest-edits.html"
              rel="noopener noreferrer"
              target="_blank"
              ><gr-icon icon="help" title="read documentation"></gr-icon
            ></a>
          </div>
          <div class="copyButton">
            <gr-copy-clipboard
              buttontitle="Copy Suggested edit to clipboard"
              hideinput=""
              multiline=""
              text="Hello World"
              copytargetname="Suggested edit"
            ></gr-copy-clipboard>
          </div>
          <div>
            <gr-button
              aria-disabled="false"
              class="action show-fix"
              secondary=""
              role="button"
              tabindex="0"
              flatten=""
              >Show edit</gr-button
            ><gr-button
              aria-disabled="true"
              disabled=""
              class="action show-fix"
              secondary=""
              role="button"
              tabindex="-1"
              flatten=""
              title="You cannot apply this fix because it is from a previous patchset"
              >Apply edit</gr-button
            >
          </div>
        </div>
        <gr-suggestion-diff-preview></gr-suggestion-diff-preview>`
    );
  });
});