Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleJu committed Oct 30, 2024
1 parent 779b9ed commit 346f845
Showing 1 changed file with 108 additions and 2 deletions.
110 changes: 108 additions & 2 deletions client-src/elements/chromedash-feature-page_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('chromedash-feature-page', () => {
'Spec link': 'fake spec link',
'Web developer signals': 'True',
});
const channelsPromise = Promise.resolve({
const channels = {
canary_asan: {
version: 81,
earliest_beta: '2020-02-13T00:00:00',
Expand All @@ -59,13 +59,15 @@ describe('chromedash-feature-page', () => {
version: 80,
earliest_beta: '2020-02-13T00:00:00',
mstone: 'fake milestone number',
final_beta: '2020-03-13T00:00:00',
},
stable: {
version: 79,
earliest_beta: '2020-02-13T00:00:00',
mstone: 'fake milestone number',
},
});
};
const channelsPromise = Promise.resolve(channels);
const validFeaturePromise = Promise.resolve({
id: 123456,
name: 'feature one',
Expand All @@ -92,6 +94,7 @@ describe('chromedash-feature-page', () => {
maturity: {text: 'Unknown standards status - check spec link for status'},
},
tags: ['tag_one'],

stages: [
{
id: 1,
Expand All @@ -103,6 +106,12 @@ describe('chromedash-feature-page', () => {
stage_type: 120,
intent_stage: 2,
},
{
id: 3,
stage_type: 160,
intent_stage: 3,
desktop_first: 80,
},
],
});

Expand Down Expand Up @@ -314,4 +323,101 @@ describe('chromedash-feature-page', () => {
// But it does still include webdev views.
assert.include(consensusSection.innerHTML, 'fake webdev view text');
});

it('isFeatureUpcoming tests', async () => {
const featureId = 123456;
const contextLink = '/features';
const feature: any = structuredClone(await validFeaturePromise);
const component: ChromedashFeaturePage =
await fixture<ChromedashFeaturePage>(
html`<chromedash-feature-page
.user=${user}
.featureId=${featureId}
.contextLink=${contextLink}
>
</chromedash-feature-page>`
);
assert.exists(component);

component.isFeatureUpcoming({}, feature.stages);
assert.isFalse(component.isUpcoming);
assert.equal(component.closestShippingMilestone, '');

component.isFeatureUpcoming(channels, []);
assert.isFalse(component.isUpcoming);
assert.equal(component.closestShippingMilestone, '');

// No shipping milestones.
let stages: any = structuredClone(feature.stages);
stages[2].stage_type = 130;
component.isFeatureUpcoming(channels, stages);
assert.isFalse(component.isUpcoming);
assert.equal(component.closestShippingMilestone, '');

// No upcoming shipping milestones.
stages = structuredClone(feature.stages);
stages[2].desktop_first = 20;
component.isFeatureUpcoming(channels, stages);
assert.isFalse(component.isUpcoming);
assert.equal(component.closestShippingMilestone, '');

component.isFeatureUpcoming(channels, feature.stages);
assert.isTrue(component.isUpcoming);
assert.equal(component.closestShippingMilestone, '2020-03-13T00:00:00');
});

it('isFeatureOutdated tests', async () => {
const featureId = 123456;
const contextLink = '/features';
const feature: any = structuredClone(await validFeaturePromise);
feature.accurate_as_of = '2024-08-28 21:51:34.22386';
window.csClient.getFeature
.withArgs(featureId)
.returns(Promise.resolve(feature));
const component: ChromedashFeaturePage =
await fixture<ChromedashFeaturePage>(
html`<chromedash-feature-page
.user=${user}
.featureId=${featureId}
.contextLink=${contextLink}
>
</chromedash-feature-page>`
);
component.currentDate = new Date('2024-10-23').getTime();
assert.exists(component);

component.isFeatureUpcoming(channels, feature.stages);
assert.isTrue(component.isUpcoming);
assert.equal(component.closestShippingMilestone, '2020-03-13T00:00:00');
assert.isTrue(component.isFeatureOutdated());

// accurate_as_of is not outdated and within the 4-week grace period.
component.currentDate = new Date('2024-09-18').getTime();
assert.isFalse(component.isFeatureOutdated());
});

it('render the oudated warning when feature is outdated', async () => {
const featureId = 123456;
const contextLink = '/features';
const feature: any = structuredClone(await validFeaturePromise);
feature.accurate_as_of = '2024-08-28 21:51:34.22386';
window.csClient.getFeature
.withArgs(featureId)
.returns(Promise.resolve(feature));
const component: ChromedashFeaturePage =
await fixture<ChromedashFeaturePage>(
html`<chromedash-feature-page
.user=${user}
.featureId=${featureId}
.contextLink=${contextLink}
>
</chromedash-feature-page>`
);
component.currentDate = new Date('2024-10-23').getTime();
assert.exists(component);

component.isFeatureUpcoming(channels, feature.stages);
const oudated = component.shadowRoot!.querySelector('#outdated-icon');
assert.exists(oudated);
});
});

0 comments on commit 346f845

Please sign in to comment.