Skip to content

Commit

Permalink
Merge pull request #217 from emberobserver/more-static-data-in-tests
Browse files Browse the repository at this point in the history
Fix a few more instances where dynamic dates where causing Percy mismismatches
  • Loading branch information
pgengler authored Apr 2, 2021
2 parents 9118783 + a942c58 commit ca16c2f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
6 changes: 3 additions & 3 deletions mirage/factories/version.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Mirage from 'ember-cli-mirage';
import { Factory } from 'ember-cli-mirage';

export default Mirage.Factory.extend({
export default Factory.extend({
version: (i) => `1.0.${i}`,
released: () => new Date(),
released: '2021-01-01T12:34:56Z',
emberCliVersion: '1.13.1'
});
33 changes: 21 additions & 12 deletions tests/acceptance/addons-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { click, currentRouteName, currentURL, visit, findAll } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { percySnapshot } from 'ember-percy';
import { setupEmberObserverTest } from '../helpers/setup-ember-observer-test';
import { setupEmberObserverTest } from 'ember-observer/tests/helpers/setup-ember-observer-test';
import moment from 'moment';
import visitAddon from '../helpers/visit-addon';
import visitAddon from 'ember-observer/tests/helpers/visit-addon';
import Mirage from 'ember-cli-mirage';
import { setupOnerror, resetOnerror } from '@ember/test-helpers';
import Service from '@ember/service';

module('Acceptance: Addons', function(hooks) {
setupEmberObserverTest(hooks);
Expand Down Expand Up @@ -170,8 +171,8 @@ module('Acceptance: Addons', function(hooks) {
openIssues: 13,
forks: 94,
stars: 37,
latestCommitDate: window.moment().subtract(2, 'months').toString(),
firstCommitDate: window.moment().subtract(1, 'years').toString(),
latestCommitDate: moment().subtract(2, 'months').toString(),
firstCommitDate: moment().subtract(1, 'years').toString(),
addonId: addon.id
});

Expand Down Expand Up @@ -225,6 +226,14 @@ module('Acceptance: Addons', function(hooks) {
});

test('displays review', async function(assert) {
// make "current date" a static value so the relative date of the "last review" date
// doesn't change and cause Percy to show a change when it shouldn't.
this.owner.register('service:current-date', class extends Service {
get date() {
return moment('2020-10-31T17:14:51Z');
}
});

let addon = server.create('addon', {
name: 'test-addon'
});
Expand Down Expand Up @@ -252,14 +261,14 @@ module('Acceptance: Addons', function(hooks) {
let addonVersion = server.create('version', {
addon: addonWithReview,
review,
released: window.moment().subtract(3, 'months')
released: '2020-07-30T17:14:51Z'
});

// Newer version without review
let newerVersion = server.create('version', {
addon: addonWithReview,
review: null,
released: window.moment().subtract(1, 'months')
released: '2020-09-30T17:41:51Z'
});

review.update('versionId', addonVersion.id);
Expand Down Expand Up @@ -288,7 +297,7 @@ module('Acceptance: Addons', function(hooks) {
let addon = server.create('addon', {
name: 'test-addon',
maintainerIds: maintainers.map((m) => m.id),
latestVersionDate: window.moment().subtract(3, 'months'),
latestVersionDate: moment().subtract(3, 'months'),
isTopDownloaded: true,
lastMonthDownloads: 1564,
demoUrl: 'http://www.example.com/demo_of_addon',
Expand All @@ -301,7 +310,7 @@ module('Acceptance: Addons', function(hooks) {
version: '1.0.1',
addonId: addon.id,
emberCliVersion: '1.13.1',
released: window.moment().subtract(3, 'months')
released: moment().subtract(3, 'months')
});

addon.update('latestAddonVersion', version);
Expand All @@ -310,7 +319,7 @@ module('Acceptance: Addons', function(hooks) {
version: '1.0.0',
addonId: addon.id,
emberCliVersion: '1.13.0',
released: window.moment().subtract(4, 'months')
released: moment().subtract(4, 'months')
});

server.create('ember-version', {
Expand Down Expand Up @@ -377,7 +386,7 @@ module('Acceptance: Addons', function(hooks) {
assert.dom('.readme').doesNotExist('does not display readme');
});

test('displays addon dependencies', async (assert) => {
test('displays addon dependencies', async function(assert) {
let addon = server.create('addon');
let latestVersion = server.create('version', {
addon
Expand All @@ -402,7 +411,7 @@ module('Acceptance: Addons', function(hooks) {
assert.dom('.test-addon-dependencies .test-dependency-name').hasText(devDependency.package);
});

test('displays addon dependency size info when available', async (assert) => {
test('displays addon dependency size info when available', async function(assert) {
let addon = server.create('addon');
let latestVersion = server.create('version', {
addon
Expand Down Expand Up @@ -513,7 +522,7 @@ module('Acceptance: Addons', function(hooks) {
assert.equal(11, devDependencyPackages.length, 'Shows full list of dependencies');
});

test('when there are no addon dependencies', async (assert) => {
test('when there are no addon dependencies', async function(assert) {
let addon = server.create('addon');
let latestVersion = server.create('version', {
addon
Expand Down
8 changes: 4 additions & 4 deletions tests/acceptance/size-calculation-results-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { findAll, click, currentURL, currentRouteName, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { percySnapshot } from 'ember-percy';
import { setupEmberObserverTest } from '../helpers/setup-ember-observer-test';
import findByText from '../helpers/find-by-text';
import { setupEmberObserverTest } from 'ember-observer/tests/helpers/setup-ember-observer-test';
import findByText from 'ember-observer/tests/helpers/find-by-text';
import login from 'ember-observer/tests/helpers/login';
import moment from 'moment';

Expand Down Expand Up @@ -124,11 +124,11 @@ module('Acceptance | size calculation results', function(hooks) {
let testResult = server.create('sizeCalculationResult', {
versionId: version.id,
output: JSON.stringify(output),
testsRunAt: '2020-10-31T17:14:51Z',
createdAt: '2020-10-31T17:14:51Z',
});

await login();
await visit('/admin/size-calculation-results');
await visit('/admin/size-calculation-results?date=2020-10-31');
await click(findByText('.test-size-calculation-result a', 'details'));

await percySnapshot('/admin/size-calculation-results');
Expand Down

0 comments on commit ca16c2f

Please sign in to comment.