Skip to content

Commit

Permalink
Upgrade React, Webpack, and use Jest (#994)
Browse files Browse the repository at this point in the history
* Upgrade React and Webpack

* Replace Karma + Jasmine with Jest

* Disable prerendering cause of problems on production
  • Loading branch information
julianguyen authored Sep 22, 2018
1 parent 2f71912 commit 2bd9943
Show file tree
Hide file tree
Showing 37 changed files with 1,461 additions and 989 deletions.
1 change: 0 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ engines:
exclude_paths:
- public/javascripts/
- vendor/assets/javascripts
- client/karma.conf.js
- client/flow/
fixme:
enabled: false
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/core/grids.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
}

@mixin gridH1() {
Expand Down Expand Up @@ -124,6 +123,7 @@
}
&SpaceBetween {
@include gridRow();
flex-wrap: wrap;
justify-content: space-between;
}
}
Expand Down
30 changes: 10 additions & 20 deletions app/controllers/meetings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ def show
meeting_id: @meeting.id,
user_id: current_user.id
).exists?

@is_group_member = GroupMember.where(
group_id: @meeting.group_id,
user_id: current_user.id
).exists?
@is_leader = MeetingMember.where(
meeting_id: @meeting.id,
user_id: current_user.id,
leader: true
).exists?

@no_hide_page = false
if hide_page(@meeting)
redirect_to_path(group_path(@meeting.group_id))
else
if @is_member
@no_hide_page = true
@comment = Comment.new
@comments = Comment.where(
commentable_id: @meeting.id,
commentable_type: 'meeting'
).all.order('created_at DESC')

@no_hide_page = true
elsif !@is_group_member
redirect_to_path(groups_path)
end
end
# rubocop:enable MethodLength
Expand Down Expand Up @@ -77,7 +78,6 @@ def delete_comment
def new
@group_id = params[:group_id]
not_a_leader(@group_id)

@meeting = Meeting.new
end

Expand Down Expand Up @@ -173,8 +173,7 @@ def join
meeting_id: params[:meeting_id],
leader: true
).all
meeting_id = Meeting.where(id: params[:meeting_id]).first.id
meeting = Meeting.where(id: params[:meeting_id]).first.name
meeting = Meeting.find(params[:meeting_id])

MeetingNotificationsService.handle_members(current_user: current_user,
meeting: meeting,
Expand All @@ -183,7 +182,7 @@ def join

respond_to do |format|
format.html do
redirect_to(meeting_path(meeting_id),
redirect_to(meeting_path(params[:meeting_id]),
notice: t('meetings.join_success'))
end
format.json do
Expand Down Expand Up @@ -282,14 +281,5 @@ def meeting_params
params.require(:meeting).permit(:name, :description, :location, :date,
:time, :maxmembers, :group_id)
end

def hide_page(meeting)
meeting_obj = Meeting.where(id: meeting.id)
meeting_member = MeetingMember.where(
meeting_id: meeting.id,
user_id: current_user.id
)
!(meeting_obj.exists? && meeting_member.exists?)
end
end
# rubocop:enable ClassLength
6 changes: 0 additions & 6 deletions app/helpers/moods_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ def mood_form_inputs
label: t('common.form.description'),
value: @mood.description || nil,
dark: true
},
{
id: 'submit',
type: 'submit',
value: t('common.actions.submit'),
dark: true
}
]
end
Expand Down
4 changes: 3 additions & 1 deletion app/views/allies/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@
<% end %>

<% if @outgoing_ally_requests.empty? && @incoming_ally_requests.empty? && @accepted_allies.count == 0 %>
<%= t('allies.index.none') %>
<div class="small_margin_top">
<%= t('allies.index.none') %>
</div>
<% end %>
4 changes: 1 addition & 3 deletions app/views/categories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
<%= paginate @categories %>
<% else %>
<%= raw t('categories.index.instructions') %>
<div class="actions">
<%= button_to t('common.actions.add_all'), premade_categories_path %>
</div>
<%= button_to t('common.actions.add_all'), premade_categories_path, class: 'small_margin_top buttonDarkS' %>

<div class="spacer"></div>

Expand Down
39 changes: 39 additions & 0 deletions app/views/groups/_info.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<%= sanitize(local_assigns[:group].description) %>
<div class="small_margin_top">
<%= react_component('Modal', props: {
element: "<button class=\"buttonDarkXS groupMembersButton\">#{t('members', count: local_assigns[:group].group_members.count)}</button>",
title: t('notifications.members.title'),
body: render(partial: '/groups/members', locals: { group: local_assigns[:group] })
}) %>
</div>
<div class="gridItemBoxDark gridRowSpaceBetween small_margin_top">
<div class="gridRowSpaceBetween">
<div class="smaller_margin_right"><%= t('common.actions.plural') %>:</div>
<%= react_component('StoryActions', props: {
dark: true,
actions: {
join: !local_assigns[:group].members.include?(current_user) ? {
name: t('common.actions.join'),
link: group_membership_path(group_id: local_assigns[:group].id, id: 'join'),
dataMethod: 'post'
} : nil,
leave: local_assigns[:group].members.include?(current_user) && user_can_leave?(local_assigns[:group]) ? {
name: t('common.actions.leave'),
link: group_membership_path(group_id: local_assigns[:group].id, id: 'leave'),
dataConfirm: t('common.actions.confirm'),
dataMethod: 'delete'
} : nil,
edit: user_can_edit?(local_assigns[:group]) ? {
name: t('common.actions.edit'),
link: edit_group_path(local_assigns[:group])
} : nil,
delete: user_can_delete?(local_assigns[:group]) ? {
name: t('common.actions.delete'),
link: url_for(local_assigns[:group]),
dataConfirm: t('common.actions.confirm'),
dataMethod: 'delete'
} : nil
}
}) %>
</div>
</div>
8 changes: 0 additions & 8 deletions app/views/groups/_story_body.html.erb

This file was deleted.

14 changes: 6 additions & 8 deletions app/views/groups/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
link: url_for(group),
dataConfirm: t('common.actions.confirm'),
dataMethod: 'delete'
} : nil,
},
body: render(partial: '/groups/story_body', locals: { group: group })
} : nil
}
}) %>
</div>
<% end %>
Expand All @@ -44,9 +43,9 @@
<%= t('pages.faq.group_question') %>
</div>

<%= raw t('pages.faq.group_answer',{
groups: link_to(t('groups.singular'), groups_path)
}) %>
<%= raw t('pages.faq.group_answer', {
group: link_to(t('groups.singular'), groups_path)
}) %>
<% end %>

<% if @available_groups.any? %>
Expand All @@ -64,8 +63,7 @@
link: group_membership_path(group_id: group.id, id: 'join'),
dataMethod: 'post'
}
},
body: render(partial: '/groups/story_body', locals: { group: group })
}
}) %>
</div>
<% end %>
Expand Down
30 changes: 1 addition & 29 deletions app/views/groups/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
<% title @group.name %>
<% page_new new_meeting_path(group_id: @group.id) %>
<%= render partial: '/groups/story_body', locals: { group: @group } %>
<% if user_is_leader_of?(@group) %>
<div class="gridItemBoxDark gridRowSpaceBetween small_margin_top">
<div class="gridRowSpaceBetween">
<div class="smaller_margin_right"><%= t('common.actions.plural') %>:</div>
<%= react_component('StoryActions', props: {
dark: true,
actions: {
leave: user_can_leave?(@group) ? {
name: t('common.actions.leave'),
link: group_membership_path(group_id: @group.id, id: 'leave'),
dataConfirm: t('common.actions.confirm'),
dataMethod: 'delete'
} : nil,
edit: user_can_edit?(@group) ? {
name: t('common.actions.edit'),
link: edit_group_path(@group)
} : nil,
delete: user_can_delete?(@group) ? {
name: t('common.actions.delete'),
link: url_for(@group),
dataConfirm: t('common.actions.confirm'),
dataMethod: 'delete'
} : nil
}
}) %>
</div>
</div>
<% end %>
<%= render partial: '/groups/info', locals: { group: @group } %>

<% if @meetings.present? %>
<div class="gridTwo small_margin_top">
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<body class="<%= controller_name %> <%= action_name %>">
<div class="content <%= (user_signed_in? && !static_page?) || secret_share_path? ? 'dashboard' : 'static' %>">
<%= react_component('Header', prerender: true, props: header_props) %>
<%= react_component('Header', props: header_props) %>
<%= render partial: 'shared/alerts' %>
<% if user_signed_in? && !static_page? %>
<div class="dashboardContent">
Expand Down
20 changes: 0 additions & 20 deletions app/views/meetings/_story_body.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<div class="small_margin_bottom">
<%= sanitize(meeting.description) %>
</div>

<div>
<strong>
<%= t('common.form.location') %>:
Expand Down Expand Up @@ -31,19 +27,3 @@
<%= get_meeting_members(meeting) %>
</strong>
</div>
<div class="small_margin_top">
<%
if local_assigns[:show_group]
elementText = t('meetings.info.members_of_group_html',
count: meeting.members.count,
group: link_to(meeting.group.name, meeting.group))
else
elementText = t('members', count: meeting.members.count)
end
%>
<%= react_component('Modal', prerender: true, props: {
element: "<button class=\"buttonDarkXS meetingMembersButton\">#{elementText}</button>",
title: t('notifications.members.title'),
body: render(partial: '/groups/members', locals: { group: meeting })
}) %>
</div>
16 changes: 15 additions & 1 deletion app/views/meetings/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
<% title @meeting.name %>
<div class="small_margin_bottom">
<%= sanitize(@meeting.description) %>
</div>
<%= render partial: '/meetings/story_body', locals: { meeting: @meeting } %>
<div class="small_margin_top">
<%= react_component('Modal', props: {
element: "<button class=\"buttonDarkXS meetingMembersButton\">#{t('members', count: @meeting.members.count)}</button>",
title: t('notifications.members.title'),
body: render(partial: '/groups/members', locals: { group: @meeting })
}) %>
</div>
<% if user_is_leader_of?(@meeting) %>
<div class="gridItemBoxDark gridRowSpaceBetween small_margin_top">
<div class="gridRowSpaceBetween">
<div class="smaller_margin_right"><%= t('common.actions.plural') %>:</div>
<%= react_component('StoryActions', props: {
dark: true,
actions: {
delete: @meeting.leaders.include?(current_user) && {
edit: {
name: t('common.actions.edit'),
link: edit_meeting_path(@meeting)
},
delete: {
name: t('common.actions.delete'),
link: url_for(@meeting),
dataConfirm: t('common.actions.confirm'),
Expand Down
2 changes: 1 addition & 1 deletion app/views/moods/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<%= paginate @moods %>
<% else %>
<%= raw t('moods.index.instructions') %>
<%= button_to t('common.actions.add_all'), premade_moods_path %>
<%= button_to t('common.actions.add_all'), premade_moods_path, class: 'small_margin_top buttonDarkS' %>

<div class="spacer"></div>

Expand Down
4 changes: 1 addition & 3 deletions app/views/strategies/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
<%= paginate @strategies %>
<% else %>
<%= raw t('strategies.index.instructions') %>
<div class="actions">
<%= button_to t('common.actions.add'), premade_strategies_path %>
</div>
<%= button_to t('common.actions.add'), premade_strategies_path, class: 'small_margin_top buttonDarkS' %>

<div class="spacer"></div>

Expand Down
1 change: 0 additions & 1 deletion client/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
flow/
flow-typed/
default.js
karma.conf.js
translations.js
4 changes: 2 additions & 2 deletions client/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"plugins": ["jasmine", "flowtype"],
"plugins": ["flowtype", "jest", "react"],
"extends": ["airbnb", "plugin:flowtype/recommended"],
"parser": "babel-eslint",
"env": {
"browser": true,
"jasmine": true
"jest/globals": true
},
"root": true,
"rules": {
Expand Down
1 change: 0 additions & 1 deletion client/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.*/__tests__/.*
.*/node_modules/draft-js/.*
.*/node_modules/enzyme-matchers/.*
.*/node_modules/jasmine-enzyme/.*
.*/node_modules/radium/.*

[include]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function messaging(ids) {

describe('CheckboxGroup', () => {
beforeEach(() => {
spyOn(window, 'alert');
jest.spyOn(window, 'alert');
});

describe('when there is one checkbox', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const someEvent = (checkbox) => {

describe('InputCheckbox', () => {
beforeEach(() => {
spyOn(window, 'alert');
jest.spyOn(window, 'alert');
});

describe('has no uncheckedValue prop', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const checkboxes = [

describe('InputCheckboxGroup', () => {
beforeEach(() => {
spyOn(window, 'alert');
jest.spyOn(window, 'alert');
});

describe('has no required prop', () => {
Expand Down
Loading

0 comments on commit 2bd9943

Please sign in to comment.