summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-08-14 16:47:02 +0100
committerPhil Hughes <me@iamphill.com>2018-08-14 16:47:02 +0100
commit59b6b07e3b889cdced8edf8e388b09f15415fd68 (patch)
tree73fcb2fbe56eb4525a66060a7492f68472b591ea
parenta6d5cb6cbbab1d07ea0b33c67fbeffcb28ac41cf (diff)
downloadgitlab-ce-ide-gitattributes.tar.gz
added specs for getterside-gitattributes
-rw-r--r--app/assets/javascripts/ide/stores/getters.js2
-rw-r--r--changelogs/unreleased/ide-gitattributes.yml5
-rw-r--r--spec/javascripts/ide/stores/getters_spec.js101
3 files changed, 107 insertions, 1 deletions
diff --git a/app/assets/javascripts/ide/stores/getters.js b/app/assets/javascripts/ide/stores/getters.js
index 55a5bb63ac9..1427cee6c65 100644
--- a/app/assets/javascripts/ide/stores/getters.js
+++ b/app/assets/javascripts/ide/stores/getters.js
@@ -112,7 +112,7 @@ export const parsedGitattributes = state => {
return {
...acc,
- [pathMatch[0]]: {
+ [pathMatch[0].trim()]: {
encoding,
},
};
diff --git a/changelogs/unreleased/ide-gitattributes.yml b/changelogs/unreleased/ide-gitattributes.yml
new file mode 100644
index 00000000000..4e58b0c380c
--- /dev/null
+++ b/changelogs/unreleased/ide-gitattributes.yml
@@ -0,0 +1,5 @@
+---
+title: Support gitattributes encoding in the Web IDE
+merge_request: 21133
+author:
+type: added
diff --git a/spec/javascripts/ide/stores/getters_spec.js b/spec/javascripts/ide/stores/getters_spec.js
index 9c135661997..b59703eae94 100644
--- a/spec/javascripts/ide/stores/getters_spec.js
+++ b/spec/javascripts/ide/stores/getters_spec.js
@@ -189,4 +189,105 @@ describe('IDE store getters', () => {
});
});
});
+
+ describe('parsedGitattributes', () => {
+ describe('without .gitattributes file', () => {
+ it('returns empty object', () => {
+ expect(getters.parsedGitattributes(localState)).toEqual({});
+ });
+ });
+
+ describe('with .gitattributes file', () => {
+ beforeEach(() => {
+ localState.entries['.gitattributes'] = {
+ raw: '',
+ content: '',
+ };
+ });
+
+ it('returns empty object when raw is empty', () => {
+ expect(getters.parsedGitattributes(localState)).toEqual({});
+ });
+
+ ['raw', 'content'].forEach(key => {
+ describe(`${key} key in file object`, () => {
+ beforeEach(() => {
+ const content =
+ '*.png -text\n*.svg binary\nDockerfile text\n*.vue text\nREADME.md testing';
+
+ if (key === 'content') {
+ localState.entries['.gitattributes'].raw = content;
+ }
+
+ localState.entries['.gitattributes'][key] = content;
+ });
+
+ it('returns parsed .gitattributes', () => {
+ expect(getters.parsedGitattributes(localState)).toEqual({
+ '*.png': {
+ encoding: 'binary',
+ },
+ '*.svg': {
+ encoding: 'binary',
+ },
+ '*.vue': {
+ encoding: 'text',
+ },
+ Dockerfile: {
+ encoding: 'text',
+ },
+ });
+ });
+
+ it('does not include key when encoding is not recognised', () => {
+ expect(getters.parsedGitattributes(localState)).not.toEqual(
+ jasmine.objectContaining({
+ 'README.md': {},
+ }),
+ );
+ });
+ });
+ });
+ });
+ });
+
+ describe('isFileBinary', () => {
+ let localGetters;
+
+ beforeEach(() => {
+ localState.entries['.gitattributes'] = {
+ raw: '*.svg binary\n*.vue text',
+ };
+
+ localGetters = {
+ parsedGitattributes: getters.parsedGitattributes(localState),
+ };
+ });
+
+ it('returns true when gitattributes has binary path', () => {
+ expect(
+ getters.isFileBinary(localState, localGetters)({
+ name: 'test.svg',
+ }),
+ ).toBe(true);
+ });
+
+ it('returns false when gitattributes has text path', () => {
+ expect(
+ getters.isFileBinary(localState, localGetters)({
+ name: 'test.vue',
+ binary: false,
+ }),
+ ).toBe(false);
+ });
+
+ it('uses binary key if parsed gittatributes returns false', () => {
+ expect(
+ getters.isFileBinary(localState, localGetters)({
+ name: 'test.vue',
+ binary: true,
+ }),
+ ).toBe(true);
+ });
+ });
});