Skip to content

Commit

Permalink
rubocop and lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielRMuller committed Aug 16, 2024
1 parent 89c0491 commit 5be175c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 135 deletions.
34 changes: 5 additions & 29 deletions app/assets/javascripts/actions/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,33 +223,8 @@ export const updateCollapsedStory =
);
};

export const toggleStory =
(currentStory, from) =>
async (dispatch, _, { Story }) => {
if (!currentStory.collapsed) {
return dispatch(collapseStory(currentStory.id, from));
}

if (isStoryLoading(currentStory)) {
return;
}

dispatch(setLoadingStory(currentStory.id, from));
try {
const { data } = await projectStoriesService.fetchStory(currentStory);
dispatch(
updateStorySuccess(
{ ...Story.deserialize(data.story), ...currentStory },
from
)
);
dispatch(expandStory(currentStory.id, from));
} catch (error) {
dispatch(sendErrorNotification(error));
}
};

export const dragDropStory = (storyId, projectId, newAttributes, from) =>
export const dragDropStory =
(storyId, projectId, newAttributes, from) =>
async (dispatch, getState, { Story }) => {
const { stories } = getState();

Expand All @@ -263,7 +238,8 @@ export const dragDropStory = (storyId, projectId, newAttributes, from) =>
);

try {
dispatch(optimisticallyUpdate(newStory, from));
// Optimistic Update:
dispatch(sortStories(storiesWithUpdatedPositions, from));
const updatedStories = await Story.updatePosition(newStory);
await wait(300);
return dispatch(sortStories(updatedStories, from));
Expand Down Expand Up @@ -373,7 +349,7 @@ export const saveStory =
);
}

return dispatch(toggleStory(story.id, from));
return dispatch(collapseStory(story.id, from));
};

export const deleteStory =
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/components/story/StoryItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
isHighlighted,
isAccepted,
} from '../../models/beta/story';
import { releaseIsLate, isHighlighted, isAccepted } from '../../models/beta/story';
import classNames from 'classnames';

export const StoryItem = ({
Expand Down
29 changes: 17 additions & 12 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@ class Story < ApplicationRecord
start_date.beginning_of_day,
end_date.end_of_day)
}
scope :not_accepted_or_recently_accepted, ->(current_iteration_start) { where.not(state: 'accepted').or(where("accepted_at >= ?", current_iteration_start))}
scope :collapsed_story, -> {select(
:id,
:title,
:description,
:estimate,
:story_type,
:state,
:requested_by_name,
:owned_by_initials,
:project_id
)}
scope :not_accepted_or_recently_accepted, lambda { |current_iteration_start|
where.not(state: 'accepted').or(where('accepted_at >= ?', current_iteration_start))
}

scope :collapsed_story, lambda {
select(
:id,
:title,
:description,
:estimate,
:story_type,
:state,
:requested_by_name,
:owned_by_initials,
:project_id
)
}

delegate :suppress_notifications, to: :project

Expand Down
96 changes: 3 additions & 93 deletions spec/javascripts/actions/story_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Story Actions', () => {
);
});

it('dispatch only toggleStory when _isDirty is false', async () => {
it('dispatches collapseStory when _isDirty is false', async () => {
const editedStory = {
...story,
_editing: {
Expand All @@ -75,7 +75,7 @@ describe('Story Actions', () => {
);

expect(fakeDispatch).toHaveBeenCalledWith(
Story.toggleStory(editedStory.id)
Story.collapseStory(editedStory.id)
);
expect(fakeDispatch).not.toHaveBeenCalledWith(
Story.updateStorySuccess(story)
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('Story Actions', () => {
Story.updateStorySuccess(story)
);
expect(fakeDispatch).not.toHaveBeenCalledWith(
Story.toggleStory(editedStory.id)
Story.collapseStory(editedStory.id)
);
});

Expand Down Expand Up @@ -565,94 +565,4 @@ describe('Story Actions', () => {
});
});
});

describe('toggleStory', () => {
const fakeDispatch = jest.fn();
beforeEach(() => {
jest.clearAllMocks();
});
const expandedStory = { id: 5 };
const collapsedStory = { id: 5, collapsed: true };
const dependencies = { Story: { deserialize: () => {} } };

describe('when is expanded', () => {
it('should dispatch collapseStory', async () => {
const thunkFunction = Story.toggleStory(expandedStory, undefined);
await thunkFunction(fakeDispatch, null, dependencies);
expect(fakeDispatch).toHaveBeenCalledWith({
type: actionTypes.COLLAPSE_STORY,
storyId: expandedStory.id,
from: undefined,
});
});

it('should not dispatch "updateStorySuccess"', async () => {
const thunkFunction = Story.toggleStory(expandedStory, undefined);
await thunkFunction(fakeDispatch, null, dependencies);
expect(fakeDispatch).not.toHaveBeenCalledWith({
type: actionTypes.UPDATE_STORY_SUCCESS,
story: expandedStory,
from: undefined,
});
});

it('should not dispatch loading', async () => {
const thunkFunction = Story.toggleStory(expandedStory, undefined);
await thunkFunction(fakeDispatch, null, dependencies);
expect(fakeDispatch).not.toHaveBeenCalledWith({
type: actionTypes.SET_LOADING_STORY,
id: expandedStory.id,
from: undefined,
});
});
});

describe('when is collapsed', () => {
it('should dispatch loading', async () => {
const thunkFunction = Story.toggleStory(collapsedStory, undefined);
await thunkFunction(fakeDispatch, null, dependencies);
expect(fakeDispatch).toHaveBeenCalledWith({
type: actionTypes.SET_LOADING_STORY,
id: collapsedStory.id,
from: undefined,
});
});

describe('when request is successful', () => {
beforeEach(() => {
httpService.get.mockResolvedValue({ data: { story: {} } });
});
it('should dispatch "updateStorySuccess"', async () => {
const thunkFunction = Story.toggleStory(collapsedStory, undefined);
await thunkFunction(fakeDispatch, null, dependencies);
expect(fakeDispatch).toHaveBeenCalledWith({
type: actionTypes.UPDATE_STORY_SUCCESS,
story: collapsedStory,
from: undefined,
});
});

it('should dispatch expandStory on success', async () => {
const thunkFunction = Story.toggleStory(collapsedStory, undefined);
await thunkFunction(fakeDispatch, null, dependencies);
expect(fakeDispatch).toHaveBeenCalledWith({
type: actionTypes.EXPAND_STORY,
storyId: collapsedStory.id,
from: undefined,
});
});
});

describe('when request fails', () => {
beforeEach(() => {
httpService.get.mockRejectedValue();
});
it('should handle fetch error', async () => {
const thunkFunction = Story.toggleStory(collapsedStory, undefined);
await thunkFunction(fakeDispatch, null, dependencies);
expect(sendErrorNotification).toHaveBeenCalled();
});
});
});
});
});

0 comments on commit 5be175c

Please sign in to comment.