-
Notifications
You must be signed in to change notification settings - Fork 9
[OSDEV-1429] Block list uploading during release process #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Innavin369
merged 24 commits into
main
from
OSDEV-1429-block-list-uploading-during-release
Nov 22, 2024
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
831ac70
created flag, added disabled btn to UI
3f4ba57
added migration
84cb2d6
added task description
ea765f9
added flag on BE side
8b67afa
added tests for BE
5a8f8ac
merged main
3f1c1c5
fix after merge, updated message
6f1f42d
added UI tests
f40a68e
removed comments, changed duplicated code
cb55a58
added tests for tooltip, fixed component, changed mock data to avoid …
8a4d53b
merged main, resolved conflicts
a6b9c79
added changes regarding coderabbitai comments
ec1870e
added describe for tooltip test
acb91d0
added ServiceUnavailableException class and replaced raising error wi…
41fa5c3
merged main
ec69a3a
deleted tooltip test, created test for tooltip on hover Submit button
4f2acfc
linter
ed5a470
replaced status code using rest_framework, improved code
2100446
removed the redundant check
f842a0a
Merge branch 'main' into OSDEV-1429-block-list-uploading-during-release
226324d
recreated migration
39f234a
changed properties, added absolute import
b9e94be
lint
f702690
changed props for Button component
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| from rest_framework.exceptions import APIException | ||
| from rest_framework import status | ||
|
|
||
|
|
||
| class BadRequestException(APIException): | ||
| status_code = 400 | ||
| status_code = status.HTTP_400_BAD_REQUEST | ||
| default_detail = 'Bad request' | ||
| default_code = 'bad_request' | ||
|
|
||
|
|
||
| class ServiceUnavailableException(APIException): | ||
| status_code = status.HTTP_503_SERVICE_UNAVAILABLE | ||
| default_detail = 'Service is temporarily unavailable due to maintenance \ | ||
| work. Please try again later.' | ||
| default_code = 'service_unavailable' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/django/api/migrations/0161_create_bdisable_list_uploading.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Generated by Django 3.2.17 on 2024-11-22 09:50 | ||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| def create_disable_list_uploading_switch(apps, schema_editor): | ||
| Switch = apps.get_model('waffle', 'Switch') | ||
| Switch.objects.create(name='disable_list_uploading', active=False) | ||
|
|
||
|
|
||
| def delete_disable_list_uploading_switch(apps, schema_editor): | ||
| Switch = apps.get_model('waffle', 'Switch') | ||
| Switch.objects.get(name='disable_list_uploading').delete() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('api', '0160_allow_null_parsing_errors_in_facilitylist'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython( | ||
| create_disable_list_uploading_switch, | ||
| delete_disable_list_uploading_switch,) | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
258 changes: 258 additions & 0 deletions
258
src/react/src/__tests__/components/SubmitListUploadingButton.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,258 @@ | ||
| import React from 'react'; | ||
| import { render, fireEvent } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import { BrowserRouter as Router } from 'react-router-dom'; | ||
| import { Provider } from "react-redux"; | ||
| import configureMockStore from 'redux-mock-store' | ||
| import thunk from 'redux-thunk' | ||
|
|
||
| import ContributeList from '../../components/Contribute'; | ||
| import { MAINTENANCE_MESSAGE } from '../../util/constants'; | ||
|
|
||
| jest.mock('@material-ui/core/Popper', () => ({ children }) => children); | ||
| jest.mock('@material-ui/core/Portal', () => ({ children }) => children); | ||
|
|
||
| afterEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| const createMockStore = (featureFlags, baseState) => { | ||
| const middlewares = [thunk]; | ||
| const mockStore = configureMockStore(middlewares); | ||
|
|
||
| return mockStore({ | ||
| ...baseState, | ||
| featureFlags: { | ||
| flags: featureFlags, | ||
| fetching: false, | ||
| fetchingFeatureFlags: false | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| describe('SubmitListUploadingButton component without DISABLE_LIST_UPLOADING', () => { | ||
| const features = { | ||
| disable_list_uploading: false, | ||
| }; | ||
|
|
||
| const user = { | ||
| id: 57658, | ||
| email: '', | ||
| isModerationMode: false, | ||
| name: '', | ||
| description: '', | ||
| website: '', | ||
| contributorType: '', | ||
| otherContributorType: '', | ||
| currentPassword: '', | ||
| newPassword: '', | ||
| confirmNewPassword: '', | ||
| facilityLists: [], | ||
| }; | ||
Innavin369 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const initialState = { | ||
| auth: { | ||
| user: { user }, | ||
| session: { fetching: false }, | ||
| }, | ||
| upload: { | ||
| form: { name:'', description:'', filename:'', replaces:0 }, | ||
| fetching: false, | ||
| error: null, | ||
| }, | ||
| facilityLists: { facilityLists: [ | ||
| { | ||
| "id": 8573, | ||
| "name": "Apparel", | ||
| "description": "Test description", | ||
| "file_name": "Template_Excel.xlsx", | ||
| "is_active": false, | ||
| "is_public": true, | ||
| "item_count": 0, | ||
| "items_url": "/api/facility-lists/8573/items/", | ||
| "statuses": [], | ||
| "status_counts": { | ||
| "UPLOADED": 1, | ||
| "PARSED": 1, | ||
| "GEOCODED": 1, | ||
| "GEOCODED_NO_RESULTS": 1, | ||
| "MATCHED": 1, | ||
| "POTENTIAL_MATCH": 1, | ||
| "CONFIRMED_MATCH": 1, | ||
| "ERROR": 1, | ||
| "ERROR_PARSING": 1, | ||
| "ERROR_GEOCODING": 1, | ||
| "ERROR_MATCHING": 1, | ||
| "DUPLICATE": 1, | ||
| "DELETED": 1, | ||
| "ITEM_REMOVED": 1 | ||
| }, | ||
| "contributor_id": 2371, | ||
| "created_at": "2024-01-13T10:12:05.895143Z", | ||
| "match_responsibility": "moderator", | ||
| "status": "AUTOMATIC", | ||
| "status_change_reason": "test", | ||
| "file": "/Template_Excel_KdIAiX9.xlsx", | ||
| "parsing_errors": [] | ||
| },], | ||
| fetchingFacilityLists: false,}, | ||
| embeddedMap: { isEmbeded:true }, | ||
| fetching:false, | ||
| error: null, | ||
| fetchingFacilityLists:false, | ||
| }; | ||
| const newPreloadedState = { | ||
| userHasSignedIn: true, | ||
| fetchingSessionSignIn: false, | ||
| }; | ||
| const store = createMockStore(features, initialState); | ||
|
|
||
| const renderComponent = (props = {}) => | ||
| render( | ||
| <Provider store={store}> | ||
| <Router> | ||
| <ContributeList {...newPreloadedState} {...props}/> | ||
| </Router>, | ||
| </Provider> | ||
| ); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| test("renders without crashing", () => { | ||
| renderComponent(); | ||
| }); | ||
|
|
||
| test('should render the SUBMIT Button when activeFeatureFlags NOT include DISABLE_LIST_UPLOADING',async () => { | ||
| const {getByRole} = renderComponent(); | ||
|
|
||
| const button = getByRole('button', { name: 'SUBMIT' }); | ||
|
|
||
| expect(button).toBeInTheDocument(); | ||
| expect(button).not.toHaveAttribute('disabled'); | ||
| expect(button).not.toBeDisabled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('SubmitListUploadingButton component with DISABLE_LIST_UPLOADING', () => { | ||
| const features = { | ||
| extended_profile: true, | ||
| disable_list_uploading: true, | ||
| }; | ||
| const user = { | ||
| id: 96565, | ||
| email: '[email protected]', | ||
| isModerationMode: true, | ||
| name: 'TestName', | ||
| description: 'test description', | ||
| website: 'https://test.pl', | ||
| contributorType: 'test type', | ||
| otherContributorType: 'new type', | ||
| currentPassword: 'pass', | ||
| newPassword: 'pass1', | ||
| confirmNewPassword: 'pass1', | ||
| facilityLists: [], | ||
| }; | ||
| const initialState = { | ||
| auth: { | ||
| user: { user }, | ||
| session: { fetching: false }, | ||
| }, | ||
| upload: { | ||
| form: { name:'List name', description:'List description', filename:'file name', replaces:1 }, | ||
| fetching: false, | ||
| error: null, | ||
| }, | ||
| facilityLists: { facilityLists: [ | ||
| { | ||
| "id": 3648, | ||
| "name": "Clothes", | ||
| "description": "No description", | ||
| "file_name": "OSHub_Data_Template_Excel.xlsx", | ||
| "is_active": false, | ||
| "is_public": true, | ||
| "item_count": 0, | ||
| "items_url": "/api/facility-lists/3648/items/", | ||
| "statuses": [], | ||
| "status_counts": { | ||
| "UPLOADED": 0, | ||
| "PARSED": 0, | ||
| "GEOCODED": 0, | ||
| "GEOCODED_NO_RESULTS": 0, | ||
| "MATCHED": 0, | ||
| "POTENTIAL_MATCH": 0, | ||
| "CONFIRMED_MATCH": 0, | ||
| "ERROR": 0, | ||
| "ERROR_PARSING": 0, | ||
| "ERROR_GEOCODING": 0, | ||
| "ERROR_MATCHING": 0, | ||
| "DUPLICATE": 0, | ||
| "DELETED": 0, | ||
| "ITEM_REMOVED": 0 | ||
| }, | ||
| "contributor_id": 7742, | ||
| "created_at": "2024-01-24T11:22:05.895943Z", | ||
| "match_responsibility": "moderator", | ||
| "status": "REJECTED", | ||
| "status_change_reason": "", | ||
| "file": "/OSHub_Data_Template_Excel_KdIAiX9.xlsx", | ||
| "parsing_errors": [] | ||
| },], | ||
| fetchingFacilityLists: false,}, | ||
| embeddedMap: { isEmbeded:false }, | ||
| fetching:false, | ||
| error: null, | ||
| fetchingFacilityLists:false, | ||
| }; | ||
| const preloadedState = { | ||
| userHasSignedIn: true, | ||
| fetchingSessionSignIn: false, | ||
| }; | ||
| const store = createMockStore(features, initialState); | ||
|
|
||
| const renderComponent = (props = {}) => | ||
| render( | ||
| <Provider store={store}> | ||
| <Router> | ||
| <ContributeList {...preloadedState} {...props}/> | ||
| </Router>, | ||
| </Provider> | ||
| ); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('should render the disabled SUBMIT Button when activeFeatureFlags include DISABLE_LIST_UPLOADING', () => { | ||
| const {getByRole} = renderComponent(); | ||
| const submitButton = getByRole('button', { name: 'SUBMIT' }); | ||
|
|
||
| expect(submitButton).toBeInTheDocument(); | ||
| expect(submitButton).toHaveAttribute('disabled'); | ||
| expect(submitButton).toBeDisabled(); | ||
| }); | ||
|
|
||
| test('shows tooltip on hover SUBMIT Button', async () => { | ||
| const {getByRole} = renderComponent(); | ||
| const button = getByRole('button', { name:'SUBMIT' }); | ||
|
|
||
| expect(button).toHaveTextContent('SUBMIT'); | ||
| expect(button).toBeDisabled(); | ||
|
|
||
| const noTooltipElement = document.querySelector(`[title="${ | ||
| MAINTENANCE_MESSAGE}"]`); | ||
|
|
||
| expect(noTooltipElement).toBeInTheDocument(); | ||
| fireEvent.mouseOver(button); | ||
|
|
||
| const tooltip = document.querySelector('[aria-describedby^="mui-tooltip-"]'); | ||
|
|
||
| expect(tooltip).toBeInTheDocument(); | ||
| fireEvent.mouseOut(button); | ||
|
|
||
| const noTooltipElementAfter = document.querySelector(`[title="${ | ||
| MAINTENANCE_MESSAGE}"]`); | ||
|
|
||
| expect(noTooltipElementAfter).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.