Skip to content

Commit

Permalink
build: remove enzyme enzyme-adapter-react-16 and sinon from dependenc…
Browse files Browse the repository at this point in the history
…ies and replace last sinon.fakeServer for msw
  • Loading branch information
wrspada02 committed Sep 27, 2024
1 parent 450a87f commit 70925a8
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 532 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@
"babel-jest": "^24.9.0",
"coveralls": "^3.0.9",
"cypress": "^10.1.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.1",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-react-app": "^5.0.2",
Expand All @@ -106,7 +104,6 @@
"prettier": "^3.0.3",
"react-addons-test-utils": "^15.6.2",
"react-test-renderer": "^16.12.0",
"sinon": "^7.5.0",
"vite": "^4.5.3",
"vite-plugin-ruby": "^3.2.0",
"vitest": "^2.0.5"
Expand Down
94 changes: 43 additions & 51 deletions spec/javascripts/models/past_iteration_spec.js
Original file line number Diff line number Diff line change
@@ -1,100 +1,92 @@
import Cookies from 'js-cookie';
import Project from 'models/project';
import PastIteration from 'models/pastIteration';
import { server } from '../mocks/server';
import { http, HttpResponse } from 'msw';

describe('PastIteration model', function() {
describe('PastIteration model', function () {
let project;
let pastIterations;

beforeEach(function() {
Cookies.set('current_flow', 'progress_to_left', {expires: 365});
beforeEach(function () {
Cookies.set('current_flow', 'progress_to_left', { expires: 365 });

project = new Project({
id: 1337, title: 'Test project', point_values: [0, 1, 2, 3],
last_changeset_id: null, iteration_start_day: 1, iteration_length: 1,
id: 1337,
title: 'Test project',
point_values: [0, 1, 2, 3],
last_changeset_id: null,
iteration_start_day: 1,
iteration_length: 1,
default_flow: Cookies.get('current_flow'),
current_flow: Cookies.get('current_flow')
current_flow: Cookies.get('current_flow'),
});

pastIterations = new PastIteration({
project: project,
startDate: Date.now(),
endDate: Date.now() + 7,
points: 3,
iterationNumber: 2
project: project,
startDate: Date.now(),
endDate: Date.now() + 7,
points: 3,
iterationNumber: 2,
});
});

describe('when instantiated', function() {

it("should exhibit attributes", function() {
describe('when instantiated', function () {
it('should exhibit attributes', function () {
expect(pastIterations.get('number')).toEqual(2);
});

it("should have a default load state", function() {
it('should have a default load state', function () {
expect(pastIterations.get('needsLoad')).toBe(true);
});

it("should have a default column", function() {
it('should have a default column', function () {
expect(pastIterations.get('column')).toBe('#done');
});
});

describe('stories', function() {

it('should return the models stories', function() {
describe('stories', function () {
it('should return the models stories', function () {
expect(pastIterations.stories()).toEqual(pastIterations._stories);
});

});

describe('startDate', function() {

it('should return the models start date', function() {
describe('startDate', function () {
it('should return the models start date', function () {
expect(pastIterations.startDate()).toEqual(pastIterations._startDate);
});

});

describe('endDate', function() {

it('should return the models end date', function() {
describe('endDate', function () {
it('should return the models end date', function () {
expect(pastIterations.endDate()).toEqual(pastIterations._endDate);
});

});

describe('points', function() {

it('should return the model points', function() {
describe('points', function () {
it('should return the model points', function () {
expect(pastIterations.points()).toEqual(pastIterations._points);
});

});

describe('fetch', function() {

it('should update the stories from the iteration', function(done) {
var story = [ { story:{id:42,title:"Test story"} } ];
var stories = { stories:story }
var server = sinon.fakeServer.create();

server.respondImmediately = true;
server.respondWith(
"GET", /\/project_boards\/1337\/iterations(.*)/, [
200, {"Content-Type": "application/json"},
JSON.stringify(stories)
]
describe('fetch', function () {
it('should update the stories from the iteration', function (done) {
var story = [{ story: { id: 42, title: 'Test story' } }];
var stories = { stories: story };
server.use(
http.get(/\/project_boards\/1337\/iterations(.*)/, () => {
return HttpResponse.json(stories), { status: 200 };
})
);

var initialStoriesLength = pastIterations._stories.length;

pastIterations.fetch()
.then(() => {
expect(pastIterations._stories.length).toEqual(initialStoriesLength + 1);
done();
});
pastIterations.fetch().then(() => {
expect(pastIterations._stories.length).toEqual(
initialStoriesLength + 1
);
done();
});
});
});

});
80 changes: 46 additions & 34 deletions spec/javascripts/models/project_board_spec.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,79 @@
import Cookies from 'js-cookie';
import Project from 'models/project';
import ProjectBoard from 'models/projectBoard';
import { server } from '../mocks/server';
import { http, HttpResponse } from 'msw';

describe('ProjectBoard model', function() {
describe('ProjectBoard model', function () {
let project;
let projectBoard;

beforeEach(function() {
Cookies.set('current_flow', 'progress_to_left', {expires: 365});
beforeEach(function () {
Cookies.set('current_flow', 'progress_to_left', { expires: 365 });

project = new Project({
id: 1337, title: 'Test project', point_values: [0, 1, 2, 3],
last_changeset_id: null, iteration_start_day: 1, iteration_length: 1,
id: 1337,
title: 'Test project',
point_values: [0, 1, 2, 3],
last_changeset_id: null,
iteration_start_day: 1,
iteration_length: 1,
default_flow: Cookies.get('current_flow'),
current_flow: Cookies.get('current_flow')
current_flow: Cookies.get('current_flow'),
});

projectBoard = new ProjectBoard({project: project});
projectBoard = new ProjectBoard({ project: project });
});

describe('when instantiated', function() {

it('should set up a story collection', function() {
describe('when instantiated', function () {
it('should set up a story collection', function () {
expect(projectBoard.stories).toBeDefined();
});

it('should have a project', function() {
it('should have a project', function () {
expect(projectBoard.project).toBe(project);
expect(projectBoard.stories.project).toBe(project);
});

it("should have a default past iterations empty array", function() {
it('should have a default past iterations empty array', function () {
expect(projectBoard.pastIterations).toEqual([]);
});

});

describe('fetch', function() {

it('should update the past iterations and stories of the project board', function(done) {
var activeStories = [{story:{id:42,title:"Active story"}}];
var pastIterations = [{start_date:"2018/03/19",end_date:"2018/03/25",points:3,iteration_number:2}];
var dataHash = {active_stories: activeStories, past_iterations: pastIterations}
var server = sinon.fakeServer.create();
server.respondImmediately = true;
server.respondWith(
"GET", "/project_boards/1337", [
200, {"Content-Type": "application/json"},
JSON.stringify(dataHash)
]
describe('fetch', function () {
it('should update the past iterations and stories of the project board', function (done) {
var activeStories = [{ story: { id: 42, title: 'Active story' } }];
var pastIterations = [
{
start_date: '2018/03/19',
end_date: '2018/03/25',
points: 3,
iteration_number: 2,
},
];
var dataHash = {
active_stories: activeStories,
past_iterations: pastIterations,
};
server.use(
http.get('/project_boards/1337', () => {
return HttpResponse.json(dataHash), { status: 200 };
})
);

var initialPastIterationsLength = projectBoard.pastIterations.length;

var initialActiveStoriesLength = projectBoard.stories.length
var initialActiveStoriesLength = projectBoard.stories.length;

projectBoard.fetch()
.then(() => {
expect(projectBoard.pastIterations.length).toEqual(initialPastIterationsLength + 1);
expect(projectBoard.stories.length).toEqual(initialActiveStoriesLength + 1);
done();
});
projectBoard.fetch().then(() => {
expect(projectBoard.pastIterations.length).toEqual(
initialPastIterationsLength + 1
);
expect(projectBoard.stories.length).toEqual(
initialActiveStoriesLength + 1
);
done();
});
});
});

});
42 changes: 21 additions & 21 deletions spec/javascripts/models/project_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,16 @@ describe('Project model', function () {
describe('changesets', function () {
it('should load changesets when last_changeset_id is changed', function () {
var changesets = [
{ changeset: { id: 2, story_id: 456, project_id: 789 }},
{ changeset: { id: 2, story_id: 456, project_id: 789 } },
];

vi.spyOn(project, 'handleChangesets').mockImplementation((arg) => {
vi.spyOn(project, 'handleChangesets').mockImplementation(arg => {
expect(arg).toStrictEqual(changesets);
});

server.use(
http.get('/projects/999/changesets', () => {
return HttpResponse.json(
changesets,
{ status: 200 },
);
return HttpResponse.json(changesets, { status: 200 });
})
);

Expand All @@ -108,7 +105,6 @@ describe('Project model', function () {
});

it('should reload changed stories from changesets', function () {

var changesets = [
{ changeset: { id: 123, story_id: 456, project_id: 789 } },
];
Expand All @@ -125,10 +121,7 @@ describe('Project model', function () {
var story_json = { story: { id: 123 } };
server.use(
http.get('/projects/999/stories/123', () => {
return HttpResponse.json(
story_json,
{ status: 200 },
);
return HttpResponse.json(story_json, { status: 200 });
})
);

Expand All @@ -152,10 +145,7 @@ describe('Project model', function () {
var story_json = { story: { id: 987, title: 'New changeset story' } };
server.use(
http.get('/projects/999/stories/987', () => {
return HttpResponse.json(
story_json,
{ status: 200 },
);
return HttpResponse.json(story_json, { status: 200 });
})
);

Expand Down Expand Up @@ -312,7 +302,9 @@ describe('Project model', function () {
var doneIterations = _.map([1, 2, 3, 4, 5], function (i) {
return { points: vi.fn().mockReturnValueOnce(i) };
});
vi.spyOn(project, 'doneIterations').mockImplementation(() => doneIterations);
vi.spyOn(project, 'doneIterations').mockImplementation(
() => doneIterations
);

// By default, should take the average of the last 3 iterations,
// (3 + 4 + 5) = 12 / 3 = 4
Expand All @@ -323,7 +315,9 @@ describe('Project model', function () {
var doneIterations = _.map([1, 2, 0, 4, 5], function (i) {
return { points: vi.fn().mockReturnValueOnce(i) };
});
vi.spyOn(project, 'doneIterations').mockImplementation(() => doneIterations);
vi.spyOn(project, 'doneIterations').mockImplementation(
() => doneIterations
);

// By default, should take the average of the last 3 iterations,
// (2 + 4 + 5) = 11 / 3 = 5
Expand All @@ -334,7 +328,9 @@ describe('Project model', function () {
var doneIterations = _.map([3, 2, 2], function (i) {
return { points: vi.fn().mockReturnValueOnce(i) };
});
vi.spyOn(project, 'doneIterations').mockImplementation(() => doneIterations);
vi.spyOn(project, 'doneIterations').mockImplementation(
() => doneIterations
);

// Should floor the result
// (3 + 2 + 2) = 7 / 3 = 2.333333
Expand All @@ -347,8 +343,10 @@ describe('Project model', function () {
var doneIterations = _.map([3, 1], function (i) {
return { points: vi.fn().mockReturnValueOnce(i) };
});

vi.spyOn(project, 'doneIterations').mockImplementation(() => doneIterations);

vi.spyOn(project, 'doneIterations').mockImplementation(
() => doneIterations
);

expect(project.velocity()).toEqual(2);
});
Expand All @@ -357,7 +355,9 @@ describe('Project model', function () {
var doneIterations = _.map([0, 0, 0], function (i) {
return { points: vi.fn().mockReturnValueOnce(i) };
});
vi.spyOn(project, 'doneIterations').mockImplementation(() => doneIterations);
vi.spyOn(project, 'doneIterations').mockImplementation(
() => doneIterations
);

expect(project.velocity()).toEqual(1);
});
Expand Down
Loading

0 comments on commit 70925a8

Please sign in to comment.