Skip to content

Commit

Permalink
feat: implemented support to upload media in advertisement register c…
Browse files Browse the repository at this point in the history
…omponent (#1248)

* feat: implemented support to upload media in advertisement register component

* fix: failing tests

* fix: failing tests

* removed commented code

* fix: failing tests

* renamed link variable to mediaUrl

* updated the type of mediaUrl

* updated schema and mutation for createAdvertisement

* removed unused variables

* Added support to display advertisement image/video in user portal

* fix: failing tests

* fix: failing tests

* reverted unwanted changes

* fix: failing tests

* fix: failing tests

* added translations for different languages and improved variable names

* Updated variable name and input fields for creating advertisements

* fix: failing tests

* fix: failing tests

* updated get advertisement query

* fix: update advertisement feature

* removed unwanted curly braces

* fix failing tests

* updated type of file

* fix: formatting issues

* fix: formatting issues

* updated variable name and fix cross origin error

* removed: unwanted curly braces

* fix: failing tests

* added oragnization resolver for advertisement

* removed unwanted code

* fix: failing tests

* fix: formatting issues

* fix: formatting issues

* fix: formatting issues

* fix: failing tests
  • Loading branch information
disha1202 authored Feb 1, 2024
1 parent 2f4e5e1 commit 81d11fc
Show file tree
Hide file tree
Showing 21 changed files with 522 additions and 354 deletions.
2 changes: 1 addition & 1 deletion public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@
"delete": "Delete",
"Rname": "Enter name of Advertisement",
"Rtype": "Select type of Advertisement",
"Rlink": "Provide a link for content to be displayed",
"Rmedia": "Provide media content to be displayed",
"RstartDate": "Select Start Date",
"RendDate": "Select End Date",
"RClose": "Close the window",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@
"deleteAdvertisementMsg": "Voulez-vous supprimer cette annonce ?",
"no": "Non",
"yes": "Oui",
"Rmedia": "Fournir du contenu multimédia à afficher",
"view": "Voir",
"edit": "Éditer",
"editAdvertisement": "Éditer l'annonce",
Expand Down
1 change: 1 addition & 0 deletions public/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@
"deleteAdvertisementMsg": "क्या आप इस विज्ञापन को हटाना चाहते हैं?",
"no": "नहीं",
"yes": "हाँ",
"Rmedia": "प्रदर्शित करने के लिए मीडिया सामग्री प्रदान करें",
"view": "देखें",
"edit": "संपादित करें",
"editAdvertisement": "विज्ञापन संपादित करें",
Expand Down
1 change: 1 addition & 0 deletions public/locales/sp.json
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@
"deleteAdvertisementMsg": "¿Desea eliminar este anuncio?",
"no": "No",
"yes": "",
"Rmedia": "Proporcionar contenido multimedia para mostrar",
"view": "Ver",
"edit": "Editar",
"editAdvertisement": "Editar Anuncio",
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@
"deleteAdvertisementMsg": "您是否要删除此广告?",
"no": "",
"yes": "",
"Rmedia": "提供要显示的媒体内容",
"view": "查看",
"edit": "编辑",
"editAdvertisement": "编辑广告",
Expand Down
26 changes: 16 additions & 10 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ directive @role(requires: UserType) on FIELD_DEFINITION
type Advertisement {
_id: ID
endDate: Date!
link: String!
mediaUrl: URL!
name: String!
orgId: ID
organizationId: ID!
startDate: Date!
type: String!
}
Expand Down Expand Up @@ -402,6 +402,19 @@ type MinimumValueError implements FieldError {
path: [String!]!
}

input CreateAdvertisementInput {
endDate: Date!
name: String!
organizationId: ID!
startDate: Date!
type: String!
mediaFile: String!
}

type CreateAdvertisementPayload {
advertisement: Advertisement
}

type Mutation {
acceptAdmin(id: ID!): Boolean!
acceptMembershipRequest(membershipRequestId: ID!): MembershipRequest!
Expand All @@ -419,14 +432,7 @@ type Mutation {
cancelMembershipRequest(membershipRequestId: ID!): MembershipRequest!
checkIn(data: CheckInInput!): CheckIn!
createAdmin(data: UserAndOrganizationInput!): User!
createAdvertisement(
endDate: Date!
link: String!
name: String!
orgId: ID!
startDate: Date!
type: String!
): Advertisement!
createAdvertisement(input: CreateAdvertisementInput!): CreateAdvertisementPayload
createComment(data: CommentInput!, postId: ID!): Comment
createDirectChat(data: createChatInput!): DirectChat!
createDonation(
Expand Down
22 changes: 12 additions & 10 deletions src/GraphQl/Mutations/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,20 +444,22 @@ export const ADD_PLUGIN_MUTATION = gql`
`;
export const ADD_ADVERTISEMENT_MUTATION = gql`
mutation (
$orgId: ID!
$organizationId: ID!
$name: String!
$link: String!
$type: String!
$startDate: Date!
$endDate: Date!
$file: String!
) {
createAdvertisement(
orgId: $orgId
name: $name
link: $link
type: $type
startDate: $startDate
endDate: $endDate
input: {
organizationId: $organizationId
name: $name
type: $type
startDate: $startDate
endDate: $endDate
mediaFile: $file
}
) {
_id
}
Expand All @@ -467,7 +469,7 @@ export const UPDATE_ADVERTISEMENT_MUTATION = gql`
mutation UpdateAdvertisement(
$id: ID!
$name: String
$link: String
$file: String
$type: AdvertisementType
$startDate: Date
$endDate: Date
Expand All @@ -476,7 +478,7 @@ export const UPDATE_ADVERTISEMENT_MUTATION = gql`
input: {
_id: $id
name: $name
link: $link
mediaFile: $file
type: $type
startDate: $startDate
endDate: $endDate
Expand Down
6 changes: 4 additions & 2 deletions src/GraphQl/Queries/PlugInQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export const ADVERTISEMENTS_GET = gql`
_id
name
type
orgId
link
organization {
_id
}
mediaUrl
endDate
startDate
}
Expand Down
42 changes: 28 additions & 14 deletions src/components/Advertisements/Advertisements.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import 'jest-location-mock';
import { act, render, screen } from '@testing-library/react';
import { act, fireEvent, render, screen } from '@testing-library/react';
import { MockedProvider } from '@apollo/client/testing';
import {
ApolloClient,
Expand Down Expand Up @@ -88,9 +88,9 @@ const ADD_ADVERTISEMENT_MUTATION_MOCK = {
request: {
query: ADD_ADVERTISEMENT_MUTATION,
variables: {
orgId: 'undefined',
organizationId: 'undefined',
name: 'Cookie Shop',
link: 'http://yourwebsite.com/photo',
file: 'data:image/png;base64,bWVkaWEgY29udGVudA==',
type: 'POPUP',
startDate: '2023-01-01',
endDate: '2023-02-02',
Expand Down Expand Up @@ -210,18 +210,26 @@ describe('Testing Advertisement Component', () => {
screen.getByLabelText('Enter name of Advertisement'),
'Cookie Shop'
);
userEvent.type(
screen.getByLabelText('Provide a link for content to be displayed'),
'http://yourwebsite.com/photo'
);
const mediaFile = new File(['media content'], 'test.png', {
type: 'image/png',
});

const mediaInput = screen.getByTestId('advertisementMedia');
fireEvent.change(mediaInput, {
target: {
files: [mediaFile],
},
});
const mediaPreview = await screen.findByTestId('mediaPreview');
expect(mediaPreview).toBeInTheDocument();
userEvent.selectOptions(
screen.getByLabelText('Select type of Advertisement'),
'POPUP'
);
userEvent.type(screen.getByLabelText('Select Start Date'), '2023-01-01');
userEvent.type(screen.getByLabelText('Select End Date'), '2023-02-02');

await userEvent.click(screen.getByTestId('addonregister'));
userEvent.click(screen.getByTestId('addonregister'));
expect(
await screen.findByText('Advertisement created successfully')
).toBeInTheDocument();
Expand All @@ -243,8 +251,10 @@ describe('Testing Advertisement Component', () => {
_id: '1',
name: 'Advertisement1',
type: 'POPUP',
orgId: 'undefined',
link: 'http://example1.com',
organization: {
_id: 'undefined',
},
mediaUrl: 'http://example1.com',
endDate: '2023-01-01',
startDate: '2022-01-01',
},
Expand Down Expand Up @@ -308,17 +318,21 @@ describe('Testing Advertisement Component', () => {
_id: '1',
name: 'Advertisement1',
type: 'POPUP',
orgId: 'undefined',
link: 'http://example1.com',
organization: {
_id: 'undefined',
},
mediaUrl: 'http://example1.com',
endDate: '2023-01-01',
startDate: '2022-01-01',
},
{
_id: '2',
name: 'Advertisement2',
type: 'BANNER',
orgId: 'undefined',
link: 'http://example2.com',
organization: {
_id: 'undefined',
},
mediaUrl: 'http://example2.com',
endDate: tomorrow,
startDate: today,
},
Expand Down
Loading

0 comments on commit 81d11fc

Please sign in to comment.