Skip to content

Commit

Permalink
New(preview): Adding preview with excel online for xlsb & xlsm files (#…
Browse files Browse the repository at this point in the history
…1001)

* New(preview): Adding preview with excel online for xlsb & xlsm files

* New: Show excel icons for xlsb files
  • Loading branch information
kritishrivastava authored and mergify[bot] committed Jun 21, 2019
1 parent d41c05b commit c6359cd
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/lib/icons/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const ICON_FILE_MAP = {};
});

// EXCEL ICON EXTENSIONS
['xls', 'xlsm', 'xlsx'].forEach((extension) => {
['xls', 'xlsm', 'xlsx', 'xlsb'].forEach((extension) => {
ICON_FILE_MAP[extension] = 'FILE_EXCEL';
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/office/OfficeLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const VIEWERS = [
NAME: 'Office',
CONSTRUCTOR: OfficeViewer,
REP: ORIGINAL_REP_NAME,
EXT: ['xlsx']
EXT: ['xlsx', 'xlsm', 'xlsb']
}
];

Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/office/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ There are several limitations at the moment:

## Supported File Extensions

`xlsx`
`xlsx`, `xlsm`, `xlsb`

## Events

Expand Down
116 changes: 62 additions & 54 deletions src/lib/viewers/office/__tests__/OfficeLoader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,82 @@ import * as file from '../../../file';
import { PERMISSION_DOWNLOAD } from '../../../constants';

const sandbox = sinon.sandbox.create();
let fakeFile;

describe('lib/viewers/office/OfficeLoader', () => {
beforeEach(() => {
fakeFile = {
extension: 'xlsx',
size: 1000,
permissions: {
can_download: true
},
representations: {
entries: [
{
representation: 'ORIGINAL'
}
]
}
};
});
const fakeFileTemplate = {
size: 1000,
permissions: {
can_download: true
},
representations: {
entries: [
{
representation: 'ORIGINAL'
}
]
}
};

afterEach(() => {
sandbox.verifyAndRestore();
});

describe('determineViewer()', () => {
it('should choose the Office viewer if it is not disabled and the file is ok', () => {
const viewer = OfficeLoader.determineViewer(fakeFile);
expect(viewer).to.deep.equal({
NAME: 'Office',
CONSTRUCTOR: OfficeViewer,
REP: 'ORIGINAL',
EXT: ['xlsx']
});
});

it('should choose the Office viewer if it is not disabled and the file is a shared link that is not password-protected', () => {
fakeFile.shared_link = {
is_password_enabled: false
};
const fakeFiles = [
Object.assign({}, fakeFileTemplate, { extension: 'xlsx' }),
Object.assign({}, fakeFileTemplate, { extension: 'xlsm' }),
Object.assign({}, fakeFileTemplate, { extension: 'xlsb' })
];

const viewer = OfficeLoader.determineViewer(fakeFile);
expect(viewer.NAME).to.equal('Office');
});
fakeFiles.forEach((fakeFile) => {
it('should choose the Office viewer if it is not disabled and the file is ok', () => {
const viewer = OfficeLoader.determineViewer(fakeFile);
expect(viewer).to.deep.equal({
NAME: 'Office',
CONSTRUCTOR: OfficeViewer,
REP: 'ORIGINAL',
EXT: ['xlsx', 'xlsm', 'xlsb']
});
});

it('should not return a viewer if the Office viewer is disabled', () => {
const viewer = OfficeLoader.determineViewer(fakeFile, ['Office']);
expect(viewer).to.equal(undefined);
});
it('should choose the Office viewer if it is not disabled and the file is a shared link that is not password-protected', () => {
const editedFakeFile = fakeFile;
editedFakeFile.shared_link = {
is_password_enabled: false
};
const viewer = OfficeLoader.determineViewer(editedFakeFile);
expect(viewer.NAME).to.equal('Office');
});

it('should not return a viewer if the file is too large', () => {
fakeFile.size = 5242881;
const viewer = OfficeLoader.determineViewer(fakeFile, []);
expect(viewer).to.equal(undefined);
});
it('should not return a viewer if the Office viewer is disabled', () => {
const viewer = OfficeLoader.determineViewer(fakeFile, ['Office']);
expect(viewer).to.equal(undefined);
});

it('should not return a viewer if the user does not have download permissions', () => {
sandbox.stub(file, 'checkPermission').withArgs(fakeFile, PERMISSION_DOWNLOAD).returns(false);
const viewer = OfficeLoader.determineViewer(fakeFile, []);
expect(viewer).to.equal(undefined);
});
it('should not return a viewer if the file is too large', () => {
const editedFakeFile = fakeFile;
editedFakeFile.size = 5242881;
const viewer = OfficeLoader.determineViewer(editedFakeFile, []);
expect(viewer).to.equal(undefined);
});

it('should not return a viewer if the file is a password-protected shared link', () => {
fakeFile.shared_link = {
is_password_enabled: true
};
it('should not return a viewer if the user does not have download permissions', () => {
sandbox
.stub(file, 'checkPermission')
.withArgs(fakeFile, PERMISSION_DOWNLOAD)
.returns(false);
const viewer = OfficeLoader.determineViewer(fakeFile, []);
expect(viewer).to.equal(undefined);
});

const viewer = OfficeLoader.determineViewer(fakeFile, []);
expect(viewer).to.equal(undefined);
it('should not return a viewer if the file is a password-protected shared link', () => {
const editedFakeFile = fakeFile;
editedFakeFile.shared_link = {
is_password_enabled: true
};
const viewer = OfficeLoader.determineViewer(editedFakeFile, []);
expect(viewer).to.equal(undefined);
});
});
});
});

0 comments on commit c6359cd

Please sign in to comment.