-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathwebstatus-feature-gone-split-page.test.ts
More file actions
139 lines (121 loc) · 4.57 KB
/
webstatus-feature-gone-split-page.test.ts
File metadata and controls
139 lines (121 loc) · 4.57 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {expect, fixture, html} from '@open-wc/testing';
import '../webstatus-feature-gone-split-page.js';
import {WebstatusFeatureGoneSplitPage} from '../webstatus-feature-gone-split-page.js';
import {Task} from '@lit/task';
import {APIClient} from '../../contexts/api-client-context.js';
import {GITHUB_REPO_ISSUE_LINK} from '../../utils/constants.js';
type NewFeature = {name: string; url: string};
describe('webstatus-feature-gone-split-page', () => {
const newFeatureIds = 'feature1,feature2';
const mockNewFeatures: NewFeature[] = [
{name: 'Feature One', url: '/features/feature1'},
{name: 'Feature Two', url: '/features/feature2'},
];
it('renders the correct error message', async () => {
const component = await fixture<WebstatusFeatureGoneSplitPage>(
html`<webstatus-feature-gone-split-page
.location=${{search: ''}}
></webstatus-feature-gone-split-page>`,
);
expect(
component.shadowRoot
?.querySelector('#error-status-code')
?.textContent?.trim(),
).to.equal('410');
expect(
component.shadowRoot
?.querySelector('#error-headline')
?.textContent?.trim(),
).to.equal('Feature Gone');
expect(
component.shadowRoot
?.querySelector('#error-detailed-message .error-message')
?.textContent?.trim(),
).to.equal('This feature has been split into multiple new features.');
});
it('displays "Loading new features..." when the API request is pending', async () => {
const component = await createComponentWithMockedNewFeatures(
newFeatureIds,
[],
{stayPending: true},
);
const loadingMessage =
component.shadowRoot?.querySelector('.loading-message');
expect(loadingMessage).to.exist;
expect(loadingMessage?.textContent?.trim()).to.equal(
'Loading new features...',
);
});
it('renders new features when API returns results', async () => {
const component = await createComponentWithMockedNewFeatures(
newFeatureIds,
mockNewFeatures,
);
const featureList =
component.shadowRoot?.querySelectorAll('.feature-list li');
expect(featureList?.length).to.equal(2);
expect(featureList?.[0]?.textContent?.trim()).to.equal('Feature One');
expect(featureList?.[1]?.textContent?.trim()).to.equal('Feature Two');
});
it('renders action buttons', async () => {
const component = await fixture<WebstatusFeatureGoneSplitPage>(html`
<webstatus-feature-gone-split-page
.location=${{search: ''}}
></webstatus-feature-gone-split-page>
`);
expect(component.shadowRoot?.querySelector('#error-action-home-btn')).to
.exist;
expect(component.shadowRoot?.querySelector('#error-action-report')).to
.exist;
});
it('report issue button links to GitHub', async () => {
const component = await fixture<WebstatusFeatureGoneSplitPage>(html`
<webstatus-feature-gone-split-page
.location=${{search: ''}}
></webstatus-feature-gone-split-page>
`);
const reportButton = component.shadowRoot?.querySelector(
'#error-action-report',
);
expect(reportButton?.getAttribute('href')).to.equal(GITHUB_REPO_ISSUE_LINK);
});
async function createComponentWithMockedNewFeatures(
newFeatureIds: string,
mockData: NewFeature[],
options: {stayPending?: boolean} = {},
): Promise<WebstatusFeatureGoneSplitPage> {
const component = await fixture<WebstatusFeatureGoneSplitPage>(html`
<webstatus-feature-gone-split-page
.location=${{search: `?new_features=${newFeatureIds}`}}
></webstatus-feature-gone-split-page>
`);
component._newFeatures = new Task<[APIClient, string], NewFeature[]>(
component,
{
args: () => [undefined as unknown as APIClient, newFeatureIds],
task: async () => {
if (options.stayPending) return new Promise(() => {});
return mockData;
},
},
);
component._newFeatures.run();
await component.updateComplete;
return component;
}
});